Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2290,12 +2290,12 @@ def cast(self, dtype: DtypeObj) -> ColumnBase:
def astype(self, dtype: DtypeObj, copy: bool | None = False) -> ColumnBase:
if self.dtype == dtype:
result = self
elif isinstance(dtype, CategoricalDtype):
result = self.as_categorical_column(dtype)
elif len(self) == 0:
result = column_empty(0, dtype=dtype)
else:
if isinstance(dtype, CategoricalDtype):
result = self.as_categorical_column(dtype)
elif is_dtype_obj_interval(dtype):
if is_dtype_obj_interval(dtype):
result = self.as_interval_column(dtype) # type: ignore[arg-type]
elif is_dtype_obj_list(dtype) or is_dtype_obj_struct(dtype):
if isinstance(dtype, pd.ArrowDtype):
Expand Down
7 changes: 6 additions & 1 deletion python/cudf/cudf/tests/series/methods/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ def test_cast_float_nan_to_bool_pandas_compat():
def test_empty_astype_always_castable(type1, type2, as_dtype, copy):
ser = cudf.Series([], dtype=as_dtype(type1))
result = ser.astype(as_dtype(type2), copy=copy)
expected = cudf.Series([], dtype=as_dtype(type2))
if type2 == "category":
# Empty astype to category inherits the source dtype as the
# categories dtype, matching pandas behavior.
expected = cudf.Series([], dtype=result.dtype)
else:
expected = cudf.Series([], dtype=as_dtype(type2))
assert_eq(result, expected)
if not copy and cudf.dtype(type1) == cudf.dtype(type2):
assert ser._column is result._column
Expand Down
Loading