Skip to content

Commit eb6bc4c

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pandas/core/groupby.py

+12
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ class Grouper(object):
233233
234234
>>> df.groupby(Grouper(level='date', freq='60s', axis=1))
235235
"""
236+
_attributes = (('key', None), ('level', None), ('freq', None),
237+
('axis', 0), ('sort', False))
236238

237239
def __new__(cls, *args, **kwargs):
238240
if kwargs.get('freq') is not None:
@@ -333,6 +335,16 @@ def _set_grouper(self, obj, sort=False):
333335
def groups(self):
334336
return self.grouper.groups
335337

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

337349
class GroupByPlot(PandasObject):
338350
"""

pandas/core/resample.py

+5
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,11 @@ 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', None), ('level', None), ('freq', 'Min'),
1029+
('sort', False), ('closed', None), ('label', None),
1030+
('how', 'mean'), ('nperiods', None), ('axis', 0),
1031+
('fill_method', None), ('limit', None), ('loffset', None),
1032+
('kind', None), ('convention', None), ('base', 0))
10281033

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

0 commit comments

Comments
 (0)