Skip to content

Commit 10c7280

Browse files
committed
NotImp -> ValueError
1 parent e203fcf commit 10c7280

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

pandas/tseries/resample.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Resampler(_GroupBy):
6464
'binner', 'grouper', 'groupby',
6565
'sort', 'kind', 'squeeze', 'keys',
6666
'group_keys', 'as_index', 'exclusions',
67-
'_groupby', 'from_selection']
67+
'_groupby', '_from_selection']
6868

6969
# don't raise deprecation warning on attributes starting with these
7070
# patterns - prevents warnings caused by IPython introspection
@@ -85,14 +85,14 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
8585
self.exclusions = set()
8686
self.binner = None
8787
self.grouper = None
88-
self.from_selection = False
88+
self._from_selection = False
8989

9090
if self.groupby is not None:
9191
# upsampling and PeriodIndex resampling do not work
9292
# if resampling on a column or mi level
9393
# this state used to catch and raise an error
94-
self.from_selection = (self.groupby.key is not None or
95-
self.groupby.level is not None)
94+
self._from_selection = (self.groupby.key is not None or
95+
self.groupby.level is not None)
9696
self.groupby._set_grouper(self._convert_obj(obj), sort=True)
9797

9898
def __unicode__(self):
@@ -716,11 +716,11 @@ def _upsample(self, method, limit=None):
716716
self._set_binner()
717717
if self.axis:
718718
raise AssertionError('axis must be 0')
719-
if self.from_selection:
720-
raise NotImplementedError("Upsampling from level= or on= selection"
721-
" is not supported, use .set_index(...)"
722-
" to explicitly set index to"
723-
" datetime-like")
719+
if self._from_selection:
720+
raise ValueError("Upsampling from level= or on= selection"
721+
" is not supported, use .set_index(...)"
722+
" to explicitly set index to"
723+
" datetime-like")
724724

725725
ax = self.ax
726726
obj = self._selected_obj
@@ -778,7 +778,7 @@ def _convert_obj(self, obj):
778778

779779
# convert to timestamp
780780
if not (self.kind is None or self.kind == 'period'):
781-
if self.from_selection:
781+
if self._from_selection:
782782
# see GH 14008, GH 12871
783783
msg = ("Resampling from level= or on= selection"
784784
" with a PeriodIndex is not currently supported,"
@@ -863,11 +863,11 @@ def _upsample(self, method, limit=None):
863863
.fillna
864864
865865
"""
866-
if self.from_selection:
867-
raise NotImplementedError("Upsampling from level= or on= selection"
868-
" is not supported, use .set_index(...)"
869-
" to explicitly set index to"
870-
" datetime-like")
866+
if self._from_selection:
867+
raise ValueError("Upsampling from level= or on= selection"
868+
" is not supported, use .set_index(...)"
869+
" to explicitly set index to"
870+
" datetime-like")
871871
# we may need to actually resample as if we are timestamps
872872
if self.kind == 'timestamp':
873873
return super(PeriodIndexResampler, self)._upsample(method,

pandas/tseries/tests/test_resample.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ def test_agg_consistency(self):
385385
result = r.agg({'r1': 'mean', 'r2': 'sum'})
386386
assert_frame_equal(result, expected)
387387

388+
# TODO: once GH 14008 is fixed, move these tests into
389+
# `Base` test class
388390
def test_agg(self):
389391
# test with all three Resampler apis and TimeGrouper
390392

@@ -635,10 +637,11 @@ def test_selection_api_validation(self):
635637
with tm.assertRaises(KeyError):
636638
df.resample('2D', level=['a', 'date'])
637639

638-
with tm.assertRaises(NotImplementedError):
640+
# upsampling not allowed
641+
with tm.assertRaises(ValueError):
639642
df.resample('2D', level='d').asfreq()
640643

641-
with tm.assertRaises(NotImplementedError):
644+
with tm.assertRaises(ValueError):
642645
df.resample('2D', on='date').asfreq()
643646

644647
exp = df_exp.resample('2D').sum()

0 commit comments

Comments
 (0)