Skip to content

Commit 45eef38

Browse files
committed
reorder clause
1 parent 3aad776 commit 45eef38

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
@@ -131,13 +131,6 @@ def maybe_downcast_to_dtype(result, dtype):
131131
elif isinstance(result, ABCDataFrame):
132132
# occurs in pivot_table doctest
133133
return result
134-
elif dtype.type is Period:
135-
from pandas.core.arrays import PeriodArray
136-
137-
with suppress(TypeError):
138-
# e.g. TypeError: int() argument must be a string, a
139-
# bytes-like object or a number, not 'Period
140-
return PeriodArray(result, freq=dtype.freq)
141134

142135
if isinstance(dtype, str):
143136
if dtype == "infer":
@@ -162,6 +155,14 @@ def maybe_downcast_to_dtype(result, dtype):
162155

163156
dtype = np.dtype(dtype)
164157

158+
elif dtype.type is Period:
159+
from pandas.core.arrays import PeriodArray
160+
161+
with suppress(TypeError):
162+
# e.g. TypeError: int() argument must be a string, a
163+
# bytes-like object or a number, not 'Period
164+
return PeriodArray(result, freq=dtype.freq)
165+
165166
converted = maybe_downcast_numeric(result, dtype, do_round)
166167
if converted is not result:
167168
return converted

0 commit comments

Comments
 (0)