Skip to content

Commit 0d8561e

Browse files
committed
BUG: resampling with a how could trigger asfreq instead
closes #12332
1 parent 66c23aa commit 0d8561e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v0.18.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ other anchored offsets like ``MonthBegin`` and ``YearBegin``.
581581
Resample API
582582
^^^^^^^^^^^^
583583

584-
Like the change in the window functions API :ref:`above <whatsnew_0180.enhancements.moments>`, ``.resample(...)`` is changing to have a more groupby-like API. (:issue:`11732`, :issue:`12702`, :issue:`12202`).
584+
Like the change in the window functions API :ref:`above <whatsnew_0180.enhancements.moments>`, ``.resample(...)`` is changing to have a more groupby-like API. (:issue:`11732`, :issue:`12702`, :issue:`12202`, :issue:`12332`).
585585

586586
.. ipython:: python
587587

pandas/tseries/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def _downsample(self, how, **kwargs):
500500
# do we have a regular frequency
501501
if ax.freq is not None or ax.inferred_freq is not None:
502502

503-
if len(self.grouper.binlabels) > len(ax):
503+
if len(self.grouper.binlabels) > len(ax) and how is None:
504504

505505
# let's do an asfreq
506506
return self.asfreq()

pandas/tseries/tests/test_resample.py

+13
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,19 @@ def test_resample_ohlc(self):
925925
self.assertEqual(xs['low'], s[:5].min())
926926
self.assertEqual(xs['close'], s[4])
927927

928+
def test_resample_ohlc_result(self):
929+
930+
# GH 12332
931+
index = pd.date_range('1-1-2000', '2-15-2000', freq='h')
932+
index = index.union(pd.date_range('4-15-2000', '5-15-2000', freq='h'))
933+
s = Series(range(len(index)), index=index)
934+
935+
a = s.loc[:'4-15-2000'].resample('30T').ohlc()
936+
self.assertIsInstance(a, DataFrame)
937+
938+
b = s.loc[:'4-14-2000'].resample('30T').ohlc()
939+
self.assertIsInstance(b, DataFrame)
940+
928941
def test_resample_ohlc_dataframe(self):
929942
df = (
930943
pd.DataFrame({

0 commit comments

Comments
 (0)