Skip to content

Commit 9084246

Browse files
committed
Test SparseSeries.reindex with fill_value and nearest
1 parent d6a46da commit 9084246

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pandas/tests/sparse/test_indexing.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_reindex(self):
366366
exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse()
367367
tm.assert_sp_series_equal(res, exp)
368368

369-
def test_reindex_fill_value(self):
369+
def test_fill_value_reindex(self):
370370
orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE'))
371371
sparse = orig.to_sparse(fill_value=0)
372372

@@ -397,6 +397,23 @@ def test_reindex_fill_value(self):
397397
exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0)
398398
tm.assert_sp_series_equal(res, exp)
399399

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+
400417
def tests_indexing_with_sparse(self):
401418
# GH 13985
402419

0 commit comments

Comments
 (0)