Skip to content

Commit 30b242d

Browse files
authored
Add logical operator support (__and__/__or__ methods on dataframe and column) (#171)
* fix __and__ docstring * fix __and__ docs, add __or__ * more fixups * Update spec/API_specification/dataframe_api/dataframe_object.py * note that nulls should follow kleene logic * type return * Update spec/API_specification/dataframe_api/column_object.py
1 parent 185b203 commit 30b242d

File tree

2 files changed

+97
-5
lines changed

2 files changed

+97
-5
lines changed

spec/API_specification/dataframe_api/column_object.py

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def __eq__(self, other: Column | Scalar) -> Column:
7373
"""
7474
Compare for equality.
7575
76+
Nulls should follow Kleene Logic.
77+
7678
Parameters
7779
----------
7880
other : Column or Scalar
@@ -89,6 +91,8 @@ def __ne__(self, other: Column | Scalar) -> Column:
8991
"""
9092
Compare for non-equality.
9193
94+
Nulls should follow Kleene Logic.
95+
9296
Parameters
9397
----------
9498
other : Column or Scalar
@@ -165,9 +169,51 @@ def __lt__(self, other: Column | Scalar) -> Column:
165169
Column
166170
"""
167171

168-
def __and__(self, other: Column | Scalar) -> Column:
172+
def __and__(self, other: Column[bool] | bool) -> Column[bool]:
173+
"""
174+
Apply logical 'and' to `other` Column (or scalar) and this Column.
175+
176+
Nulls should follow Kleene Logic.
177+
178+
Parameters
179+
----------
180+
other : Column[bool] or bool
181+
If Column, must have same length.
182+
183+
Returns
184+
-------
185+
Column
186+
187+
Raises
188+
------
189+
ValueError
190+
If `self` or `other` is not boolean.
191+
"""
192+
193+
def __or__(self, other: Column[bool] | bool) -> Column[bool]:
194+
"""
195+
Apply logical 'or' to `other` Column (or scalar) and this column.
196+
197+
Nulls should follow Kleene Logic.
198+
199+
Parameters
200+
----------
201+
other : Column[bool] or Scalar
202+
If Column, must have same length.
203+
204+
Returns
205+
-------
206+
Column[bool]
207+
208+
Raises
209+
------
210+
ValueError
211+
If `self` or `other` is not boolean.
212+
"""
213+
214+
def __add__(self, other: Column | Scalar) -> Column:
169215
"""
170-
Add `other` dataframe or scalar to this column.
216+
Add `other` column or scalar to this column.
171217
172218
Parameters
173219
----------
@@ -183,7 +229,7 @@ def __and__(self, other: Column | Scalar) -> Column:
183229

184230
def __sub__(self, other: Column | Scalar) -> Column:
185231
"""
186-
Subtract `other` dataframe or scalar from this column.
232+
Subtract `other` column or scalar from this column.
187233
188234
Parameters
189235
----------
@@ -199,7 +245,7 @@ def __sub__(self, other: Column | Scalar) -> Column:
199245

200246
def __mul__(self, other: Column | Scalar) -> Column:
201247
"""
202-
Multiply `other` dataframe or scalar with this column.
248+
Multiply `other` column or scalar with this column.
203249
204250
Parameters
205251
----------
@@ -231,7 +277,7 @@ def __truediv__(self, other: Column | Scalar) -> Column:
231277

232278
def __floordiv__(self, other: Column | Scalar) -> Column:
233279
"""
234-
Floor-divide `other` dataframe or scalar to this column.
280+
Floor-divide `other` column or scalar to this column.
235281
236282
Parameters
237283
----------

spec/API_specification/dataframe_api/dataframe_object.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def __eq__(self, other: DataFrame | Scalar) -> DataFrame:
295295
"""
296296
Compare for equality.
297297
298+
Nulls should follow Kleene Logic.
299+
298300
Parameters
299301
----------
300302
other : DataFrame or Scalar
@@ -312,6 +314,8 @@ def __ne__(self, other: DataFrame | Scalar) -> DataFrame:
312314
"""
313315
Compare for non-equality.
314316
317+
Nulls should follow Kleene Logic.
318+
315319
Parameters
316320
----------
317321
other : DataFrame or Scalar
@@ -393,6 +397,48 @@ def __lt__(self, other: DataFrame | Scalar) -> DataFrame:
393397
"""
394398
...
395399

400+
def __and__(self, other: DataFrame[bool] | bool) -> DataFrame[bool]:
401+
"""
402+
Apply logical 'and' to `other` DataFrame (or scalar) and this dataframe.
403+
404+
Nulls should follow Kleene Logic.
405+
406+
Parameters
407+
----------
408+
other : DataFrame[bool] or bool
409+
If DataFrame, must have same length.
410+
411+
Returns
412+
-------
413+
DataFrame[bool]
414+
415+
Raises
416+
------
417+
ValueError
418+
If `self` or `other` is not boolean.
419+
"""
420+
421+
def __or__(self, other: DataFrame[bool] | bool) -> DataFrame[bool]:
422+
"""
423+
Apply logical 'or' to `other` DataFrame (or scalar) and this DataFrame.
424+
425+
Nulls should follow Kleene Logic.
426+
427+
Parameters
428+
----------
429+
other : DataFrame[bool] or bool
430+
If DataFrame, must have same length.
431+
432+
Returns
433+
-------
434+
DataFrame[bool]
435+
436+
Raises
437+
------
438+
ValueError
439+
If `self` or `other` is not boolean.
440+
"""
441+
396442
def __add__(self, other: DataFrame | Scalar) -> DataFrame:
397443
"""
398444
Add `other` dataframe or scalar to this dataframe.

0 commit comments

Comments
 (0)