From ca65c9dfe9700f594d1613dc3b9a065d221fe9cc Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sun, 14 Apr 2019 17:29:48 -0500 Subject: [PATCH 1/5] Removed groupby modules from mypy blacklist --- mypy.ini | 9 --------- 1 file changed, 9 deletions(-) diff --git a/mypy.ini b/mypy.ini index 31f4781e18caa..83930159adb22 100644 --- a/mypy.ini +++ b/mypy.ini @@ -74,15 +74,6 @@ ignore_errors=True [mypy-pandas.core.generic] 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 From ac433a471d39bf9c5aca35595c60e1c38b78a27f Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sun, 14 Apr 2019 17:40:35 -0500 Subject: [PATCH 2/5] Fixed typing issues in pandas.core.groupby --- pandas/core/groupby/generic.py | 10 +++++----- pandas/core/groupby/groupby.py | 7 ++++--- pandas/core/groupby/ops.py | 4 +++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index b6fc31bb6f015..7e0a763d749d8 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -179,10 +179,10 @@ def _post_process_cython_aggregate(self, obj): obj = obj.swapaxes(0, 1) return obj - 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 @@ -190,14 +190,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], @@ -209,7 +209,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 2494cf55d2e0d..632f56cd2c99c 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 +import pandas._libs.groupby as libgroupby +from pandas._libs import Timestamp import pandas.compat as compat from pandas.compat import set_function_name from pandas.compat.numpy import function as nv @@ -326,7 +327,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 ec22548de6da3..d2bd6e7862d2a 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 +import pandas._libs.groupby as libgroupby +import pandas._libs.reduction as reduction +from pandas._libs import NaT, iNaT, lib from pandas.compat import lzip from pandas.errors import AbstractMethodError from pandas.util._decorators import cache_readonly From 00ea6748290089b9e9999ddfe5a6990037e812f9 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 15 Apr 2019 08:41:56 -0700 Subject: [PATCH 3/5] isort fixup --- pandas/core/groupby/groupby.py | 3 +-- pandas/core/groupby/ops.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 04616f4aae06d..bd8a8852964e3 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -19,9 +19,8 @@ class providing the base-class of operations. from pandas._config.config import option_context -import pandas._libs.groupby as libgroupby from pandas._libs import Timestamp -from pandas._libs import Timestamp, groupby as libgroupby +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 diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index d2bd6e7862d2a..11c08aa68310d 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -10,9 +10,9 @@ import numpy as np +from pandas._libs import NaT, iNaT, lib import pandas._libs.groupby as libgroupby import pandas._libs.reduction as reduction -from pandas._libs import NaT, iNaT, lib from pandas.compat import lzip from pandas.errors import AbstractMethodError from pandas.util._decorators import cache_readonly From edf64fa7976cdcbcdb37a5cedc3e0bdc640c8c7f Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 15 Apr 2019 09:15:57 -0700 Subject: [PATCH 4/5] Added whatsnew --- doc/source/whatsnew/v0.25.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index da712f84eb1b5..246053d073f03 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`` to match the signature of its superclass (:issue:`26089`) .. _whatsnew_0250.deprecations: From 162efaa09a64d1ab51f5c541919b8d4fdca5de05 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 17 Apr 2019 09:02:46 -0700 Subject: [PATCH 5/5] Updated whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 958b104bfa1fb..20d4f46348be6 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -218,7 +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`` to match the signature of its superclass (:issue:`26089`) +- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`) .. _whatsnew_0250.deprecations: