Skip to content

Commit a119f6e

Browse files
committed
short circut only for the dtype
1 parent d712505 commit a119f6e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/core/dtypes/dtypes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ def update_dtype(self, dtype: str_type | CategoricalDtype) -> CategoricalDtype:
611611
dtype = cast(CategoricalDtype, dtype)
612612

613613
# update categories/ordered unless they've been explicitly passed as None
614-
if dtype.categories is not None and dtype.ordered is not None:
614+
if (
615+
isinstance(dtype, CategoricalDtype)
616+
and dtype.categories is not None
617+
and dtype.ordered is not None
618+
):
615619
# Avoid re-validation in CategoricalDtype constructor
616620
return dtype
617621
new_categories = (

pandas/tests/dtypes/test_dtypes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ def test_repr_range_categories(self):
222222

223223
def test_update_dtype(self):
224224
# GH 27338
225-
result = CategoricalDtype(["a"]).update_dtype(
226-
CategoricalDtype(["b"], ordered=True)
227-
)
225+
result = CategoricalDtype(["a"]).update_dtype(Categorical(["b"], ordered=True))
228226
expected = CategoricalDtype(["b"], ordered=True)
229227
assert result == expected
230228

0 commit comments

Comments
 (0)