Skip to content

TYPING/DOC: Move custom type to _typing and add whatsnew #35220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 11, 2020
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ Other enhancements
- :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`).
- :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`)
- :class:`pandas.core.window.ExponentialMovingWindow` now supports a ``times`` argument that allows ``mean`` to be calculated with observations spaced by the timestamps in ``times`` (:issue:`34839`)
- :meth:`DataFrame.agg` and :meth:`Series.agg` now accept named aggregation for renaming the output columns/indexes. (:issue:`26513`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologize that somehow i didn't notice there wasn't a whatsnew note.

Added here!


.. ---------------------------------------------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@
# DataFrame::sort_index, among others
ValueKeyFunc = Optional[Callable[["Series"], Union["Series", AnyArrayLike]]]
IndexKeyFunc = Optional[Callable[["Index"], Union["Index", AnyArrayLike]]]

# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
AggFuncTypeBase = Union[Callable, str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a more generic name you can think of than AggFuncTypeBase I think would be useful in other areas that aren't aggregations; i.e. in groupby a lot we accept a callable / str and resolve the latter to a builtin or NumPy func if we can, which could use this same type

AggFuncType = Union[
AggFuncTypeBase,
List[AggFuncTypeBase],
Dict[Label, Union[AggFuncTypeBase, List[AggFuncTypeBase]]],
]
10 changes: 1 addition & 9 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Union,
)

from pandas._typing import Label
from pandas._typing import AggFuncType, Label

from pandas.core.dtypes.common import is_dict_like, is_list_like

Expand All @@ -26,14 +26,6 @@
from pandas.core.indexes.api import Index
from pandas.core.series import FrameOrSeriesUnion, Series

# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
AggFuncTypeBase = Union[Callable, str]
AggFuncType = Union[
AggFuncTypeBase,
List[AggFuncTypeBase],
Dict[Label, Union[AggFuncTypeBase, List[AggFuncTypeBase]]],
]


def reconstruct_func(
func: Optional[AggFuncType], **kwargs,
Expand Down