Skip to content

Commit 384026b

Browse files
committed
remove PeriodIndex workaround
1 parent c7b299e commit 384026b

File tree

4 files changed

+156
-140
lines changed

4 files changed

+156
-140
lines changed

doc/source/whatsnew/v0.19.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ Bug Fixes
948948
- Bug in ``pd.read_hdf()`` returns incorrect result when a ``DataFrame`` with a ``categorical`` column and a query which doesn't match any values (:issue:`13792`)
949949
- Bug in ``pd.to_datetime()`` raise ``AttributeError`` with NaN and the other string is not valid when errors='ignore' (:issue:`12424`)
950950

951-
- Bug in ``groupby`` where a ``TimeGrouper`` selection is used with the ``key`` or ``level`` arguments with a ``PeriodIndex`` (:issue:`14008`)
951+
952952
- Bug in ``Series`` comparison operators when dealing with zero dim NumPy arrays (:issue:`13006`)
953953
- Bug in ``groupby`` where ``apply`` returns different result depending on whether first result is ``None`` or not (:issue:`12824`)
954954
- Bug in ``groupby(..).nth()`` where the group key is included inconsistently if called after ``.head()/.tail()`` (:issue:`12839`)

pandas/core/groupby.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ def _set_grouper(self, obj, sort=False, converter=None):
257257
obj : the subject object
258258
sort : bool, default False
259259
whether the resulting grouper should be sorted
260-
converter : callable, optional
261-
conversion to apply the grouper after selection
262260
"""
263261

264262
if self.key is not None and self.level is not None:
@@ -298,8 +296,6 @@ def _set_grouper(self, obj, sort=False, converter=None):
298296
convert=False, is_copy=False)
299297

300298
self.obj = obj
301-
if converter is not None:
302-
ax = converter(ax)
303299
self.grouper = ax
304300
return self.grouper
305301

pandas/tseries/resample.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
8888
self.from_selection = False
8989

9090
if self.groupby is not None:
91-
# bookeeping to disallow upsampling if not resampling on index
91+
# upsampling and PeriodIndex resampling do not work
92+
# if resampling on a column or mi level
93+
# this is state used to catch and raise an error
9294
self.from_selection = (self.groupby.key is not None or
9395
self.groupby.level is not None)
94-
obj, converter = self._convert_obj(obj)
95-
self.groupby._set_grouper(obj, sort=True, converter=converter)
96+
obj = self._convert_obj(obj)
97+
self.groupby._set_grouper(obj, sort=True)
9698

9799
def __unicode__(self):
98100
""" provide a nice str repr of our rolling object """
@@ -208,7 +210,6 @@ def __setitem__(self, attr, value):
208210
def _convert_obj(self, obj):
209211
"""
210212
provide any conversions for the object in order to correctly handle
211-
and returns a converter function to be applied to grouping selection
212213
213214
Parameters
214215
----------
@@ -217,11 +218,9 @@ def _convert_obj(self, obj):
217218
Returns
218219
-------
219220
obj : converted object
220-
converter : callable, optional
221-
converter to apply after selection
222221
"""
223222
obj = obj.consolidate()
224-
return obj, None
223+
return obj
225224

226225
def _get_binner_for_time(self):
227226
raise AbstractMethodError(self)
@@ -768,7 +767,7 @@ def _resampler_for_grouping(self):
768767
return PeriodIndexResamplerGroupby
769768

770769
def _convert_obj(self, obj):
771-
obj, _ = super(PeriodIndexResampler, self)._convert_obj(obj)
770+
obj = super(PeriodIndexResampler, self)._convert_obj(obj)
772771

773772
offset = to_offset(self.freq)
774773
if offset.n > 1:
@@ -778,17 +777,18 @@ def _convert_obj(self, obj):
778777
# Cannot have multiple of periods, convert to timestamp
779778
self.kind = 'timestamp'
780779

781-
converter = None
782780
# convert to timestamp
783781
if not (self.kind is None or self.kind == 'period'):
784-
# if periondindex is the actual index obj, just convert it
785-
# otherwise, converter callback will be used on selection
786782
if self.from_selection:
787-
converter = lambda x: x.to_timestamp(how=self.convention)
783+
# see GH 14008, GH 12871
784+
msg = ("Resampling from level= or on= selection"
785+
" with a PeriodIndex is not currently supported,"
786+
" use .set_index(...) to explicitly set index")
787+
raise NotImplementedError(msg)
788788
else:
789789
obj = obj.to_timestamp(how=self.convention)
790790

791-
return obj, converter
791+
return obj
792792

793793
def aggregate(self, arg, *args, **kwargs):
794794
result, how = self._aggregate(arg, *args, **kwargs)

0 commit comments

Comments
 (0)