Skip to content

Commit 918b4e2

Browse files
committed
move is_categorical_dtype()
1 parent 1a9fa40 commit 918b4e2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pandas/core/internals/blocks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,8 @@ def coerce_to_target_dtype(self, other):
10101010
if is_dtype_equal(self.dtype, dtype):
10111011
return self
10121012

1013-
if (
1014-
is_extension_array_dtype(self.dtype)
1015-
and not is_categorical_dtype(self.dtype)
1016-
and not self.is_datetime
1013+
if is_extension_array_dtype(self.dtype) and not is_categorical_dtype(
1014+
self.dtype
10171015
):
10181016
dtype = self.dtype
10191017

@@ -1060,6 +1058,8 @@ def coerce_to_target_dtype(self, other):
10601058
raise AssertionError(
10611059
f"possible recursion in coerce_to_target_dtype: {self} {other}"
10621060
)
1061+
if is_categorical_dtype(dtype) or self.is_datetime:
1062+
return self.astype(object)
10631063

10641064
try:
10651065
return self.astype(dtype)

pandas/tests/series/methods/test_replace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ def test_replace_only_one_dictlike_arg(self):
414414
(pd.Series([1, 2], dtype="int64"), {1: 10, 2: 20}, "int64"),
415415
(pd.Series([True, False], dtype="bool"), {True: False}, "bool"),
416416
(
417-
pd.Series(pd.interval_range(0, 5), dtype=pd.IntervalDtype("int64")),
417+
pd.Series([pd.Interval(0, 1)], dtype=pd.IntervalDtype("int64")),
418418
{pd.Interval(0, 1): pd.Interval(10, 20)},
419419
"interval[int64]",
420420
),
421421
(
422-
pd.Series(pd.interval_range(0, 1), dtype=pd.IntervalDtype("float64")),
422+
pd.Series([pd.Interval(0, 1)], dtype=pd.IntervalDtype("float64")),
423423
{pd.Interval(0.0, 1.0): pd.Interval(0.2, 0.3)},
424424
"interval[float64]",
425425
),
@@ -449,5 +449,5 @@ def test_replace_only_one_dictlike_arg(self):
449449
)
450450
def test_replace_dtype(self, series, to_replace, expected):
451451
# GH 33484
452-
result = str(series.replace(to_replace).dtype)
452+
result = series.replace(to_replace).dtype
453453
assert expected == result

0 commit comments

Comments
 (0)