Skip to content

Commit 9b4cf5e

Browse files
committed
split out some indexing / analytics tests
1 parent 6d53863 commit 9b4cf5e

File tree

3 files changed

+153
-102
lines changed

3 files changed

+153
-102
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
import numpy as np
3+
from pandas import SparseDataFrame, DataFrame, SparseSeries
4+
from pandas.util import testing as tm
5+
6+
7+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
8+
'(GH 17386)')
9+
def test_quantile():
10+
# GH 17386
11+
data = [[1, 1], [2, 10], [3, 100], [np.nan, np.nan]]
12+
q = 0.1
13+
14+
sparse_df = SparseDataFrame(data)
15+
result = sparse_df.quantile(q)
16+
17+
dense_df = DataFrame(data)
18+
dense_expected = dense_df.quantile(q)
19+
sparse_expected = SparseSeries(dense_expected)
20+
21+
tm.assert_series_equal(result, dense_expected)
22+
tm.assert_sp_series_equal(result, sparse_expected)
23+
24+
25+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
26+
'(GH 17386)')
27+
def test_quantile_multi():
28+
# GH 17386
29+
data = [[1, 1], [2, 10], [3, 100], [np.nan, np.nan]]
30+
q = [0.1, 0.5]
31+
32+
sparse_df = SparseDataFrame(data)
33+
result = sparse_df.quantile(q)
34+
35+
dense_df = DataFrame(data)
36+
dense_expected = dense_df.quantile(q)
37+
sparse_expected = SparseDataFrame(dense_expected)
38+
39+
tm.assert_frame_equal(result, dense_expected)
40+
tm.assert_sp_frame_equal(result, sparse_expected)

pandas/tests/sparse/frame/test_frame.py

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,108 +1402,6 @@ def test_numpy_func_call(self):
14021402
for func in funcs:
14031403
getattr(np, func)(self.frame)
14041404

