Skip to content

Commit deab64f

Browse files
author
tp
committed
Added repr string for Grouper and TimeGrouper
1 parent c176a3c commit deab64f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pandas/core/groupby.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class Grouper(object):
233233
234234
>>> df.groupby(Grouper(level='date', freq='60s', axis=1))
235235
"""
236+
_attributes = ('key', 'level', 'freq', 'axis', 'sort')
236237

237238
def __new__(cls, *args, **kwargs):
238239
if kwargs.get('freq') is not None:
@@ -333,6 +334,15 @@ def _set_grouper(self, obj, sort=False):
333334
def groups(self):
334335
return self.grouper.groups
335336

337+
def __repr__(self):
338+
attrs_list = []
339+
for attr_name in self._attributes:
340+
attrib_value = getattr(self, attr_name)
341+
attrs_list.append("{}={!r}".format(attr_name, attrib_value))
342+
attrs = ", ".join(attrs_list)
343+
cls_name = self.__class__.__name__
344+
return "{}({})".format(cls_name, attrs)
345+
336346

337347
class GroupByPlot(PandasObject):
338348
"""

pandas/core/resample.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,9 @@ class TimeGrouper(Grouper):
10251025
Use begin, end, nperiods to generate intervals that cannot be derived
10261026
directly from the associated object
10271027
"""
1028+
_attributes = ('key', 'level', 'freq', 'sort', 'closed', 'label',
1029+
'how', 'nperiods', 'axis', 'fill_method', 'limit', 'loffset',
1030+
'kind', 'convention', 'base')
10281031

10291032
def __init__(self, freq='Min', closed=None, label=None, how='mean',
10301033
nperiods=None, axis=0,

0 commit comments

Comments
 (0)