Skip to content

Commit c0d4339

Browse files
scarijreback
authored andcommitted
BUG: Resample BM/BQ adds extra index point #9756
1 parent 43b6c3f commit c0d4339

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

doc/source/whatsnew/v0.16.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Bug Fixes
287287

288288
- Bug where dividing a dataframe containing values of type ``Decimal`` by another ``Decimal`` would raise. (:issue:`9787`)
289289
- Bug where using DataFrames asfreq would remove the name of the index. (:issue:`9885`)
290+
- Bug causing extra index point when resample BM/BQ (:issue:`9756`)
290291
- Changed caching in ``AbstractHolidayCalendar`` to be at the instance level rather than at the class level as the latter can result in unexpected behaviour. (:issue:`9552`)
291292

292293
- Fixed latex output for multi-indexed dataframes (:issue:`9778`)

pandas/tests/test_groupby.py

+10
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,16 @@ def demean(arr):
966966
expected = DataFrame({'b' : range(5)})
967967
tm.assert_frame_equal(result, expected)
968968

969+
def test_resample_extra_index_point(self):
970+
# GH 9756
971+
expected_i = pd.DatetimeIndex(start='20150101', end='20150331', freq='BM')
972+
expected = pd.DataFrame(index=expected_i, data=len(expected_i)*[0])
973+
974+
index = pd.DatetimeIndex(start='20150101', end='20150331', freq='B')
975+
df = pd.DataFrame(index=index, data=len(index)*[0])
976+
result = df.resample('BM', how='last')
977+
assert_frame_equal(result, expected)
978+
969979
def test_transform_fast(self):
970980

971981
df = DataFrame( { 'id' : np.arange( 100000 ) / 3,

pandas/tseries/frequencies.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def is_subperiod(source, target):
989989
return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
990990
elif _is_quarterly(target):
991991
return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
992-
elif target == 'M':
992+
elif _is_monthly(target):
993993
return source in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
994994
elif _is_weekly(target):
995995
return source in [target, 'D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
@@ -1048,7 +1048,7 @@ def is_superperiod(source, target):
10481048
return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
10491049
elif _is_quarterly(source):
10501050
return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
1051-
elif source == 'M':
1051+
elif _is_monthly(source):
10521052
return target in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
10531053
elif _is_weekly(source):
10541054
return target in [source, 'D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
@@ -1093,7 +1093,12 @@ def _quarter_months_conform(source, target):
10931093

10941094
def _is_quarterly(rule):
10951095
rule = rule.upper()
1096-
return rule == 'Q' or rule.startswith('Q-')
1096+
return rule == 'Q' or rule.startswith('Q-') or rule.startswith('BQ')
1097+
1098+
1099+
def _is_monthly(rule):
1100+
rule = rule.upper()
1101+
return rule == 'M' or rule == 'BM'
10971102

10981103

10991104
def _is_weekly(rule):

0 commit comments

Comments
 (0)