Skip to content

Commit c4db0e7

Browse files
committed
move error handling; doc fixups
1 parent def74de commit c4db0e7

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

doc/source/timeseries.rst

+22
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,28 @@ Furthermore, you can also specify multiple aggregation functions for each column
14731473
r.agg({'A' : ['sum','std'], 'B' : ['mean','std'] })
14741474
14751475
1476+
If a ``DataFrame`` does not have a ``DatetimeIndex``, but instead you want
1477+
to resample based on column in the frame, it can passed to the ``on`` keyword.
1478+
1479+
.. ipython:: python
1480+
1481+
df = pd.DataFrame({'date': pd.date_range('2015-01-01', freq='W', periods=5),
1482+
'a': np.arange(5)},
1483+
index=pd.MultiIndex.from_arrays([
1484+
[1,2,3,4,5],
1485+
pd.date_range('2015-01-01', freq='W', periods=5)],
1486+
names=['v','d']))
1487+
df
1488+
df.resample('M', on='date').sum()
1489+
1490+
Similarly, if you instead want to resample by a level of ``MultiIndex``, its
1491+
name or location can be passed to the ``level`` keyword.
1492+
1493+
.. ipython:: python
1494+
1495+
df.resample(level='d').sum()
1496+
1497+
14761498
.. _timeseries.periods:
14771499

14781500
Time Span Representation

doc/source/whatsnew/v0.19.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ Other enhancements
377377

378378
pd.Timestamp(year=2012, month=1, day=1, hour=8, minute=30)
379379

380-
- the ``.resample()`` function now accepts a ``on=`` or ``key=`` parameter for resampling on a column or ``MultiIndex`` level (:issue:`13500`)
380+
- the ``.resample()`` function now accepts a ``on=`` or ``level=`` parameter for resampling on a column or ``MultiIndex`` level (:issue:`13500`)
381381

382382
.. ipython:: python
383383

pandas/core/generic.py

-5
Original file line numberDiff line numberDiff line change
@@ -4169,11 +4169,6 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
41694169
"""
41704170
from pandas.tseries.resample import (resample,
41714171
_maybe_process_deprecations)
4172-
if is_list_like(on):
4173-
raise ValueError("Only a single column may be passed to on")
4174-
if is_list_like(level):
4175-
raise ValueError("Only a single column may be passed to level")
4176-
41774172
axis = self._get_axis_number(axis)
41784173
r = resample(self, freq=rule, label=label, closed=closed,
41794174
axis=axis, kind=kind, loffset=loffset,

pandas/tseries/tests/test_resample.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,24 @@ def test_api_validation(self):
608608
actual = df.resample('M', on='date').sum()
609609
assert_frame_equal(actual, expected)
610610

611-
actual = df.resample('M', level='d').sum()
612611
expected.index.name = 'd'
612+
actual = df.resample('M', level='d').sum()
613+
assert_frame_equal(actual, expected)
614+
615+
actual = df.resample('M', level=1).sum()
613616
assert_frame_equal(actual, expected)
614617

618+
# non DatetimeIndex
619+
with tm.assertRaises(TypeError):
620+
df.resample('M', level='v')
621+
615622
with tm.assertRaises(ValueError):
616623
df.resample('M', on='date', level='d')
617624

618-
with tm.assertRaises(ValueError):
625+
with tm.assertRaises(TypeError):
619626
df.resample('M', on=['a', 'date'])
620627

621-
with tm.assertRaises(ValueError):
628+
with tm.assertRaises(KeyError):
622629
df.resample('M', level=['a', 'date'])
623630

624631

0 commit comments

Comments
 (0)