@@ -361,29 +361,6 @@ def test_fillna(self):
361361 with self .assertRaises (ValueError ):
362362 r .fillna (0 )
363363
364- def test_fill_value (self ):
365- # test for fill value during resampling, issue 3715
366-
367- # setup
368- rng = pd .date_range ('1/1/2016' , periods = 10 , freq = '2S' )
369- ts = pd .Series (np .arange (len (rng )), index = rng )
370- ts2 = pd .Series (np .random .rand (len (rng )), index = rng )
371- df = pd .DataFrame ({'one' : ts , 'two' : ts2 })
372-
373- # insert pre-existing missing value
374- df .loc ['2016-01-01 00:00:08' , 'two' ] = None
375-
376- actual_df = df .resample ('1S' ).asfreq (fill_value = 9.0 )
377-
378- expected_df = df .resample ('1S' ).asfreq ().fillna (9.0 )
379- expected_df .loc ['2016-01-01 00:00:08' , 'two' ] = None
380-
381- assert_frame_equal (expected_df , actual_df )
382-
383- expected_series = ts .asfreq (freq = '1S' ).fillna (9.0 )
384- actual_series = ts .asfreq (freq = '1S' , fill_value = 9.0 )
385- assert_series_equal (expected_series , actual_series )
386-
387364 def test_apply_without_aggregation (self ):
388365
389366 # both resample and groupby should work w/o aggregation
@@ -716,6 +693,24 @@ def test_asfreq_upsample(self):
716693 expected = frame .reindex (new_index )
717694 assert_frame_equal (result , expected )
718695
696+ def test_asfreq_fill_value (self ):
697+ # test for fill value during resampling, issue 3715
698+
699+ s = self .create_series ()
700+
701+ result = s .resample ('1H' ).asfreq ()
702+ new_index = self .create_index (s .index [0 ], s .index [- 1 ], freq = '1H' )
703+ expected = s .reindex (new_index )
704+ assert_series_equal (result , expected )
705+
706+ frame = s .to_frame ('value' )
707+ frame .iloc [1 ] = None
708+ result = frame .resample ('1H' ).asfreq (fill_value = 4.0 )
709+ new_index = self .create_index (frame .index [0 ],
710+ frame .index [- 1 ], freq = '1H' )
711+ expected = frame .reindex (new_index , fill_value = 4.0 )
712+ assert_frame_equal (result , expected )
713+
719714 def test_resample_interpolate (self ):
720715 # # 12925
721716 df = self .create_series ().to_frame ('value' )
@@ -2145,6 +2140,25 @@ def test_asfreq_upsample(self):
21452140 result = frame .resample ('1H' ).asfreq ()
21462141 assert_frame_equal (result , expected )
21472142
2143+ def test_asfreq_fill_value (self ):
2144+ # test for fill value during resampling, issue 3715
2145+
2146+ s = self .create_series ()
2147+ new_index = date_range (s .index [0 ].to_timestamp (how = 'start' ),
2148+ (s .index [- 1 ]).to_timestamp (how = 'start' ),
2149+ freq = '1H' )
2150+ expected = s .to_timestamp ().reindex (new_index , fill_value = 4.0 )
2151+ result = s .resample ('1H' , kind = 'timestamp' ).asfreq (fill_value = 4.0 )
2152+ assert_series_equal (result , expected )
2153+
2154+ frame = s .to_frame ('value' )
2155+ new_index = date_range (frame .index [0 ].to_timestamp (how = 'start' ),
2156+ (frame .index [- 1 ]).to_timestamp (how = 'start' ),
2157+ freq = '1H' )
2158+ expected = frame .to_timestamp ().reindex (new_index , fill_value = 3.0 )
2159+ result = frame .resample ('1H' , kind = 'timestamp' ).asfreq (fill_value = 3.0 )
2160+ assert_frame_equal (result , expected )
2161+
21482162 def test_selection (self ):
21492163 index = self .create_series ().index
21502164 # This is a bug, these should be implemented
0 commit comments