@@ -361,29 +361,6 @@ def test_fillna(self):
361
361
with self .assertRaises (ValueError ):
362
362
r .fillna (0 )
363
363
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
-
387
364
def test_apply_without_aggregation (self ):
388
365
389
366
# both resample and groupby should work w/o aggregation
@@ -716,6 +693,24 @@ def test_asfreq_upsample(self):
716
693
expected = frame .reindex (new_index )
717
694
assert_frame_equal (result , expected )
718
695
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
+
719
714
def test_resample_interpolate (self ):
720
715
# # 12925
721
716
df = self .create_series ().to_frame ('value' )
@@ -2145,6 +2140,25 @@ def test_asfreq_upsample(self):
2145
2140
result = frame .resample ('1H' ).asfreq ()
2146
2141
assert_frame_equal (result , expected )
2147
2142
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
+
2148
2162
def test_selection (self ):
2149
2163
index = self .create_series ().index
2150
2164
# This is a bug, these should be implemented
0 commit comments