16
16
iNaT ,
17
17
)
18
18
from pandas ._libs .tslibs .timezones import tz_compare
19
- from pandas ._typing import Dtype
19
+ from pandas ._typing import Dtype , DtypeObj
20
20
from pandas .util ._validators import validate_bool_kwarg
21
21
22
22
from pandas .core .dtypes .common import (
@@ -246,14 +246,27 @@ def trans(x):
246
246
return result
247
247
248
248
249
- def maybe_cast_result (result , obj , numeric_only : bool = False , how : str = "" ):
249
+ def maybe_cast_result (
250
+ result , obj : ABCSeries , numeric_only : bool = False , how : str = ""
251
+ ):
250
252
"""
251
- Try to cast the result to the desired type,
252
- we may have roundtripped through object in the mean-time.
253
+ Try casting result to a different type if appropriate
253
254
254
- If numeric_only is True, then only try to cast numerics
255
- and not datetimelikes.
255
+ Parameters
256
+ ----------
257
+ result : array-like
258
+ Result to cast.
259
+ obj : ABCSeries
260
+ Input series from which result was calculated.
261
+ numeric_only : bool, default False
262
+ Whether to cast only numerics or datetimes as well.
263
+ how : str, default ""
264
+ If result was aggregated, how the aggregation was performed.
256
265
266
+ Returns
267
+ -------
268
+ result : array-like
269
+ result maybe casted to the dtype.
257
270
"""
258
271
if obj .ndim > 1 :
259
272
dtype = obj ._values .dtype
@@ -278,21 +291,22 @@ def maybe_cast_result(result, obj, numeric_only: bool = False, how: str = ""):
278
291
return result
279
292
280
293
281
- def maybe_cast_result_dtype (dtype , how ) :
294
+ def maybe_cast_result_dtype (dtype : DtypeObj , how : str ) -> DtypeObj :
282
295
"""
283
- Get the desired dtype of a groupby result based on the
284
- input dtype and how the aggregation is done .
296
+ Get the desired dtype of a result based on the
297
+ input dtype and how it was computed .
285
298
286
299
Parameters
287
300
----------
288
- dtype : dtype, type
289
- The input dtype of the groupby .
301
+ dtype : DtypeObj
302
+ Input dtype.
290
303
how : str
291
- How the aggregation is performed .
304
+ How the result was computed .
292
305
293
306
Returns
294
307
-------
295
- The desired dtype of the aggregation result.
308
+ DtypeObj
309
+ The desired dtype of the aggregation result.
296
310
"""
297
311
d = {
298
312
(np .dtype (np .bool ), "add" ): np .dtype (np .int64 ),
0 commit comments