Skip to content

Commit 20d5b34

Browse files
BUG: incorrect handling of scipy.sparse.dok formats (#16197)
1 parent 096e215 commit 20d5b34

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Diff for: pandas/core/sparse/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def _init_spmatrix(self, data, index, columns, dtype=None,
190190
values = Series(data.data, index=data.row, copy=False)
191191
for col, rowvals in values.groupby(data.col):
192192
# get_blocks expects int32 row indices in sorted order
193+
rowvals = rowvals.sort_index()
193194
rows = rowvals.index.values.astype(np.int32)
194-
rows.sort()
195195
blocs, blens = get_blocks(rows)
196196

197197
sdict[columns[col]] = SparseSeries(

Diff for: pandas/tests/sparse/test_frame.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,8 @@ def test_isnotnull(self):
11461146
tm.assert_frame_equal(res.to_dense(), exp)
11471147

11481148

1149-
@pytest.mark.parametrize('index', [None, list('ab')]) # noqa: F811
1150-
@pytest.mark.parametrize('columns', [None, list('cd')])
1149+
@pytest.mark.parametrize('index', [None, list('abc')]) # noqa: F811
1150+
@pytest.mark.parametrize('columns', [None, list('def')])
11511151
@pytest.mark.parametrize('fill_value', [None, 0, np.nan])
11521152
@pytest.mark.parametrize('dtype', [bool, int, float, np.uint16])
11531153
def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
@@ -1156,7 +1156,8 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype):
11561156

11571157
# Make one ndarray and from it one sparse matrix, both to be used for
11581158
# constructing frames and comparing results
1159-
arr = np.eye(2, dtype=dtype)
1159+
arr = np.eye(3, dtype=dtype)
1160+
arr[0, 1] = dtype(2)
11601161
try:
11611162
spm = spmatrix(arr)
11621163
assert spm.dtype == arr.dtype

0 commit comments

Comments
 (0)