Skip to content

Commit

Permalink
Use a dictionary to better document the operator swapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Feb 11, 2022
1 parent 8e02f74 commit c850aee
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,23 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if fname in binary_operations:
not_reflect = self is inputs[0]
other = inputs[not_reflect]

# These operators need to be mapped to their inverses when
# performing a reflected operation because no reflected version of
# the operators themselves exist.
ops_without_reflection = {
"gt": "lt",
"ge": "le",
"lt": "gt",
"le": "ge",
# ne and eq are symmetric
"ne": "ne",
"eq": "eq",
}

op = binary_operations[fname]
ops_without_reflection = ("gt", "ge", "lt", "le", "ne", "eq")
if op in ops_without_reflection and not not_reflect:
# This replacement will ignore eq and ne, which don't need it.
op = op.replace(*(("g", "l") if "g" in op else ("l", "g")))
op = ops_without_reflection[op]
not_reflect = True
op = f"__{'' if not_reflect else 'r'}{op}__"

Expand Down

0 comments on commit c850aee

Please sign in to comment.