Skip to content

Commit 8902484

Browse files
committed
Added/improved docstrings and type hints
- Removed unnecessary import of try_cast_to_ea from arrays.__init__
1 parent e6f2408 commit 8902484

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

pandas/core/arrays/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from pandas.core.dtypes.cast import try_cast_to_ea
2-
31
from pandas.core.arrays.base import (
42
ExtensionArray,
53
ExtensionOpsMixin,
@@ -20,7 +18,6 @@
2018
"ExtensionArray",
2119
"ExtensionOpsMixin",
2220
"ExtensionScalarOpsMixin",
23-
"try_cast_to_ea",
2421
"BooleanArray",
2522
"Categorical",
2623
"DatetimeArray",

pandas/core/dtypes/cast.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
iNaT,
1717
)
1818
from pandas._libs.tslibs.timezones import tz_compare
19-
from pandas._typing import Dtype
19+
from pandas._typing import Dtype, DtypeObj
2020
from pandas.util._validators import validate_bool_kwarg
2121

2222
from pandas.core.dtypes.common import (
@@ -246,14 +246,27 @@ def trans(x):
246246
return result
247247

248248

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+
):
250252
"""
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
253254
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.
256265
266+
Returns
267+
-------
268+
result : array-like
269+
result maybe casted to the dtype.
257270
"""
258271
if obj.ndim > 1:
259272
dtype = obj._values.dtype
@@ -278,21 +291,22 @@ def maybe_cast_result(result, obj, numeric_only: bool = False, how: str = ""):
278291
return result
279292

280293

281-
def maybe_cast_result_dtype(dtype, how):
294+
def maybe_cast_result_dtype(dtype: DtypeObj, how: str) -> DtypeObj:
282295
"""
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.
285298
286299
Parameters
287300
----------
288-
dtype : dtype, type
289-
The input dtype of the groupby.
301+
dtype : DtypeObj
302+
Input dtype.
290303
how : str
291-
How the aggregation is performed.
304+
How the result was computed.
292305
293306
Returns
294307
-------
295-
The desired dtype of the aggregation result.
308+
DtypeObj
309+
The desired dtype of the aggregation result.
296310
"""
297311
d = {
298312
(np.dtype(np.bool), "add"): np.dtype(np.int64),

0 commit comments

Comments
 (0)