Skip to content

Commit 293bb47

Browse files
committed
fixup! ENH: SparseDataFrame supports scipy.sparse.spmatrix in setitem
1 parent 97da8bd commit 293bb47

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/core/sparse/frame.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,12 @@ def __getitem__(self, key):
436436
def __setitem__(self, key, value):
437437
if is_scipy_sparse(value):
438438
if any(ax == 1 for ax in value.shape): # 1d spmatrix
439-
value = SparseArray(value, fill_value=self._default_fill_value)
439+
value = SparseArray(value, fill_value=self._default_fill_value,
440+
kind=self._default_kind)
440441
else:
441442
# 2d; make it iterable
442443
value = list(value.tocsc().T)
443-
super().__setitem__(key, value)
444+
super(SparseDataFrame, self).__setitem__(key, value)
444445

445446
@Appender(DataFrame.get_value.__doc__, indents=0)
446447
def get_value(self, index, col, takeable=False):

pandas/tests/sparse/test_frame.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,9 @@ def test_setitem_spmatrix(self):
557557
assert (sdf[['X']].to_coo() != spm.tocoo()).nnz == 0
558558

559559
# 1d row -- changing series contents not yet supported
560-
spm = csr_matrix(np.arange(sdf.shape[1])).astype(float)
561-
idx = np.r_[[False, True], np.full(sdf.shape[0] - 2, False)]
560+
spm = csr_matrix(np.arange(sdf.shape[1], dtype=float))
561+
idx = np.zeros(sdf.shape[0], dtype=bool)
562+
idx[1] = True
562563
tm.assert_raises_regex(TypeError, 'assignment',
563564
lambda: sdf.__setitem__(idx, spm))
564565

0 commit comments

Comments
 (0)