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

Fix binop with LHS numpy datetimelike scalar #17226

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ def _wrap_binop_normalization(self, other):
if cudf.utils.utils.is_na_like(other):
return cudf.Scalar(other, dtype=self.dtype)
if isinstance(other, np.ndarray) and other.ndim == 0:
# Try and maintain the dtype
other = other.dtype.type(other.item())
# Return numpy scalar
other = other[()]
Matt711 marked this conversation as resolved.
Show resolved Hide resolved
return self.normalize_binop_value(other)

def _scatter_by_slice(
Expand Down
13 changes: 13 additions & 0 deletions python/cudf/cudf/tests/test_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3431,3 +3431,16 @@ def test_binop_eq_ne_index_series(data1, data2):
expected = gi.to_pandas() != gs.to_pandas()

assert_eq(expected, actual)


@pytest.mark.parametrize("scalar", [np.datetime64, np.timedelta64])
def test_binop_lhs_numpy_datetimelike_scalar(scalar):
slr1 = scalar(1, "ms")
slr2 = scalar(1, "ns")
result = slr1 < cudf.Series([slr2])
expected = slr1 < pd.Series([slr2])
assert_eq(result, expected)

result = slr2 < cudf.Series([slr1])
expected = slr2 < pd.Series([slr1])
assert_eq(result, expected)
Loading