@@ -366,7 +366,7 @@ def test_reindex(self):
366
366
exp = orig .reindex (['A' , 'E' , 'C' , 'D' ]).to_sparse ()
367
367
tm .assert_sp_series_equal (res , exp )
368
368
369
- def test_reindex_fill_value (self ):
369
+ def test_fill_value_reindex (self ):
370
370
orig = pd .Series ([1 , np .nan , 0 , 3 , 0 ], index = list ('ABCDE' ))
371
371
sparse = orig .to_sparse (fill_value = 0 )
372
372
@@ -397,6 +397,23 @@ def test_reindex_fill_value(self):
397
397
exp = orig .reindex (['A' , 'E' , 'C' , 'D' ]).to_sparse (fill_value = 0 )
398
398
tm .assert_sp_series_equal (res , exp )
399
399
400
+ def test_reindex_fill_value (self ):
401
+ floats = pd .Series ([1. , 2. , 3. ]).to_sparse ()
402
+ result = floats .reindex ([1 , 2 , 3 ], fill_value = 0 )
403
+ expected = pd .Series ([2. , 3. , 0 ], index = [1 , 2 , 3 ]).to_sparse ()
404
+ tm .assert_sp_series_equal (result , expected )
405
+
406
+ def test_reindex_nearest (self ):
407
+ s = pd .Series (np .arange (10 , dtype = 'float64' )).to_sparse ()
408
+ target = [0.1 , 0.9 , 1.5 , 2.0 ]
409
+ actual = s .reindex (target , method = 'nearest' )
410
+ expected = pd .Series (np .around (target ), target ).to_sparse ()
411
+ tm .assert_sp_series_equal (expected , actual )
412
+
413
+ actual = s .reindex (target , method = 'nearest' , tolerance = 0.2 )
414
+ expected = pd .Series ([0 , 1 , np .nan , 2 ], target ).to_sparse ()
415
+ tm .assert_sp_series_equal (expected , actual )
416
+
400
417
def tests_indexing_with_sparse (self ):
401
418
# GH 13985
402
419
0 commit comments