Skip to content

Commit 8d44d91

Browse files
committed
TST: Parameterized on data parameter in sparse where tests
1 parent 31d1867 commit 8d44d91

File tree

2 files changed

+48
-188
lines changed

2 files changed

+48
-188
lines changed

pandas/tests/sparse/test_frame.py

+24-94
Original file line numberDiff line numberDiff line change
@@ -1386,97 +1386,21 @@ def test_numpy_func_call(self):
13861386
for func in funcs:
13871387
getattr(np, func)(self.frame)
13881388

1389-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1390-
'(GH 17386)')
1391-
def test_where_with_int_data(self):
1392-
# GH 17386
1393-
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1394-
lower_bound = 2.5
1395-
1396-
sparse = SparseDataFrame(data)
1397-
result = sparse.where(sparse > lower_bound)
1398-
1399-
dense = DataFrame(data)
1400-
dense_expected = dense.where(dense > lower_bound)
1401-
sparse_expected = SparseDataFrame(dense_expected)
1402-
1403-
tm.assert_frame_equal(result, dense_expected)
1404-
tm.assert_sp_frame_equal(result, sparse_expected)
1405-
1406-
@pytest.mark.parametrize('other', [
1407-
True,
1408-
-100,
1409-
0.1,
1410-
100.0 + 100.0j
1411-
])
1412-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1413-
'(GH 17386)')
1414-
def test_where_with_int_data_and_other(self, other):
1415-
# GH 17386
1416-
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1417-
lower_bound = 2.5
1418-
1419-
sparse = SparseDataFrame(data)
1420-
result = sparse.where(sparse > lower_bound, other)
1421-
1422-
dense = DataFrame(data)
1423-
dense_expected = dense.where(dense > lower_bound, other)
1424-
sparse_expected = SparseDataFrame(dense_expected,
1425-
default_fill_value=other)
1426-
1427-
tm.assert_frame_equal(result, dense_expected)
1428-
tm.assert_sp_frame_equal(result, sparse_expected)
1429-
1430-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1431-
'(GH 17386)')
1432-
def test_where_with_float_data(self):
1433-
# GH 17386
1434-
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1435-
lower_bound = 2.5
1436-
1437-
sparse = SparseDataFrame(data)
1438-
result = sparse.where(sparse > lower_bound)
1439-
1440-
dense = DataFrame(data)
1441-
dense_expected = dense.where(dense > lower_bound)
1442-
sparse_expected = SparseDataFrame(dense_expected)
1443-
1444-
tm.assert_frame_equal(result, dense_expected)
1445-
tm.assert_sp_frame_equal(result, sparse_expected)
1446-
1447-
@pytest.mark.parametrize('other', [
1448-
True,
1449-
0,
1450-
0.1,
1451-
100.0 + 100.0j
1389+
@pytest.mark.parametrize('data', [
1390+
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
1391+
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]],
1392+
[
1393+
[1.0, 1.0 + 1.0j],
1394+
[2.0 + 2.0j, 2.0],
1395+
[3.0, 3.0 + 3.0j],
1396+
[4.0 + 4.0j, 4.0],
1397+
[nan, nan]
1398+
]
14521399
])
14531400
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
14541401
'(GH 17386)')
1455-
def test_where_with_float_data_and_other(self, other):
1402+
def test_where_with_numeric_data(self, data):
14561403
# GH 17386
1457-
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1458-
lower_bound = 2.5
1459-
1460-
sparse = SparseDataFrame(data)
1461-
result = sparse.where(sparse > lower_bound, other)
1462-
1463-
dense = DataFrame(data)
1464-
dense_expected = dense.where(dense > lower_bound, other)
1465-
sparse_expected = SparseDataFrame(dense_expected,
1466-
default_fill_value=other)
1467-
1468-
tm.assert_frame_equal(result, dense_expected)
1469-
tm.assert_sp_frame_equal(result, sparse_expected)
1470-
1471-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1472-
'(GH 17386)')
1473-
def test_where_with_complex_data(self):
1474-
# GH 17386
1475-
data = [[1.0, 1.0 + 1.0j],
1476-
[2.0 + 2.0j, 2.0],
1477-
[3.0, 3.0 + 3.0j],
1478-
[4.0 + 4.0j, 4.0],
1479-
[nan, nan]]
14801404
lower_bound = 1.5
14811405

14821406
sparse = SparseDataFrame(data)
@@ -1489,21 +1413,27 @@ def test_where_with_complex_data(self):
14891413
tm.assert_frame_equal(result, dense_expected)
14901414
tm.assert_sp_frame_equal(result, sparse_expected)
14911415

1416+
@pytest.mark.parametrize('data', [
1417+
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
1418+
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]],
1419+
[
1420+
[1.0, 1.0 + 1.0j],
1421+
[2.0 + 2.0j, 2.0],
1422+
[3.0, 3.0 + 3.0j],
1423+
[4.0 + 4.0j, 4.0],
1424+
[nan, nan]
1425+
]
1426+
])
14921427
@pytest.mark.parametrize('other', [
14931428
True,
1494-
0,
1429+
-100,
14951430
0.1,
14961431
100.0 + 100.0j
14971432
])
14981433
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
14991434
'(GH 17386)')
1500-
def test_where_with_complex_data_and_other(self, other):
1435+
def test_where_with_numeric_data_and_other(self, data, other):
15011436
# GH 17386
1502-
data = [[1.0, 1.0 + 1.0j],
1503-
[2.0 + 2.0j, 2.0],
1504-
[3.0, 3.0 + 3.0j],
1505-
[4.0 + 4.0j, 4.0],
1506-
[nan, nan]]
15071437
lower_bound = 1.5
15081438

15091439
sparse = SparseDataFrame(data)

pandas/tests/sparse/test_series.py

+24-94
Original file line numberDiff line numberDiff line change
@@ -1384,97 +1384,21 @@ def test_numpy_func_call(self):
13841384
for series in ('bseries', 'zbseries'):
13851385
getattr(np, func)(getattr(self, series))
13861386

