diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 7cf88a642f511..7675379c0b41b 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:`51170`) +- .. --------------------------------------------------------------------------- .. _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 = (