Skip to content

Commit 31d1867

Browse files
committed
TST: Parametrized other parameter on sparse where tests
1 parent b5e3b50 commit 31d1867

File tree

2 files changed

+56
-414
lines changed

2 files changed

+56
-414
lines changed

pandas/tests/sparse/test_frame.py

+28-210
Original file line numberDiff line numberDiff line change
@@ -1403,69 +1403,17 @@ def test_where_with_int_data(self):
14031403
tm.assert_frame_equal(result, dense_expected)
14041404
tm.assert_sp_frame_equal(result, sparse_expected)
14051405

1406+
@pytest.mark.parametrize('other', [
1407+
True,
1408+
-100,
1409+
0.1,
1410+
100.0 + 100.0j
1411+
])
14061412
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
14071413
'(GH 17386)')
1408-
def test_where_with_int_data_and_int_other(self):
1414+
def test_where_with_int_data_and_other(self, other):
14091415
# GH 17386
14101416
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1411-
other = -100
1412-
lower_bound = 2.5
1413-
1414-
sparse = SparseDataFrame(data)
1415-
result = sparse.where(sparse > lower_bound, other)
1416-
1417-
dense = DataFrame(data)
1418-
dense_expected = dense.where(dense > lower_bound, other)
1419-
sparse_expected = SparseDataFrame(dense_expected,
1420-
default_fill_value=other)
1421-
1422-
tm.assert_frame_equal(result, dense_expected)
1423-
tm.assert_sp_frame_equal(result, sparse_expected)
1424-
1425-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1426-
'(GH 17386)')
1427-
def test_where_with_int_data_and_float_other(self):
1428-
# GH 17386
1429-
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1430-
other = 0.1
1431-
lower_bound = 2.5
1432-
1433-
sparse = SparseDataFrame(data)
1434-
result = sparse.where(sparse > lower_bound, other)
1435-
1436-
dense = DataFrame(data)
1437-
dense_expected = dense.where(dense > lower_bound, other)
1438-
sparse_expected = SparseDataFrame(dense_expected,
1439-
default_fill_value=other)
1440-
1441-
tm.assert_frame_equal(result, dense_expected)
1442-
tm.assert_sp_frame_equal(result, sparse_expected)
1443-
1444-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1445-
'(GH 17386)')
1446-
def test_where_with_int_data_and_complex_other(self):
1447-
# GH 17386
1448-
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1449-
other = 100.0 + 100.0j
1450-
lower_bound = 2.5
1451-
1452-
sparse = SparseDataFrame(data)
1453-
result = sparse.where(sparse > lower_bound, other)
1454-
1455-
dense = DataFrame(data)
1456-
dense_expected = dense.where(dense > lower_bound, other)
1457-
sparse_expected = SparseDataFrame(dense_expected,
1458-
default_fill_value=other)
1459-
1460-
tm.assert_frame_equal(result, dense_expected)
1461-
tm.assert_sp_frame_equal(result, sparse_expected)
1462-
1463-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1464-
'(GH 17386)')
1465-
def test_where_with_int_data_and_bool_other(self):
1466-
# GH 17386
1467-
data = [[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]]
1468-
other = True
14691417
lower_bound = 2.5
14701418

14711419
sparse = SparseDataFrame(data)
@@ -1496,69 +1444,17 @@ def test_where_with_float_data(self):
14961444
tm.assert_frame_equal(result, dense_expected)
14971445
tm.assert_sp_frame_equal(result, sparse_expected)
14981446

