Skip to content
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

[FEA] Implement comparison operators for decimal columns #7498

Closed
ChrisJar opened this issue Mar 3, 2021 · 1 comment · Fixed by #7716
Closed

[FEA] Implement comparison operators for decimal columns #7498

ChrisJar opened this issue Mar 3, 2021 · 1 comment · Fixed by #7716
Assignees
Labels
feature request New feature or request Python Affects Python cuDF API.

Comments

@ChrisJar
Copy link
Contributor

ChrisJar commented Mar 3, 2021

Is your feature request related to a problem? Please describe.
I'd like to be able to perform boolean comparisons (>, >=, <, <=, ==) on dataframes and series with decimal columns.

Describe the solution you'd like
I would like to mimic the behavior of performing comparisons on dataframes or series with float columns. For example:

df = cudf.DataFrame({'id': [0, 1, 1], 'val': [1.00, 1.01, 1.02]})
df >= 1

returns

	id	val
0	False	True
1	True	True
2	True	True

But if a decimal column is present

df['val'] = cudf.Series([decimal.Decimal(x) for x in [1.00, 1.01, 1.02]], dtype=cudf.Decimal64Dtype(7,3))
df >= 1

it returns

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-31-5b213dd19a01> in <module>
----> 1 df >= 1

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/dataframe.py in __ge__(self, other)
   2420 
   2421     def __ge__(self, other):
-> 2422         return self._apply_op("__ge__", other)
   2423 
   2424     def __invert__(self):

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/dataframe.py in _apply_op(self, fn, other, fill_value)
   1470         ):
   1471             for col in self._data:
-> 1472                 result[col] = op(self[col], other)
   1473         else:
   1474             raise NotImplementedError(

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/dataframe.py in op(lhs, rhs)
   1399         def op(lhs, rhs):
   1400             if fill_value is None:
-> 1401                 return getattr(lhs, fn)(rhs)
   1402             else:
   1403                 return getattr(lhs, fn)(rhs, fill_value)

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/series.py in __ge__(self, other)
   1659 
   1660     def __ge__(self, other):
-> 1661         return self._binaryop(other, "ge")
   1662 
   1663     def __invert__(self):

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/contextlib.py in inner(*args, **kwds)
     72         def inner(*args, **kwds):
     73             with self._recreate_cm():
---> 74                 return func(*args, **kwds)
     75         return inner
     76 

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/series.py in _binaryop(self, other, fn, fill_value, reflect)
   1158         else:
   1159             lhs, rhs = self, other
-> 1160         rhs = self._normalize_binop_value(rhs)
   1161 
   1162         if fn == "truediv":

/home/u00u7rh1e72hXfsipJ357/miniconda3/envs/rapids-gpu-bdb/lib/python3.7/site-packages/cudf/core/series.py in _normalize_binop_value(self, other)
   1551             return cudf.Scalar(other, dtype=self.dtype)
   1552         else:
-> 1553             return self._column.normalize_binop_value(other)
   1554 
   1555     def eq(self, other, fill_value=None, axis=0):

AttributeError: 'DecimalColumn' object has no attribute 'normalize_binop_value'
@ChrisJar ChrisJar added Needs Triage Need team to review and classify feature request New feature or request labels Mar 3, 2021
@kkraus14 kkraus14 added Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Mar 3, 2021
@harrism
Copy link
Member

harrism commented Mar 16, 2021

I this this already works in libcudf. This is just a Python feature request, right?

@isVoid isVoid self-assigned this Mar 24, 2021
@rapids-bot rapids-bot bot closed this as completed in #7716 Apr 1, 2021
rapids-bot bot pushed a commit that referenced this issue Apr 1, 2021
Closes #7498 

This PR adds binary comparison `eq`, `lt`, `gt`, `le`, `ge` to 

- [x] decimal column v. decimal column
- [x] decimal column v. decimal scalar (`decimal.Decimal` and decimal `cudf.Scalar`)
- [x] decimal column v. integer column (`cudf.utils.dtypes.INTEGER_TYPES`)
- [x] decimal column v. integer scalar    (Python ints)

Other minor adds:
- Supports binary ops between `cudf.DecimalColumn` and `cudf.Scalar`, where `Scalar.dtype` is `cudf.Decimal64Dtype` (follow up for #7732 )
- Short comment noting use of decimal64 in `decimals.pxd`
- Adding decimal data type in `basics.rst`

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - Keith Kraus (https://github.com/kkraus14)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #7716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants