Skip to content

Commit

Permalink
move is_categorical_dtype()
Browse files Browse the repository at this point in the history
  • Loading branch information
kotamatsuoka committed Jun 6, 2020
1 parent 1a9fa40 commit 918b4e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,8 @@ def coerce_to_target_dtype(self, other):
if is_dtype_equal(self.dtype, dtype):
return self

if (
is_extension_array_dtype(self.dtype)
and not is_categorical_dtype(self.dtype)
and not self.is_datetime
if is_extension_array_dtype(self.dtype) and not is_categorical_dtype(
self.dtype
):
dtype = self.dtype

Expand Down Expand Up @@ -1060,6 +1058,8 @@ def coerce_to_target_dtype(self, other):
raise AssertionError(
f"possible recursion in coerce_to_target_dtype: {self} {other}"
)
if is_categorical_dtype(dtype) or self.is_datetime:
return self.astype(object)

try:
return self.astype(dtype)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/series/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ def test_replace_only_one_dictlike_arg(self):
(pd.Series([1, 2], dtype="int64"), {1: 10, 2: 20}, "int64"),
(pd.Series([True, False], dtype="bool"), {True: False}, "bool"),
(
pd.Series(pd.interval_range(0, 5), dtype=pd.IntervalDtype("int64")),
pd.Series([pd.Interval(0, 1)], dtype=pd.IntervalDtype("int64")),
{pd.Interval(0, 1): pd.Interval(10, 20)},
"interval[int64]",
),
(
pd.Series(pd.interval_range(0, 1), dtype=pd.IntervalDtype("float64")),
pd.Series([pd.Interval(0, 1)], dtype=pd.IntervalDtype("float64")),
{pd.Interval(0.0, 1.0): pd.Interval(0.2, 0.3)},
"interval[float64]",
),
Expand Down Expand Up @@ -449,5 +449,5 @@ def test_replace_only_one_dictlike_arg(self):
)
def test_replace_dtype(self, series, to_replace, expected):
# GH 33484
result = str(series.replace(to_replace).dtype)
result = series.replace(to_replace).dtype
assert expected == result

0 comments on commit 918b4e2

Please sign in to comment.