diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 1953132c826ba..20d4f46348be6 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -218,6 +218,7 @@ Other API Changes - :meth:`Timestamp.strptime` will now rise a ``NotImplementedError`` (:issue:`25016`) - Comparing :class:`Timestamp` with unsupported objects now returns :py:obj:`NotImplemented` instead of raising ``TypeError``. This implies that unsupported rich comparisons are delegated to the other object, and are now consistent with Python 3 behavior for ``datetime`` objects (:issue:`24011`) - Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`) +- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`) .. _whatsnew_0250.deprecations: diff --git a/mypy.ini b/mypy.ini index abec13b76cc21..80c34260acdd1 100644 --- a/mypy.ini +++ b/mypy.ini @@ -59,15 +59,6 @@ ignore_errors=True [mypy-pandas.core.config_init] ignore_errors=True -[mypy-pandas.core.groupby.generic] -ignore_errors=True - -[mypy-pandas.core.groupby.groupby] -ignore_errors=True - -[mypy-pandas.core.groupby.ops] -ignore_errors=True - [mypy-pandas.core.indexes.base] ignore_errors=True diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 3519b5c078ee2..01784513704b4 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -144,10 +144,10 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True, return new_items, new_blocks - def aggregate(self, arg, *args, **kwargs): + def aggregate(self, func, *args, **kwargs): _level = kwargs.pop('_level', None) - result, how = self._aggregate(arg, _level=_level, *args, **kwargs) + result, how = self._aggregate(func, _level=_level, *args, **kwargs) if how is None: return result @@ -155,14 +155,14 @@ def aggregate(self, arg, *args, **kwargs): # grouper specific aggregations if self.grouper.nkeys > 1: - return self._python_agg_general(arg, *args, **kwargs) + return self._python_agg_general(func, *args, **kwargs) else: # try to treat as if we are passing a list try: assert not args and not kwargs result = self._aggregate_multiple_funcs( - [arg], _level=_level, _axis=self.axis) + [func], _level=_level, _axis=self.axis) result.columns = Index( result.columns.levels[0], @@ -174,7 +174,7 @@ def aggregate(self, arg, *args, **kwargs): # to SparseDataFrame, so we do it here. result = SparseDataFrame(result._data) except Exception: - result = self._aggregate_generic(arg, *args, **kwargs) + result = self._aggregate_generic(func, *args, **kwargs) if not self.as_index: self._insert_inaxis_grouper_inplace(result) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index b1936a8f5121f..bd8a8852964e3 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -12,14 +12,15 @@ class providing the base-class of operations. import datetime from functools import partial, wraps import types -from typing import Optional, Tuple, Type +from typing import FrozenSet, Optional, Tuple, Type import warnings import numpy as np from pandas._config.config import option_context -from pandas._libs import Timestamp, groupby as libgroupby +from pandas._libs import Timestamp +import pandas._libs.groupby as libgroupby from pandas.compat import set_function_name from pandas.compat.numpy import function as nv from pandas.errors import AbstractMethodError @@ -325,7 +326,7 @@ def _group_selection_context(groupby): class _GroupBy(PandasObject, SelectionMixin): _group_selection = None - _apply_whitelist = frozenset() + _apply_whitelist = frozenset() # type: FrozenSet[str] def __init__(self, obj, keys=None, axis=0, level=None, grouper=None, exclusions=None, selection=None, as_index=True, diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 8a6ec285cc79e..82b9d6c1269f9 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -10,7 +10,9 @@ import numpy as np -from pandas._libs import NaT, groupby as libgroupby, iNaT, lib, reduction +from pandas._libs import NaT, iNaT, lib +import pandas._libs.groupby as libgroupby +import pandas._libs.reduction as reduction from pandas.compat import lzip from pandas.errors import AbstractMethodError from pandas.util._decorators import cache_readonly