@@ -64,7 +64,7 @@ class Resampler(_GroupBy):
64
64
'binner' , 'grouper' , 'groupby' ,
65
65
'sort' , 'kind' , 'squeeze' , 'keys' ,
66
66
'group_keys' , 'as_index' , 'exclusions' ,
67
- '_groupby' ]
67
+ '_groupby' , 'from_selection' ]
68
68
69
69
# don't raise deprecation warning on attributes starting with these
70
70
# patterns - prevents warnings caused by IPython introspection
@@ -85,8 +85,12 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
85
85
self .exclusions = set ()
86
86
self .binner = None
87
87
self .grouper = None
88
+ self .from_selection = False
88
89
89
90
if self .groupby is not None :
91
+ # bookeeping to disallow upsampling if not resampling on index
92
+ self .from_selection = (self .groupby .key is not None or
93
+ self .groupby .level is not None )
90
94
obj , converter = self ._convert_obj (obj )
91
95
self .groupby ._set_grouper (obj , sort = True , converter = converter )
92
96
@@ -711,10 +715,14 @@ def _upsample(self, method, limit=None):
711
715
.fillna
712
716
713
717
"""
714
- # import pdb; pdb.set_trace()
715
718
self ._set_binner ()
716
719
if self .axis :
717
720
raise AssertionError ('axis must be 0' )
721
+ if self .from_selection :
722
+ raise NotImplementedError ("Upsampling from level= or on= selection "
723
+ "is not supported, use .set_index(...) "
724
+ "to explicitly set index to "
725
+ "datetime-like" )
718
726
719
727
ax = self .ax
720
728
obj = self ._selected_obj
@@ -773,7 +781,13 @@ def _convert_obj(self, obj):
773
781
converter = None
774
782
# convert to timestamp
775
783
if not (self .kind is None or self .kind == 'period' ):
776
- converter = lambda x : x .to_timestamp (how = self .convention )
784
+ # if periondindex is the actual index obj, just convert it
785
+ # otherwise, converter callback will be used on selection
786
+ if self .from_selection :
787
+ converter = lambda x : x .to_timestamp (how = self .convention )
788
+ else :
789
+ obj = obj .to_timestamp (how = self .convention )
790
+
777
791
return obj , converter
778
792
779
793
def aggregate (self , arg , * args , ** kwargs ):
@@ -850,6 +864,12 @@ def _upsample(self, method, limit=None):
850
864
.fillna
851
865
852
866
"""
867
+ # import pdb; pdb.set_trace()
868
+ if self .from_selection :
869
+ raise NotImplementedError ("Upsampling from level= or on= selection "
870
+ "is not supported, use .set_index(...) "
871
+ "to explicitly set index to "
872
+ "datetime-like" )
853
873
# we may need to actually resample as if we are timestamps
854
874
if self .kind == 'timestamp' :
855
875
return super (PeriodIndexResampler , self )._upsample (method ,
0 commit comments