Skip to content

Commit d522fc4

Browse files
committed
test for from_spmatrix using csr matrix with explicit 0
Test based on issue pandas-dev#28992, very similar to a previous test but with exact methods called to ensure specific issue has been addressed
1 parent 901b1c7 commit d522fc4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/arrays/sparse/test_array.py

+12
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ def test_from_spmatrix_including_explicit_zero(self, format):
221221
expected = mat.toarray().ravel()
222222
tm.assert_numpy_array_equal(result, expected)
223223

224+
@td.skip_if_no_scipy
225+
def test_csr_to_spmatrix_with_explicit_zero(self):
226+
# similar to above, using exact methods in issue #28992
227+
import scipy.sparse
228+
randmat = scipy.sparse.random(5, 5, density=0.5)
229+
mat = scipy.sparse.csr_matrix(randmat)
230+
231+
mat.data[0] = 0
232+
dfmat = pd.DataFrame.sparse.from_spmatrix(mat)
233+
densemat = mat.todense()
234+
tm.assert_numpy_array_equal(np.array(dfmat), np.array(densemat))
235+
224236
@td.skip_if_no_scipy
225237
def test_from_spmatrix_raises(self):
226238
import scipy.sparse

0 commit comments

Comments
 (0)