Skip to content

Commit b60329c

Browse files
committed
Use pprint_thing in IndexGroupByGroups. Add whatsnew, docstring, and a couple typo fixes
1 parent acfa005 commit b60329c

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ Other API Changes
8787
- :class:`DatetimeTZDtype` will now standardize pytz timezones to a common timezone instance (:issue:`24713`)
8888
- ``Timestamp`` and ``Timedelta`` scalars now implement the :meth:`to_numpy` method as aliases to :meth:`Timestamp.to_datetime64` and :meth:`Timedelta.to_timedelta64`, respectively. (:issue:`24653`)
8989
- :meth:`Timestamp.strptime` will now rise a ``NotImplementedError`` (:issue:`25016`)
90-
- Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`)
90+
- Bug in :meth:`DatetimeIndex.snap` which didn't preserve the ``name`` of the input :class:`Index` (:issue:`25575`)
91+
- :meth:`Index.groupby` and dependent methods (notably :meth:`GroupBy.groups`) now return object with abbreviated repr (:issue:`1135`)
9192

9293
.. _whatsnew_0250.deprecations:
9394

pandas/core/groupby/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class providing the base-class of operations.
5454

5555
_apply_docs = dict(
5656
template="""
57-
Apply function `func` group-wise and combine the results together.
57+
Apply function `func` group-wise and combine the results together.
5858
5959
The function passed to `apply` must take a {input} as its first
6060
argument and return a DataFrame, Series or scalar. `apply` will

pandas/core/indexes/base.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,24 +5291,11 @@ def _add_logical_methods_disabled(cls):
52915291

52925292

52935293
class IndexGroupbyGroups(dict):
5294-
def __repr__(self):
5295-
nitems = get_option('display.max_rows') or len(self)
5296-
5297-
fmt = u("{{{things}}}")
5298-
pfmt = u("{key}: {val}")
5299-
5300-
pairs = []
5301-
for k, v in list(self.items()):
5302-
pairs.append(pfmt.format(key=k, val=v))
5294+
"""Dict extension to support abbreviated __repr__"""
5295+
from pandas.io.formats.printing import pprint_thing
53035296

5304-
if nitems < len(self):
5305-
print("Truncating repr")
5306-
start_cnt, end_cnt = nitems - int(nitems / 2), int(nitems / 2)
5307-
return fmt.format(things=", ".join(pairs[:start_cnt]) +
5308-
", ... , " +
5309-
", ".join(pairs[-end_cnt:]))
5310-
else:
5311-
return fmt.format(things=", ".join(pairs))
5297+
def __repr__(self):
5298+
return pprint_thing(self, max_seq_items=get_option('display.max_rows'))
53125299

53135300

53145301
def ensure_index_from_sequences(sequences, names=None):

0 commit comments

Comments
 (0)