File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -1465,9 +1465,10 @@ def ensure_copy(self):
14651465 """
14661466
14671467 def is_view (x ):
1468- # Sparse matrices don't have views like numpy arrays. Since indexing on
1469- # them creates copies in constructor we can skip this check here.
1470- return not sp .issparse (x ) and x .base is not None
1468+ if not sp .issparse (x ):
1469+ return x .base is not None
1470+ else :
1471+ return x .data .base is not None
14711472
14721473 if is_view (self ._X ):
14731474 self ._X = self ._X .copy ()
Original file line number Diff line number Diff line change @@ -495,9 +495,13 @@ def test_copy_sparse(self):
495495 self .assertNotEqual (id (t .metas ), id (copy .metas ))
496496
497497 # ensure that copied sparse arrays do not share data
498+ # and that both are unlockable
498499 with t .unlocked ():
499500 t .X [0 , 0 ] = 42
500501 self .assertEqual (copy .X [0 , 0 ], 5.1 )
502+ with copy .unlocked ():
503+ copy .X [0 , 0 ] = 43
504+ self .assertEqual (t .X [0 , 0 ], 42 )
501505
502506 def test_concatenate (self ):
503507 d1 = data .Domain (
You can’t perform that action at this time.
0 commit comments