@@ -1087,6 +1087,38 @@ def test_resample_doesnt_truncate(self):
10871087 result = series .resample ('D' )
10881088 self .assertEquals (result .index [0 ], dates [0 ])
10891089
1090+ def test_evenly_divisible_with_no_extra_bins (self ):
1091+ # 4076
1092+ # when the frequency is evenly divisible, sometimes extra bins
1093+
1094+ df = DataFrame (np .random .randn (9 , 3 ), index = date_range ('2000-1-1' , periods = 9 ))
1095+ result = df .resample ('5D' )
1096+ expected = pd .concat ([df .iloc [0 :5 ].mean (),df .iloc [5 :].mean ()],axis = 1 ).T
1097+ expected .index = [Timestamp ('2000-1-1' ),Timestamp ('2000-1-6' )]
1098+ assert_frame_equal (result ,expected )
1099+
1100+ index = date_range (start = '2001-5-4' , periods = 28 )
1101+ df = DataFrame (
1102+ [{'REST_KEY' : 1 , 'DLY_TRN_QT' : 80 , 'DLY_SLS_AMT' : 90 ,
1103+ 'COOP_DLY_TRN_QT' : 30 , 'COOP_DLY_SLS_AMT' : 20 }] * 28 +
1104+ [{'REST_KEY' : 2 , 'DLY_TRN_QT' : 70 , 'DLY_SLS_AMT' : 10 ,
1105+ 'COOP_DLY_TRN_QT' : 50 , 'COOP_DLY_SLS_AMT' : 20 }] * 28 ,
1106+ index = index .append (index )).sort ()
1107+
1108+ index = date_range ('2001-5-4' ,periods = 4 ,freq = '7D' )
1109+ expected = DataFrame (
1110+ [{'REST_KEY' : 14 , 'DLY_TRN_QT' : 14 , 'DLY_SLS_AMT' : 14 ,
1111+ 'COOP_DLY_TRN_QT' : 14 , 'COOP_DLY_SLS_AMT' : 14 }] * 4 ,
1112+ index = index ).unstack ().swaplevel (1 ,0 ).sortlevel ()
1113+ result = df .resample ('7D' , how = 'count' )
1114+ assert_series_equal (result ,expected )
1115+
1116+ expected = DataFrame (
1117+ [{'REST_KEY' : 21 , 'DLY_TRN_QT' : 1050 , 'DLY_SLS_AMT' : 700 ,
1118+ 'COOP_DLY_TRN_QT' : 560 , 'COOP_DLY_SLS_AMT' : 280 }] * 4 ,
1119+ index = index )
1120+ result = df .resample ('7D' , how = 'sum' )
1121+ assert_frame_equal (result ,expected )
10901122
10911123class TestTimeGrouper (tm .TestCase ):
10921124
0 commit comments