1405-
@pytest.mark.parametrize('data', [
1406-
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
1407-
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]],
1408-
[
1409-
[1.0, 1.0 + 1.0j],
1410-
[2.0 + 2.0j, 2.0],
1411-
[3.0, 3.0 + 3.0j],
1412-
[4.0 + 4.0j, 4.0],
1413-
[nan, nan]
1414-
]
1415-
])
1416-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1417-
'(GH 17386)')
1418-
def test_where_with_numeric_data(self, data):
1419-
# GH 17386
1420-
lower_bound = 1.5
1421-
1422-
sparse = SparseDataFrame(data)
1423-
result = sparse.where(sparse > lower_bound)
1424-
1425-
dense = DataFrame(data)
1426-
dense_expected = dense.where(dense > lower_bound)
1427-
sparse_expected = SparseDataFrame(dense_expected)
1428-
1429-
tm.assert_frame_equal(result, dense_expected)
1430-
tm.assert_sp_frame_equal(result, sparse_expected)
1431-
1432-
@pytest.mark.parametrize('data', [
1433-
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
1434-
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [nan, nan]],
1435-
[
1436-
[1.0, 1.0 + 1.0j],
1437-
[2.0 + 2.0j, 2.0],
1438-
[3.0, 3.0 + 3.0j],
1439-
[4.0 + 4.0j, 4.0],
1440-
[nan, nan]
1441-
]
1442-
])
1443-
@pytest.mark.parametrize('other', [
1444-
True,
1445-
-100,
1446-
0.1,
1447-
100.0 + 100.0j
1448-
])
1449-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1450-
'(GH 17386)')
1451-
def test_where_with_numeric_data_and_other(self, data, other):
1452-
# GH 17386
1453-
lower_bound = 1.5
1454-
1455-
sparse = SparseDataFrame(data)
1456-
result = sparse.where(sparse > lower_bound, other)
1457-
1458-
dense = DataFrame(data)
1459-
dense_expected = dense.where(dense > lower_bound, other)
1460-
sparse_expected = SparseDataFrame(dense_expected,
1461-
default_fill_value=other)
1462-
1463-
tm.assert_frame_equal(result, dense_expected)
1464-
tm.assert_sp_frame_equal(result, sparse_expected)
1465-
1466-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1467-
'(GH 17386)')
1468-
def test_where_with_bool_data(self):
1469-
# GH 17386
1470-
data = [[False, False], [True, True], [False, False]]
1471-
cond = True
1472-
1473-
sparse = SparseDataFrame(data)
1474-
result = sparse.where(sparse == cond)
1475-
1476-
dense = DataFrame(data)
1477-
dense_expected = dense.where(dense == cond)
1478-
sparse_expected = SparseDataFrame(dense_expected)
1479-
1480-
tm.assert_frame_equal(result, dense_expected)
1481-
tm.assert_sp_frame_equal(result, sparse_expected)
1482-
1483-
@pytest.mark.parametrize('other', [
1484-
True,
1485-
0,
1486-
0.1,
1487-
100.0 + 100.0j
1488-
])
1489-
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
1490-
'(GH 17386)')
1491-
def test_where_with_bool_data_and_other(self, other):
1492-
# GH 17386
1493-
data = [[False, False], [True, True], [False, False]]
1494-
cond = True
1495-
1496-
sparse = SparseDataFrame(data)
1497-
result = sparse.where(sparse == cond, other)
1498-
1499-
dense = DataFrame(data)
1500-
dense_expected = dense.where(dense == cond, other)
1501-
sparse_expected = SparseDataFrame(dense_expected,
1502-
default_fill_value=other)
1503-
1504-
tm.assert_frame_equal(result, dense_expected)
1505-
tm.assert_sp_frame_equal(result, sparse_expected)
1506-
15071405
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
15081406
'(GH 17386)')
15091407
def test_quantile(self):
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import pytest
2+
import numpy as np
3+
from pandas import SparseDataFrame, DataFrame
4+
from pandas.util import testing as tm
5+
6+
7+
pytestmark = pytest.mark.skip("Wrong SparseBlock initialization (GH 17386)")
8+
9+
10+
@pytest.mark.parametrize('data', [
11+
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
12+
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [np.nan, np.nan]],
13+
[
14+
[1.0, 1.0 + 1.0j],
15+
[2.0 + 2.0j, 2.0],
16+
[3.0, 3.0 + 3.0j],
17+
[4.0 + 4.0j, 4.0],
18+
[np.nan, np.nan]
19+
]
20+
])
21+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
22+
'(GH 17386)')
23+
def test_where_with_numeric_data(data):
24+
# GH 17386
25+
lower_bound = 1.5
26+
27+
sparse = SparseDataFrame(data)
28+
result = sparse.where(sparse > lower_bound)
29+
30+
dense = DataFrame(data)
31+
dense_expected = dense.where(dense > lower_bound)
32+
sparse_expected = SparseDataFrame(dense_expected)
33+
34+
tm.assert_frame_equal(result, dense_expected)
35+
tm.assert_sp_frame_equal(result, sparse_expected)
36+
37+
38+
@pytest.mark.parametrize('data', [
39+
[[1, 1], [2, 2], [3, 3], [4, 4], [0, 0]],
40+
[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0], [np.nan, np.nan]],
41+
[
42+
[1.0, 1.0 + 1.0j],
43+
[2.0 + 2.0j, 2.0],
44+
[3.0, 3.0 + 3.0j],
45+
[4.0 + 4.0j, 4.0],
46+
[np.nan, np.nan]
47+
]
48+
])
49+
@pytest.mark.parametrize('other', [
50+
True,
51+
-100,
52+
0.1,
53+
100.0 + 100.0j
54+
])
55+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
56+
'(GH 17386)')
57+
def test_where_with_numeric_data_and_other(data, other):
58+
# GH 17386
59+
lower_bound = 1.5
60+
61+
sparse = SparseDataFrame(data)
62+
result = sparse.where(sparse > lower_bound, other)
63+
64+
dense = DataFrame(data)
65+
dense_expected = dense.where(dense > lower_bound, other)
66+
sparse_expected = SparseDataFrame(dense_expected,
67+
default_fill_value=other)
68+
69+
tm.assert_frame_equal(result, dense_expected)
70+
tm.assert_sp_frame_equal(result, sparse_expected)
71+
72+
73+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
74+
'(GH 17386)')
75+
def test_where_with_bool_data():
76+
# GH 17386
77+
data = [[False, False], [True, True], [False, False]]
78+
cond = True
79+
80+
sparse = SparseDataFrame(data)
81+
result = sparse.where(sparse == cond)
82+
83+
dense = DataFrame(data)
84+
dense_expected = dense.where(dense == cond)
85+
sparse_expected = SparseDataFrame(dense_expected)
86+
87+
tm.assert_frame_equal(result, dense_expected)
88+
tm.assert_sp_frame_equal(result, sparse_expected)
89+
90+
91+
@pytest.mark.parametrize('other', [
92+
True,
93+
0,
94+
0.1,
95+
100.0 + 100.0j
96+
])
97+
@pytest.mark.xfail(reason='Wrong SparseBlock initialization '
98+
'(GH 17386)')
99+
def test_where_with_bool_data_and_other(other):
100+
# GH 17386
101+
data = [[False, False], [True, True], [False, False]]
102+
cond = True
103+
104+
sparse = SparseDataFrame(data)
105+
result = sparse.where(sparse == cond, other)
106+
107+
dense = DataFrame(data)
108+
dense_expected = dense.where(dense == cond, other)
109+
sparse_expected = SparseDataFrame(dense_expected,
110+
default_fill_value=other)
111+
112+
tm.assert_frame_equal(result, dense_expected)
113+
tm.assert_sp_frame_equal(result, sparse_expected)

0 commit comments

Comments
 (0)