Skip to content

Commit

Permalink
Fix cat.as_ordered not propogating correct size (#15780)
Browse files Browse the repository at this point in the history
closes #15778

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #15780
  • Loading branch information
mroeschke authored May 21, 2024
1 parent 8b72455 commit b4daa16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ def as_ordered(self, ordered: bool):
categories=self.categories,
codes=self.codes,
mask=self.base_mask,
size=self.base_size,
size=self.size,
offset=self.offset,
ordered=ordered,
)
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 @@ -2349,3 +2349,16 @@ def test_loc_datetime_random_with_ts(data, scalar):
expected = pdf.loc[:i]

assert_eq(actual, expected)


def test_sliced_categorical_as_ordered():
df = cudf.DataFrame({"a": list("caba"), "b": list(range(4))})
df["a"] = df["a"].astype("category")
df = df.iloc[:2]
result = df["a"].cat.as_ordered()
expected = cudf.Series(
["c", "a"],
dtype=cudf.CategoricalDtype(list("abc"), ordered=True),
name="a",
)
assert_eq(result, expected)

0 comments on commit b4daa16

Please sign in to comment.