Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ca7b6f2
CLN: move PeriodIndex binning code to TimeGrouper
winklerand Apr 26, 2017
c27f430
TST/CLN: raise error when resampling with on= or level= selection
winklerand Apr 26, 2017
390e16e
BUG: resampling PeriodIndex now returns PeriodIndex (GH 12884, 15944)
winklerand Apr 26, 2017
23566c2
BUG: OHLC-upsampling of PeriodIndex now returns DataFrame (GH 13083)
winklerand Apr 26, 2017
a82879d
BUG: enable resampling with NaT in PeriodIndex (GH 13224)
winklerand Apr 26, 2017
4b1c740
CLN: remove warning on falling back to tstamp resampling with loffset
winklerand Apr 30, 2017
73c0990
CLN: use memb._isnan for NaT masking
winklerand May 1, 2017
fa6c1d3
DOC: added issue reference for OHLC resampling
winklerand May 1, 2017
7ea04e9
STYLE: added blank lines
winklerand May 1, 2017
82a8275
TST: convert to parametrized tests / pytest idiom
winklerand May 6, 2017
432c623
CLN/TST: call assert_almost_equal() when comparing Series/DataFrames
winklerand May 6, 2017
c8814fb
STYLE: added blank lines, removed odd whitespace, fixed typo
winklerand May 13, 2017
486ad67
TST: add test case for multiple consecutive NaTs in PeriodIndex
winklerand May 13, 2017
ad8519f
TST/DOC: added issue number to test case
winklerand May 13, 2017
39fc7e2
TST: consolidate test_asfreq_downsample, test_asfreq_upsample -> test…
winklerand May 13, 2017
efcad5b
TST: set fixtures to default function scoping
winklerand May 13, 2017
41401d4
TST: convert constant 'setup-like' values/objects to pytest fixtures
winklerand May 13, 2017
398a684
DOC: whatsnew v0.21.0 entry (in API changes section)
winklerand May 21, 2017
8358c41
fixups
jreback Sep 28, 2017
6084e0c
moar whatsnew
jreback Sep 29, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST/CLN: raise error when resampling with on= or level= selection
Added tests to cover all code paths, moved the check to _convert_obj() and removed then-redundant check from _upsample() method.
  • Loading branch information
winklerand authored and jreback committed Sep 29, 2017
commit c27f43048ba0c7ae7d1f0c4947d5ac253f28f628
22 changes: 9 additions & 13 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,13 @@ def _get_binner_for_time(self):
def _convert_obj(self, obj):
obj = super(PeriodIndexResampler, self)._convert_obj(obj)

if self._from_selection:
# see GH 14008, GH 12871
msg = ("Resampling from level= or on= selection"
" with a PeriodIndex is not currently supported,"
" use .set_index(...) to explicitly set index")
raise NotImplementedError(msg)

offset = to_offset(self.freq)
if offset.n > 1:
if self.kind == 'period': # pragma: no cover
Expand All @@ -852,14 +859,7 @@ def _convert_obj(self, obj):

# convert to timestamp
if not (self.kind is None or self.kind == 'period'):
if self._from_selection:
# see GH 14008, GH 12871
msg = ("Resampling from level= or on= selection"
" with a PeriodIndex is not currently supported,"
" use .set_index(...) to explicitly set index")
raise NotImplementedError(msg)
else:
obj = obj.to_timestamp(how=self.convention)
obj = obj.to_timestamp(how=self.convention)

return obj

Expand Down Expand Up @@ -906,11 +906,7 @@ def _upsample(self, method, limit=None, fill_value=None):
.fillna

"""
if self._from_selection:
raise ValueError("Upsampling from level= or on= selection"
" is not supported, use .set_index(...)"
" to explicitly set index to"
" datetime-like")

# we may need to actually resample as if we are timestamps
if self.kind == 'timestamp':
return super(PeriodIndexResampler, self)._upsample(
Expand Down
17 changes: 11 additions & 6 deletions pandas/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2294,12 +2294,17 @@ def test_selection(self):
index=pd.MultiIndex.from_arrays([
np.arange(len(index), dtype=np.int64),
index], names=['v', 'd']))

with pytest.raises(NotImplementedError):
df.resample('2D', on='date')

with pytest.raises(NotImplementedError):
df.resample('2D', level='d')
for freq in ['H', '12H', '2D', 'W']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are more clear with parametrize
but we still inherit from TestCase so can't change this

but you can start a new test class that does this

again if it's more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if I understood correctly - pushed 48e324f as an example, are you thinking along those lines of using pytest fixtures/mark.parametrize decorators?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented directly on the commit

# check up- and downsampling with base freqs and freq multiples
with pytest.raises(NotImplementedError):
df.resample(freq, on='date')
with pytest.raises(NotImplementedError):
df.resample(freq, level='d')
for kind_param in ['timestamp', 'period']:
with pytest.raises(NotImplementedError):
df.resample(freq, on='date', kind=kind_param)
with pytest.raises(NotImplementedError):
df.resample(freq, level='d', kind=kind_param)

def test_annual_upsample_D_s_f(self):
self._check_annual_upsample_cases('D', 'start', 'ffill')
Expand Down