From 1a4fffef537344784fd109a06a2afda9b6a54b1c Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 4 Feb 2023 13:36:25 -0800 Subject: [PATCH 1/2] API: remove Grouper.groups --- doc/source/whatsnew/v2.0.0.rst | 2 ++ pandas/core/groupby/grouper.py | 9 +-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 7cf88a642f511..2a59b96d4a111 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,6 +761,8 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) +- Removed :attr:`Grouper.groups`, which would have raised ``AttributeError`` if accessed (:issue:`??`) +- .. --------------------------------------------------------------------------- .. _whatsnew_200.deprecations: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index d77ad59a4bb82..2f2900cd6f11d 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -268,7 +268,6 @@ def __init__( self.sort = sort self.dropna = dropna - self.grouper = None self._gpr_index = None self.obj = None self.indexer = None @@ -328,7 +327,7 @@ def _set_grouper(self, obj: NDFrame, sort: bool = False) -> None: if self.key is not None and self.level is not None: raise ValueError("The Grouper cannot specify both a key and a level!") - # Keep self.grouper value before overriding + # Keep self._grouper value before overriding if self._grouper is None: # TODO: What are we assuming about subsequent calls? self._grouper = self._gpr_index @@ -387,12 +386,6 @@ def _set_grouper(self, obj: NDFrame, sort: bool = False) -> None: self.obj = obj # type: ignore[assignment] self._gpr_index = ax - @final - @property - def groups(self): - # error: "None" has no attribute "groups" - return self.grouper.groups # type: ignore[attr-defined] - @final def __repr__(self) -> str: attrs_list = ( From 920d36b9d195f54e4a07fd790d85ab4f9183a58d Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 4 Feb 2023 13:37:07 -0800 Subject: [PATCH 2/2] GH ref --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 2a59b96d4a111..7675379c0b41b 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,7 +761,7 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) -- Removed :attr:`Grouper.groups`, which would have raised ``AttributeError`` if accessed (:issue:`??`) +- Removed :attr:`Grouper.groups`, which would have raised ``AttributeError`` if accessed (:issue:`51170`) - .. ---------------------------------------------------------------------------