Skip to content

Commit 7c6e30a

Browse files
committed
BUG: period resampling bug when all values fall into a single bin. close #2070
1 parent 2842ad1 commit 7c6e30a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

RELEASE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pandas 0.10.1
106106
- Fix partial date parsing issue occuring only when code is run at EOM (GH2618_)
107107
- Prevent MemoryError when using counting sort in sortlevel with
108108
high-cardinality MultiIndex objects (GH2684_)
109+
- Fix Period resampling bug when all values fall into a single bin (GH2070_)
109110

110111
**API Changes**
111112

@@ -118,6 +119,7 @@ pandas 0.10.1
118119

119120
.. _GH512: https://github.com/pydata/pandas/issues/512
120121
.. _GH1277: https://github.com/pydata/pandas/issues/1277
122+
.. _GH2070: https://github.com/pydata/pandas/issues/2070
121123
.. _GH2327: https://github.com/pydata/pandas/issues/2327
122124
.. _GH2585: https://github.com/pydata/pandas/issues/2585
123125
.. _GH2599: https://github.com/pydata/pandas/issues/2599

pandas/tseries/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def _resample_periods(self, obj):
249249

250250
if is_subperiod(axlabels.freq, self.freq) or self.how is not None:
251251
# Downsampling
252-
rng = np.arange(memb.values[0], memb.values[-1])
252+
rng = np.arange(memb.values[0], memb.values[-1] + 1)
253253
bins = memb.searchsorted(rng, side='right')
254254
grouper = BinGrouper(bins, new_index)
255255

pandas/tseries/tests/test_resample.py

+8
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,14 @@ def test_default_left_closed_label(self):
972972
assert_frame_equal(resampled, df.resample(to_freq, closed='left',
973973
label='left'))
974974

975+
def test_all_values_single_bin(self):
976+
# 2070
977+
index = period_range(start="2012-01-01", end="2012-12-31", freq="M")
978+
s = Series(np.random.randn(len(index)), index=index)
979+
980+
result = s.resample("A", how='mean')
981+
tm.assert_almost_equal(result[0], s.mean())
982+
975983

976984
class TestTimeGrouper(unittest.TestCase):
977985

0 commit comments

Comments
 (0)