Skip to content

Commit a7d145e

Browse files
committed
'and' + 'or' support
1 parent 07e530e commit a7d145e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pandas_to_sql/engine/columns/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,18 @@ def __eq__(self,other):
6868

6969
def __ne__(self,other):
7070
return create_column_from_operation(self, other, BoolColumn, '<>')
71+
72+
def __and__(self,other):
73+
return create_column_from_operation(self, other, BoolColumn, 'AND')
74+
75+
def __or__(self,other):
76+
return create_column_from_operation(self, other, BoolColumn, 'OR')
7177

7278
class_type.__lt__ = __lt__
7379
class_type.__gt__ = __gt__
7480
class_type.__le__ = __le__
7581
class_type.__ge__ = __ge__
7682
class_type.__eq__ = __eq__
7783
class_type.__ne__ = __ne__
84+
class_type.__and__ = __and__
85+
class_type.__or__ = __or__

pandas_to_sql/testing/tests/test_operations_compare.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,15 @@ def test_neg_bool():
7070
def test_neg_numeric():
7171
df = pytest.df1
7272
df['new_value'] = -df.random_int
73-
assert_(df)
73+
assert_(df)
74+
75+
76+
def test_two_conds_and():
77+
df = pytest.df1
78+
df['new_value'] = (df.random_float > 1) & (df.random_float <=2)
79+
assert_(df)
80+
81+
def test_two_conds_or():
82+
df = pytest.df1
83+
df['new_value'] = (df.random_float > 1) or True
84+
assert_(df)

0 commit comments

Comments
 (0)