Skip to content

Commit

Permalink
Fix IntervalIndex.union to preserve type-metadata (#14051)
Browse files Browse the repository at this point in the history
Fixes: #14041 

This PR fixes `fillna` that will preserve the type-metadata for `IntervalColumn`.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #14051
  • Loading branch information
galipremsagar authored Sep 7, 2023
1 parent 7331922 commit dc5f500
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
13 changes: 1 addition & 12 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,18 +1272,7 @@ def fillna(
self.codes.dtype
)

result = super().fillna(value=fill_value, method=method)

result = column.build_categorical_column(
categories=self.dtype.categories._values,
codes=column.build_column(result.base_data, dtype=result.dtype),
offset=result.offset,
size=result.size,
mask=result.base_mask,
ordered=self.dtype.ordered,
)

return result
return super().fillna(value=fill_value, method=method)

def indices_of(
self, value: ScalarLike
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def fillna(
"""
return libcudf.replace.replace_nulls(
input_col=self, replacement=value, method=method, dtype=dtype
)
)._with_type_metadata(self.dtype)

def isnull(self) -> ColumnBase:
"""Identify missing values in a Column."""
Expand Down
5 changes: 1 addition & 4 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ def fillna(
"integer values"
)

result = libcudf.replace.replace_nulls(
input_col=self, replacement=value, method=method, dtype=dtype
)
return result._with_type_metadata(self.dtype)
return super().fillna(value=value, method=method)

def normalize_binop_value(self, other):
if isinstance(other, ColumnBase):
Expand Down
4 changes: 4 additions & 0 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,10 @@ def test_range_index_concat(objs):
(pd.Index([0, 1, 2, 30], name="a"), [90, 100]),
(pd.Index([0, 1, 2, 30]), pd.Index([0, 10, 1.0, 11])),
(pd.Index(["a", "b", "c", "d", "c"]), pd.Index(["a", "c", "z"])),
(
pd.IntervalIndex.from_tuples([(0, 2), (0, 2), (2, 4)]),
pd.IntervalIndex.from_tuples([(0, 2), (2, 4)]),
),
],
)
@pytest.mark.parametrize("sort", [None, False])
Expand Down

0 comments on commit dc5f500

Please sign in to comment.