Skip to content

Commit 05b5761

Browse files
committed
reorder clause
1 parent bc823be commit 05b5761

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pandas/core/dtypes/cast.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,6 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
146146
elif isinstance(result, ABCDataFrame):
147147
# occurs in pivot_table doctest
148148
return result
149-
elif dtype.type is Period:
150-
from pandas.core.arrays import PeriodArray
151-
152-
with suppress(TypeError):
153-
# e.g. TypeError: int() argument must be a string, a
154-
# bytes-like object or a number, not 'Period
155-
return PeriodArray(result, freq=dtype.freq)
156149

157150
if isinstance(dtype, str):
158151
if dtype == "infer":
@@ -177,6 +170,14 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
177170

178171
dtype = np.dtype(dtype)
179172

173+
elif dtype.type is Period:
174+
from pandas.core.arrays import PeriodArray
175+
176+
with suppress(TypeError):
177+
# e.g. TypeError: int() argument must be a string, a
178+
# bytes-like object or a number, not 'Period
179+
return PeriodArray(result, freq=dtype.freq)
180+
180181
converted = maybe_downcast_numeric(result, dtype, do_round)
181182
if converted is not result:
182183
return converted

0 commit comments

Comments
 (0)