Skip to content

Add logical operator support (__and__/__or__ methods on dataframe and column) #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,47 @@ def __lt__(self, other: Column | Scalar) -> Column:
Column
"""

def __and__(self, other: Column | Scalar) -> Column:
def __and__(self, other: Column[bool] | bool) -> Column:
"""
Add `other` dataframe or scalar to this column.
Apply logical 'and' to `other` Column (or scalar) and this Column.

Parameters
----------
other : Column[bool] or bool
If Column, must have same length.

Returns
-------
Column

Raises
------
ValueError
If `self` or `other` is not boolean.
"""

def __or__(self, other: Column[bool] | bool) -> Column:
"""
Apply logical 'or' to `other` Column (or scalar) and this column.

Parameters
----------
other : Column[bool] or Scalar
If Column, must have same length.

Returns
-------
Column[bool]

Raises
------
ValueError
If `self` or `other` is not boolean.
"""

def __add__(self, other: Column | Scalar) -> Column:
"""
Add `other` column or scalar from this column.

Parameters
----------
Expand All @@ -183,7 +221,7 @@ def __and__(self, other: Column | Scalar) -> Column:

def __sub__(self, other: Column | Scalar) -> Column:
"""
Subtract `other` dataframe or scalar from this column.
Subtract `other` column or scalar from this column.

Parameters
----------
Expand All @@ -199,7 +237,7 @@ def __sub__(self, other: Column | Scalar) -> Column:

def __mul__(self, other: Column | Scalar) -> Column:
"""
Multiply `other` dataframe or scalar with this column.
Multiply `other` column or scalar with this column.

Parameters
----------
Expand Down Expand Up @@ -231,7 +269,7 @@ def __truediv__(self, other: Column | Scalar) -> Column:

def __floordiv__(self, other: Column | Scalar) -> Column:
"""
Floor-divide `other` dataframe or scalar to this column.
Floor-divide `other` column or scalar to this column.

Parameters
----------
Expand Down
38 changes: 38 additions & 0 deletions spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,44 @@ def __lt__(self, other: DataFrame | Scalar) -> DataFrame:
"""
...

def __and__(self, other: DataFrame[bool] | bool) -> DataFrame:
"""
Apply logical 'and' to `other` DataFrame (or scalar) and this dataframe.

Parameters
----------
other : DataFrame[bool] or bool
If DataFrame, must have same length.

Returns
-------
DataFrame[bool]

Raises
------
ValueError
If `self` or `other` is not boolean.
"""

def __or__(self, other: DataFrame[bool] | bool) -> DataFrame:
"""
Apply logical 'or' to `other` DataFrame (or scalar) and this DataFrame.

Parameters
----------
other : DataFrame[bool] or Scalar
If DataFrame, must have same length.

Returns
-------
DataFrame[bool]

Raises
------
ValueError
If `self` or `other` is not boolean.
"""

def __add__(self, other: DataFrame | Scalar) -> DataFrame:
"""
Add `other` dataframe or scalar to this dataframe.
Expand Down