Skip to content

Commit 0098856

Browse files
committed
BUG: fix closed='left' erroneous resampling logic regression. close #3020
1 parent a632362 commit 0098856

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ pandas 0.11.0
194194
- Substitute warning for segfault when grouping with categorical grouper
195195
of mismatched length (GH3011_)
196196
- Fix exception in SparseSeries.density (GH2083_)
197+
- Fix upsampling bug with closed='left' and daily to daily data (GH3020_)
197198

198199
.. _GH2758: https://github.com/pydata/pandas/issues/2758
199200
.. _GH2809: https://github.com/pydata/pandas/issues/2809
200201
.. _GH2810: https://github.com/pydata/pandas/issues/2810
201202
.. _GH2837: https://github.com/pydata/pandas/issues/2837
202203
.. _GH2898: https://github.com/pydata/pandas/issues/2898
203204
.. _GH3035: https://github.com/pydata/pandas/issues/3035
205+
.. _GH3020: https://github.com/pydata/pandas/issues/3020
204206
.. _GH2978: https://github.com/pydata/pandas/issues/2978
205207
.. _GH2877: https://github.com/pydata/pandas/issues/2877
206208
.. _GH2739: https://github.com/pydata/pandas/issues/2739

pandas/tseries/resample.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ def _resample_timestamps(self, obj):
209209
else:
210210
# upsampling shortcut
211211
assert(self.axis == 0)
212-
result = obj.reindex(binner[1:], method=self.fill_method,
212+
213+
if self.closed == 'right':
214+
res_index = binner[1:]
215+
else:
216+
res_index = binner[:-1]
217+
218+
result = obj.reindex(res_index, method=self.fill_method,
213219
limit=self.limit)
214220
else:
215221
# Irregular data, have to use groupby

pandas/tseries/tests/test_resample.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,11 @@ def test_resample_median_bug_1688(self):
559559
result = df.resample("T", how=lambda x: x.mean())
560560
exp = df.asfreq('T')
561561
tm.assert_frame_equal(result, exp)
562-
562+
563563
result = df.resample("T", how="median")
564564
exp = df.asfreq('T')
565565
tm.assert_frame_equal(result, exp)
566-
566+
567567
def test_how_lambda_functions(self):
568568
ts = _simple_ts('1/1/2000', '4/1/2000')
569569

@@ -983,6 +983,14 @@ def test_all_values_single_bin(self):
983983
result = s.resample("A", how='mean')
984984
tm.assert_almost_equal(result[0], s.mean())
985985

986+
def test_resample_doesnt_truncate(self):
987+
"""Test for issue #3020"""
988+
import pandas as pd
989+
dates = pd.date_range('01-Jan-2014','05-Jan-2014', freq='D')
990+
series = Series(1, index=dates)
991+
992+
result = series.resample('D')
993+
self.assertEquals(result.index[0], dates[0])
986994

987995
class TestTimeGrouper(unittest.TestCase):
988996

0 commit comments

Comments
 (0)