Skip to content

Commit

Permalink
Merge pull request #1 from rgsl888prabhu/index_changes_to_series_is_in
Browse files Browse the repository at this point in the history
Fix for missing series index in isin
  • Loading branch information
galipremsagar authored Apr 1, 2020
2 parents 34667a7 + b904f97 commit 6c9869a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,9 @@ def isin(self, values):
except Exception:
# pandas functionally returns all False when cleansing via
# typecasting fails
return Series(cupy.zeros(len(self), dtype="bool"))
return Series(
cupy.zeros(len(self), dtype="bool"), index=self.index
)

# If categorical, combine categories first
if is_categorical_dtype(lhs):
Expand All @@ -2078,7 +2080,9 @@ def isin(self, values):
# list doesn't have any nulls. If it does have nulls, make
# the values list a Categorical with a single null
if not rhs.has_nulls:
return Series(cupy.zeros(len(self), dtype="bool"))
return Series(
cupy.zeros(len(self), dtype="bool"), index=self.index
)
rhs = Series(pd.Categorical.from_codes([-1], categories=[]))
rhs = rhs.cat.set_categories(lhs_cats).astype(self.dtype)

Expand All @@ -2088,6 +2092,7 @@ def isin(self, values):
res = res.drop_duplicates(subset="orig_order").reset_index(drop=True)
res = res["bool"].fillna(False)
res.name = self.name
res.index = self.index

return res

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3627,7 +3627,8 @@ def test_series_value_counts():
],
)
def test_isin_numeric(data, values):
psr = pd.Series(data)
index = np.random.randint(0, 100, len(data))
psr = pd.Series(data, index=index)
gsr = Series.from_pandas(psr)

got = gsr.isin(values)
Expand Down

0 comments on commit 6c9869a

Please sign in to comment.