1447+
@pytest.mark.parametrize('other', [
1448+
True,
1449+
0,
1450+
0.1,
1451+
100.0 + 100.0j
1452+
])
14991453
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
15001454
'(GH 17386)')
1501-
def test_where_with_float_data_and_int_other(self):
1502-
# GH 17386
1503-
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1504-
other = 0
1505-
lower_bound = 2.5
1506-
1507-
sparse = SparseDataFrame(data)
1508-
result = sparse.where(sparse > lower_bound, other)
1509-
1510-
dense = DataFrame(data)
1511-
dense_expected = dense.where(dense > lower_bound, other)
1512-
sparse_expected = SparseDataFrame(dense_expected,
1513-
default_fill_value=other)
1514-
1515-
tm.assert_frame_equal(result, dense_expected)
1516-
tm.assert_sp_frame_equal(result, sparse_expected)
1517-
1518-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1519-
'(GH 17386)')
1520-
def test_where_with_float_data_and_float_other(self):
1521-
# GH 17386
1522-
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1523-
other = 0.1
1524-
lower_bound = 2.5
1525-
1526-
sparse = SparseDataFrame(data)
1527-
result = sparse.where(sparse > lower_bound, other)
1528-
1529-
dense = DataFrame(data)
1530-
dense_expected = dense.where(dense > lower_bound, other)
1531-
sparse_expected = SparseDataFrame(dense_expected,
1532-
default_fill_value=other)
1533-
1534-
tm.assert_frame_equal(result, dense_expected)
1535-
tm.assert_sp_frame_equal(result, sparse_expected)
1536-
1537-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1538-
'(GH 17386)')
1539-
def test_where_with_float_data_and_complex_other(self):
1540-
# GH 17386
1541-
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1542-
other = 100.0 - 100j
1543-
lower_bound = 2.5
1544-
1545-
sparse = SparseDataFrame(data)
1546-
result = sparse.where(sparse > lower_bound, other)
1547-
1548-
dense = DataFrame(data)
1549-
dense_expected = dense.where(dense > lower_bound, other)
1550-
sparse_expected = SparseDataFrame(dense_expected,
1551-
default_fill_value=other)
1552-
1553-
tm.assert_frame_equal(result, dense_expected)
1554-
tm.assert_sp_frame_equal(result, sparse_expected)
1555-
1556-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1557-
'(GH 17386)')
1558-
def test_where_with_float_data_and_bool_other(self):
1455+
def test_where_with_float_data_and_other(self, other):
15591456
# GH 17386
15601457
data = [[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]]
1561-
other = True
15621458
lower_bound = 2.5
15631459

15641460
sparse = SparseDataFrame(data)
@@ -1593,39 +1489,21 @@ def test_where_with_complex_data(self):
15931489
tm.assert_frame_equal(result, dense_expected)
15941490
tm.assert_sp_frame_equal(result, sparse_expected)
15951491

1492+
@pytest.mark.parametrize('other', [
1493+
True,
1494+
0,
1495+
0.1,
1496+
100.0 + 100.0j
1497+
])
15961498
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
15971499
'(GH 17386)')
1598-
def test_where_with_complex_data_and_int_other(self):
1599-
# GH 17386
1600-
data = [[1.0, 1.0 + 1.0j],
1601-
[2.0 + 2.0j, 2.0],
1602-
[3.0, 3.0 + 3.0j],
1603-
[4.0 + 4.0j, 4.0],
1604-
[nan, nan]]
1605-
other = 0
1606-
lower_bound = 1.5
1607-
1608-
sparse = SparseDataFrame(data)
1609-
result = sparse.where(sparse > lower_bound, other)
1610-
1611-
dense = DataFrame(data)
1612-
dense_expected = dense.where(dense > lower_bound, other)
1613-
sparse_expected = SparseDataFrame(dense_expected,
1614-
default_fill_value=other)
1615-
1616-
tm.assert_frame_equal(result, dense_expected)
1617-
tm.assert_sp_frame_equal(result, sparse_expected)
1618-
1619-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1620-
'(GH 17386)')
1621-
def test_where_with_complex_data_and_float_other(self):
1500+
def test_where_with_complex_data_and_other(self, other):
16221501
# GH 17386
16231502
data = [[1.0, 1.0 + 1.0j],
16241503
[2.0 + 2.0j, 2.0],
16251504
[3.0, 3.0 + 3.0j],
16261505
[4.0 + 4.0j, 4.0],
16271506
[nan, nan]]
1628-
other = 0.1
16291507
lower_bound = 1.5
16301508

