@@ -146,13 +146,6 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
146
146
elif isinstance (result , ABCDataFrame ):
147
147
# occurs in pivot_table doctest
148
148
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 )
156
149
157
150
if isinstance (dtype , str ):
158
151
if dtype == "infer" :
@@ -177,6 +170,14 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
177
170
178
171
dtype = np .dtype (dtype )
179
172
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
+
180
181
converted = maybe_downcast_numeric (result , dtype , do_round )
181
182
if converted is not result :
182
183
return converted
0 commit comments