1387-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1388-
'(GH 17386)')
1389-
def test_where_with_int_data(self):
1390-
# GH 17386
1391-
data = [1, 1, 2, 2, 3, 3, 4, 4, 0, 0]
1392-
lower_bound = 2.5
1393-
1394-
sparse = SparseSeries(data)
1395-
result = sparse.where(sparse > lower_bound)
1396-
1397-
dense = Series(data)
1398-
dense_expected = dense.where(dense > lower_bound)
1399-
sparse_expected = SparseSeries(dense_expected)
1400-
1401-
tm.assert_series_equal(result, dense_expected)
1402-
tm.assert_sp_series_equal(result, sparse_expected)
1403-
1404-
@pytest.mark.parametrize('other', [
1405-
True,
1406-
-100,
1407-
0.1,
1408-
100.0 + 100.0j
1409-
])
1410-
@pytest.mark.skip(reason='Wrong SparseBlock initialization '
1411-
'(Segfault) '
1412-
'(GH 17386)')
1413-
def test_where_with_int_data_and_other(self, other):
1414-
# GH 17386
1415-
data = [1, 1, 2, 2, 3, 3, 4, 4, 0, 0]
1416-
lower_bound = 2.5
1417-
1418-
sparse = SparseSeries(data)
1419-
result = sparse.where(sparse > lower_bound, other)
1420-
1421-
dense = Series(data)
1422-
dense_expected = dense.where(dense > lower_bound, other)
1423-
sparse_expected = SparseSeries(dense_expected, fill_value=other)
1424-
1425-
tm.assert_series_equal(result, dense_expected)
1426-
tm.assert_sp_series_equal(result, sparse_expected)
1427-
1428-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1429-
'(GH 17386)')
1430-
def test_where_with_float_data(self):
1431-
# GH 17386
1432-
data = [1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, nan, nan]
1433-
lower_bound = 2.5
1434-
1435-
sparse = SparseSeries(data)
1436-
result = sparse.where(sparse > lower_bound)
1437-
1438-
dense = Series(data)
1439-
dense_expected = dense.where(dense > lower_bound)
1440-
sparse_expected = SparseSeries(dense_expected)
1441-
1442-
tm.assert_series_equal(result, dense_expected)
1443-
tm.assert_sp_series_equal(result, sparse_expected)
1444-
1445-
@pytest.mark.parametrize('other', [
1446-
True,
1447-
0,
1448-
0.1,
1449-
100.0 + 100.0j
1387+
@pytest.mark.parametrize('data', [
1388+
[1, 1, 2, 2, 3, 3, 4, 4, 0, 0],
1389+
[1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, nan, nan],
1390+
[
1391+
1.0, 1.0 + 1.0j,
1392+
2.0 + 2.0j, 2.0,
1393+
3.0, 3.0 + 3.0j,
1394+
4.0 + 4.0j, 4.0,
1395+
nan, nan
1396+
]
14501397
])
1451-
@pytest.mark.skip(reason='Wrong SparseBlock initialization '
1452-
'(Segfault) '
1453-
'(GH 17386)')
1454-
def test_where_with_float_data_and_other(self, other):
1455-
# GH 17386
1456-
data = [1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, nan, nan]
1457-
lower_bound = 2.5
1458-
1459-
sparse = SparseSeries(data)
1460-
result = sparse.where(sparse > lower_bound, other)
1461-
1462-
dense = Series(data)
1463-
dense_expected = dense.where(dense > lower_bound, other)
1464-
sparse_expected = SparseSeries(dense_expected, fill_value=other)
1465-
1466-
tm.assert_series_equal(result, dense_expected)
1467-
tm.assert_sp_series_equal(result, sparse_expected)
1468-
14691398
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
14701399
'(GH 17386)')
1471-
def test_where_with_complex_data(self):
1400+
def test_where_with_numeric_data(self, data):
14721401
# GH 17386
1473-
data = [1.0, 1.0 + 1.0j,
1474-
2.0 + 2.0j, 2.0,
1475-
3.0, 3.0 + 3.0j,
1476-
4.0 + 4.0j, 4.0,
1477-
nan, nan]
14781402
lower_bound = 1.5
14791403

14801404
sparse = SparseSeries(data)
@@ -1487,22 +1411,28 @@ def test_where_with_complex_data(self):
14871411
tm.assert_series_equal(result, dense_expected)
14881412
tm.assert_sp_series_equal(result, sparse_expected)
14891413

1414+
@pytest.mark.parametrize('data', [
1415+
[1, 1, 2, 2, 3, 3, 4, 4, 0, 0],
1416+
[1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, nan, nan],
1417+
[
1418+
1.0, 1.0 + 1.0j,
1419+
2.0 + 2.0j, 2.0,
1420+
3.0, 3.0 + 3.0j,
1421+
4.0 + 4.0j, 4.0,
1422+
nan, nan
1423+
]
1424+
])
14901425
@pytest.mark.parametrize('other', [
14911426
True,
1492-
0,
1427+
-100,
14931428
0.1,
14941429
100.0 + 100.0j
14951430
])
14961431
@pytest.mark.skip(reason='Wrong SparseBlock initialization '
14971432
'(Segfault) '
14981433
'(GH 17386)')
1499-
def test_where_with_complex_data_and_other(self, other):
1434+
def test_where_with_numeric_data_and_other(self, data, other):
15001435
# GH 17386
1501-
data = [1.0, 1.0 + 1.0j,
1502-
2.0 + 2.0j, 2.0,
1503-
3.0, 3.0 + 3.0j,
1504-
4.0 + 4.0j, 4.0,
1505-
nan, nan]
15061436
lower_bound = 1.5
15071437

15081438
sparse = SparseSeries(data)

0 commit comments

Comments
 (0)