Skip to content

Commit 7f9add4

Browse files
committed
more wip
1 parent b55309a commit 7f9add4

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

pandas/core/groupby.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,18 @@ def _get_grouper(self, obj):
247247
sort=self.sort)
248248
return self.binner, self.grouper, self.obj
249249

250-
def _set_grouper(self, obj, sort=False):
250+
def _set_grouper(self, obj, sort=False, converter=None):
251251
"""
252252
given an object and the specifications, setup the internal grouper
253253
for this particular specification
254254
255255
Parameters
256256
----------
257257
obj : the subject object
258-
258+
sort : bool, default False
259+
whether the resulting grouper should be sorted
260+
converter : callable, optional
261+
conversion to apply the grouper after selection
259262
"""
260263

261264
if self.key is not None and self.level is not None:
@@ -295,6 +298,8 @@ def _set_grouper(self, obj, sort=False):
295298
convert=False, is_copy=False)
296299

297300
self.obj = obj
301+
if converter is not None:
302+
ax = converter(ax)
298303
self.grouper = ax
299304
return self.grouper
300305

pandas/tseries/resample.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
8787
self.grouper = None
8888

8989
if self.groupby is not None:
90-
self.groupby._set_grouper(self._convert_obj(obj), sort=True)
90+
obj, converter = self._convert_obj(obj)
91+
self.groupby._set_grouper(obj, sort=True, converter=converter)
9192

9293
def __unicode__(self):
9394
""" provide a nice str repr of our rolling object """
@@ -203,13 +204,20 @@ def __setitem__(self, attr, value):
203204
def _convert_obj(self, obj):
204205
"""
205206
provide any conversions for the object in order to correctly handle
207+
and returns a converter function to be applied to grouping selection
206208
207209
Parameters
208210
----------
209211
obj : the object to be resampled
212+
213+
Returns
214+
-------
215+
obj : converted object
216+
converter : callable, optional
217+
converter to apply after selection
210218
"""
211219
obj = obj.consolidate()
212-
return obj
220+
return obj, None
213221

214222
def _get_binner_for_time(self):
215223
raise AbstractMethodError(self)
@@ -703,6 +711,7 @@ def _upsample(self, method, limit=None):
703711
.fillna
704712
705713
"""
714+
# import pdb; pdb.set_trace()
706715
self._set_binner()
707716
if self.axis:
708717
raise AssertionError('axis must be 0')
@@ -751,7 +760,7 @@ def _resampler_for_grouping(self):
751760
return PeriodIndexResamplerGroupby
752761

753762
def _convert_obj(self, obj):
754-
obj = super(PeriodIndexResampler, self)._convert_obj(obj)
763+
obj, _ = super(PeriodIndexResampler, self)._convert_obj(obj)
755764

756765
offset = to_offset(self.freq)
757766
if offset.n > 1:
@@ -761,10 +770,11 @@ def _convert_obj(self, obj):
761770
# Cannot have multiple of periods, convert to timestamp
762771
self.kind = 'timestamp'
763772

773+
converter = None
764774
# convert to timestamp
765775
if not (self.kind is None or self.kind == 'period'):
766-
obj = obj.to_timestamp(how=self.convention)
767-
return obj
776+
converter = lambda x: x.to_timestamp(how=self.convention)
777+
return obj, converter
768778

769779
def aggregate(self, arg, *args, **kwargs):
770780
result, how = self._aggregate(arg, *args, **kwargs)
@@ -1002,7 +1012,6 @@ def _get_resampler(self, obj, kind=None):
10021012
TypeError if incompatible axis
10031013
10041014
"""
1005-
import pdb; pdb.set_trace()
10061015
self._set_grouper(obj)
10071016

10081017
ax = self.ax

0 commit comments

Comments
 (0)