From dc5f5006b1e7c9d5ca3649188833e0a3b44cc841 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Thu, 7 Sep 2023 10:01:37 -0500 Subject: [PATCH] Fix `IntervalIndex.union` to preserve type-metadata (#14051) 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: https://github.com/rapidsai/cudf/pull/14051 --- python/cudf/cudf/core/column/categorical.py | 13 +------------ python/cudf/cudf/core/column/column.py | 2 +- python/cudf/cudf/core/column/decimal.py | 5 +---- python/cudf/cudf/tests/test_index.py | 4 ++++ 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/python/cudf/cudf/core/column/categorical.py b/python/cudf/cudf/core/column/categorical.py index eaffc18db70..5be609c81bc 100644 --- a/python/cudf/cudf/core/column/categorical.py +++ b/python/cudf/cudf/core/column/categorical.py @@ -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 diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 9dde17a1045..a8735a1dd8d 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -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.""" diff --git a/python/cudf/cudf/core/column/decimal.py b/python/cudf/cudf/core/column/decimal.py index a8a707ec805..5a823c5f7c3 100644 --- a/python/cudf/cudf/core/column/decimal.py +++ b/python/cudf/cudf/core/column/decimal.py @@ -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): diff --git a/python/cudf/cudf/tests/test_index.py b/python/cudf/cudf/tests/test_index.py index 359b3c519de..5730ecc4ae7 100644 --- a/python/cudf/cudf/tests/test_index.py +++ b/python/cudf/cudf/tests/test_index.py @@ -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])