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] Support missing operators in cudf.Series (__divmod__, __rdivmod__, __round__). #10177

Open
bdice opened this issue Jan 31, 2022 · 5 comments
Assignees
Labels
feature request New feature or request Python Affects Python cuDF API.

Comments

@bdice
Copy link
Contributor

bdice commented Jan 31, 2022

Is your feature request related to a problem? Please describe.
cudf.Series does not have reverse binary operators for bitwise operators like __rxor__. This was caught after changing the output of Series.hash_values from a cupy.array to a cudf.Series in #9390, which broke NVTabular: NVIDIA-Merlin/NVTabular#1376 (review). The cupy.array class supports both directions, like array ^ scalar and scalar ^ array. Similarly, pandas supports both directions. Currently cudf.Series only supports series ^ scalar.

Describe the solution you'd like
Add reverse binary operators for all cases that are missing, which include at least bitwise operators like __rxor__ but possibly others as well. Missing operators have been addressed several times in the past (#208, #213, #1292, #8598, ...). Resolving this issue should involve checking the full list in the Python object model documentation to make sure we catch everything that pandas supports.

Additional context
A workaround is to use the binary operator in the reverse order (for commutative operators).

@bdice bdice added feature request New feature or request Needs Triage Need team to review and classify labels Jan 31, 2022
@bdice bdice changed the title [FEA] Commutative bitwise operators (e.g. __rxor__) for cudf.Series. [FEA] Commutative bitwise operators (like __rxor__) for cudf.Series. Jan 31, 2022
@bdice bdice added Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Jan 31, 2022
@bdice
Copy link
Contributor Author

bdice commented Feb 12, 2022

List of other operators I've found are implemented in pandas but not cudf:

  • __divmod__(self, other) (docs on divmod)
  • __rdivmod__(self, other)
  • __round__(self, ndigits)

@vyasr
Copy link
Contributor

vyasr commented Feb 25, 2022

#10360 handles the reverse binary operators. The three that you listed in your last comment are not yet done. divmod and rdivmod are out of scope for #10360 but are in general trivial to implement in the relevant classes once that PR is merged since they are just

def __divmod__(self, other):
    return self // other, self % other
def __rdivmod__(self, other):
    return other // self, other % self

I think they should probably just bypass the new binop machinery, but maybe there will be a benefit to including them.

round is a little different from other binary operations because the second parameter is optional, i.e. round(x) will not pass a parameter for ndigits so you have to make sure to handle the None case. Obviously trivial to do, but a reason to perhaps not shoehorn it into the same patterns and instead implement it separately.

@bdice bdice changed the title [FEA] Commutative bitwise operators (like __rxor__) for cudf.Series. [FEA] Support missing operators in cudf.Series (__rxor__, __divmod__, __rdivmod, __round__). Feb 28, 2022
@bdice bdice changed the title [FEA] Support missing operators in cudf.Series (__rxor__, __divmod__, __rdivmod, __round__). [FEA] Support missing operators in cudf.Series (__rxor__, __divmod__, __rdivmod__, __round__). Feb 28, 2022
@bdice
Copy link
Contributor Author

bdice commented Feb 28, 2022

@vyasr Awesome. I subscribed to notifications on #10360 and I can take a look at the missing operators after that PR is merged. I changed the title of this issue to reflect the change in scope.

rapids-bot bot pushed a commit that referenced this issue Mar 2, 2022
This PR builds on the framework introduced in #9925 to implement scans. I plan to apply this mixin to ColumnBase as well, but that will require more work to clean up binary operations for column types and it is large enough to merit a separate PR.

Contributes to #10177.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Michael Wang (https://github.com/isVoid)
  - Ashwin Srinath (https://github.com/shwina)

URL: #10360
@github-actions
Copy link

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@github-actions
Copy link

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.

@vyasr vyasr changed the title [FEA] Support missing operators in cudf.Series (__rxor__, __divmod__, __rdivmod__, __round__). [FEA] Support missing operators in cudf.Series (__divmod__, __rdivmod__, __round__). Oct 27, 2022
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
Status: No status
Development

No branches or pull requests

3 participants