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

Improve memory footprint of isin by using contains #14478

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 5 additions & 7 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,11 @@ def _obtain_isin_result(self, rhs: ColumnBase) -> ColumnBase:
Helper function for `isin` which merges `self` & `rhs`
to determine what values of `rhs` exist in `self`.
"""
ldf = cudf.DataFrame({"x": self, "orig_order": arange(len(self))})
rdf = cudf.DataFrame(
{"x": rhs, "bool": full(len(rhs), True, dtype="bool")}
)
res = ldf.merge(rdf, on="x", how="left").sort_values(by="orig_order")
res = res.drop_duplicates(subset="orig_order", ignore_index=True)
return res._data["bool"].fillna(False)
# We've already matched dtypes by now
result = libcudf.search.contains(rhs, self)
if result.null_count:
return result.fillna(False)
return result

def as_mask(self) -> Buffer:
"""Convert booleans to bitmask
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def isin(self, values, level=None):
)
self_df = self.to_frame(index=False).reset_index()
values_df = values_idx.to_frame(index=False)
idx = self_df.merge(values_df)._data["index"]
idx = self_df.merge(values_df, how="leftsemi")._data["index"]
res = cudf.core.column.full(size=len(self), fill_value=False)
res[idx] = True
result = res.values
Expand Down
Loading