Skip to content

Commit 77d87d2

Browse files
committed
Table: Fix ensure_copy for sparse matrices
`ensure_copy` is checking whether an array is a view through the `.base` argument which doesn't exist on `scipy.sparse` matrices. Since `scipy.sparse` don't work with views (e.g. indexing returns a copy of the matrix) the check should only be performed for dense matrices.
1 parent 4a484f6 commit 77d87d2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Orange/data/table.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,15 +912,16 @@ def is_copy(self):
912912

913913
def ensure_copy(self):
914914
"""
915-
Ensure that the table owns its data; copy arrays when necessary
915+
Ensure that the table owns its data; copy arrays when necessary.
916+
The check is skipped for sparse matrices since they don't have views like numpy arrays.
916917
"""
917-
if self.X.base is not None:
918+
if not sp.issparse(self.X) and self.X.base is not None:
918919
self.X = self.X.copy()
919-
if self._Y.base is not None:
920+
if not sp.issparse(self._Y) and self._Y.base is not None:
920921
self._Y = self._Y.copy()
921-
if self.metas.base is not None:
922+
if not sp.issparse(self.metas) and self.metas.base is not None:
922923
self.metas = self.metas.copy()
923-
if self.W.base is not None:
924+
if not sp.issparse(self.W) and self.W.base is not None:
924925
self.W = self.W.copy()
925926

926927
def copy(self):

0 commit comments

Comments
 (0)