16311509
sparse = SparseDataFrame(data)
@@ -1639,52 +1517,6 @@ def test_where_with_complex_data_and_float_other(self):
16391517
tm.assert_frame_equal(result, dense_expected)
16401518
tm.assert_sp_frame_equal(result, sparse_expected)
16411519

1642-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1643-
'(GH 17386)')
1644-
def test_where_with_complex_data_and_complex_other(self):
1645-
# GH 17386
1646-
data = [[1.0, 1.0 + 1.0j],
1647-
[2.0 + 2.0j, 2.0],
1648-
[3.0, 3.0 + 3.0j],
1649-
[4.0 + 4.0j, 4.0],
1650-
[nan, nan]]
1651-
other = 100.0 - 100.0j
1652-
lower_bound = 1.5
1653-
1654-
sparse = SparseDataFrame(data)
1655-
result = sparse.where(sparse > lower_bound, other)
1656-
1657-
dense = DataFrame(data)
1658-
dense_expected = dense.where(dense > lower_bound, other)
1659-
sparse_expected = SparseDataFrame(dense_expected,
1660-
default_fill_value=other)
1661-
1662-
tm.assert_frame_equal(result, dense_expected)
1663-
tm.assert_sp_frame_equal(result, sparse_expected)
1664-
1665-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1666-
'(GH 17386)')
1667-
def test_where_with_complex_data_and_bool_other(self):
1668-
# GH 17386
1669-
data = [[1.0, 1.0 + 1.0j],
1670-
[2.0 + 2.0j, 2.0],
1671-
[3.0, 3.0 + 3.0j],
1672-
[4.0 + 4.0j, 4.0],
1673-
[nan, nan]]
1674-
other = True
1675-
lower_bound = 2.5
1676-
1677-
sparse = SparseDataFrame(data)
1678-
result = sparse.where(sparse > lower_bound, other)
1679-
1680-
dense = DataFrame(data)
1681-
dense_expected = dense.where(dense > lower_bound, other)
1682-
sparse_expected = SparseDataFrame(dense_expected,
1683-
default_fill_value=other)
1684-
1685-
tm.assert_frame_equal(result, dense_expected)
1686-
tm.assert_sp_frame_equal(result, sparse_expected)
1687-
16881520
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
16891521
'(GH 17386)')
16901522
def test_where_with_bool_data(self):
@@ -1702,31 +1534,17 @@ def test_where_with_bool_data(self):
17021534
tm.assert_frame_equal(result, dense_expected)
17031535
tm.assert_sp_frame_equal(result, sparse_expected)
17041536

1537+
@pytest.mark.parametrize('other', [
1538+
True,
1539+
0,
1540+
0.1,
1541+
100.0 + 100.0j
1542+
])
17051543
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
17061544
'(GH 17386)')
1707-
def test_where_with_bool_data_and_bool_other(self):
1708-
# GH 17386
1709-
data = [[False, False], [True, True], [False, False]]
1710-
other = True
1711-
cond = True
1712-
1713-
sparse = SparseDataFrame(data)
1714-
result = sparse.where(sparse == cond, other)
1715-
1716-
dense = DataFrame(data)
1717-
dense_expected = dense.where(dense == cond, other)
1718-
sparse_expected = SparseDataFrame(dense_expected,
1719-
default_fill_value=other)
1720-
1721-
tm.assert_frame_equal(result, dense_expected)
1722-
tm.assert_sp_frame_equal(result, sparse_expected)
1723-
1724-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1725-
'(GH 17386)')
1726-
def test_where_with_bool_data_and_complex_other(self):
1545+
def test_where_with_bool_data_and_other(self, other):
17271546
# GH 17386
17281547
data = [[False, False], [True, True], [False, False]]
1729-
other = 100.0 + 100.0j
17301548
cond = True
17311549

17321550
sparse = SparseDataFrame(data)

0 commit comments

Comments
 (0)