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 handling of typecasting in searchsorted #13925

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 14 additions & 3 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,12 +1409,23 @@ def searchsorted(
if len(values) != len(self._data):
raise ValueError("Mismatch number of columns to search for.")

common_dtype_list = [
find_common_type([col.dtype, val.dtype])
for col, val in zip(self._columns, values)
]
sources = [
col
if is_dtype_equal(col.dtype, val.dtype)
else col.astype(val.dtype)
for col, val in zip(self._columns, values)
if is_dtype_equal(col.dtype, common_dtype)
else col.astype(common_dtype)
for col, common_dtype in zip(self._columns, common_dtype_list)
]
values = [
val
if is_dtype_equal(val.dtype, common_dtype)
else val.astype(common_dtype)
for val, common_dtype in zip(values, common_dtype_list)
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
]

outcol = libcudf.search.search_sorted(
sources,
values,
Expand Down
13 changes: 13 additions & 0 deletions python/cudf/cudf/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,3 +2067,16 @@ def test_loc_index_notinindex_slice(
expect = pdf.loc[lo:hi:take_order]
actual = df.loc[lo:hi:take_order]
assert_eq(expect, actual)

galipremsagar marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.parametrize(
"arg", [slice(2, 4), slice(2, 5), slice(2.3, 5), slice(4.6, 6)]
)
def test_series_iloc_float_int(arg):
gs = cudf.Series(range(4), index=[2.0, 3.0, 4.5, 5.5])
ps = gs.to_pandas()

actual = gs.loc[arg]
expected = ps.loc[arg]

assert_eq(actual, expected)