Skip to content

Commit 06843a8

Browse files
WillAydjreback
authored andcommitted
Fix Up Typing in GroupBy (#26089)
1 parent b2ef74d commit 06843a8

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Other API Changes
218218
- :meth:`Timestamp.strptime` will now rise a ``NotImplementedError`` (:issue:`25016`)
219219
- 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`)
220220
- Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`)
221+
- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`)
221222

222223
.. _whatsnew_0250.deprecations:
223224

mypy.ini

-9
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ ignore_errors=True
5959
[mypy-pandas.core.config_init]
6060
ignore_errors=True
6161

62-
[mypy-pandas.core.groupby.generic]
63-
ignore_errors=True
64-
65-
[mypy-pandas.core.groupby.groupby]
66-
ignore_errors=True
67-
68-
[mypy-pandas.core.groupby.ops]
69-
ignore_errors=True
70-
7162
[mypy-pandas.core.indexes.base]
7263
ignore_errors=True
7364

pandas/core/groupby/generic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,25 @@ def _cython_agg_blocks(self, how, alt=None, numeric_only=True,
144144

145145
return new_items, new_blocks
146146

147-
def aggregate(self, arg, *args, **kwargs):
147+
def aggregate(self, func, *args, **kwargs):
148148

149149
_level = kwargs.pop('_level', None)
150-
result, how = self._aggregate(arg, _level=_level, *args, **kwargs)
150+
result, how = self._aggregate(func, _level=_level, *args, **kwargs)
151151
if how is None:
152152
return result
153153

154154
if result is None:
155155

156156
# grouper specific aggregations
157157
if self.grouper.nkeys > 1:
158-
return self._python_agg_general(arg, *args, **kwargs)
158+
return self._python_agg_general(func, *args, **kwargs)
159159
else:
160160

161161
# try to treat as if we are passing a list
162162
try:
163163
assert not args and not kwargs
164164
result = self._aggregate_multiple_funcs(
165-
[arg], _level=_level, _axis=self.axis)
165+
[func], _level=_level, _axis=self.axis)
166166

167167
result.columns = Index(
168168
result.columns.levels[0],
@@ -174,7 +174,7 @@ def aggregate(self, arg, *args, **kwargs):
174174
# to SparseDataFrame, so we do it here.
175175
result = SparseDataFrame(result._data)
176176
except Exception:
177-
result = self._aggregate_generic(arg, *args, **kwargs)
177+
result = self._aggregate_generic(func, *args, **kwargs)
178178

179179
if not self.as_index:
180180
self._insert_inaxis_grouper_inplace(result)

pandas/core/groupby/groupby.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ class providing the base-class of operations.
1212
import datetime
1313
from functools import partial, wraps
1414
import types
15-
from typing import Optional, Tuple, Type
15+
from typing import FrozenSet, Optional, Tuple, Type
1616
import warnings
1717

1818
import numpy as np
1919

2020
from pandas._config.config import option_context
2121

22-
from pandas._libs import Timestamp, groupby as libgroupby
22+
from pandas._libs import Timestamp
23+
import pandas._libs.groupby as libgroupby
2324
from pandas.compat import set_function_name
2425
from pandas.compat.numpy import function as nv
2526
from pandas.errors import AbstractMethodError
@@ -325,7 +326,7 @@ def _group_selection_context(groupby):
325326

326327
class _GroupBy(PandasObject, SelectionMixin):
327328
_group_selection = None
328-
_apply_whitelist = frozenset()
329+
_apply_whitelist = frozenset() # type: FrozenSet[str]
329330

330331
def __init__(self, obj, keys=None, axis=0, level=None,
331332
grouper=None, exclusions=None, selection=None, as_index=True,

pandas/core/groupby/ops.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
import numpy as np
1212

13-
from pandas._libs import NaT, groupby as libgroupby, iNaT, lib, reduction
13+
from pandas._libs import NaT, iNaT, lib
14+
import pandas._libs.groupby as libgroupby
15+
import pandas._libs.reduction as reduction
1416
from pandas.compat import lzip
1517
from pandas.errors import AbstractMethodError
1618
from pandas.util._decorators import cache_readonly

0 commit comments

Comments
 (0)