Skip to content

Commit

Permalink
Table: Fix ensure_copy for sparse matrices
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
nikicc committed Jul 14, 2016
1 parent 4a484f6 commit 77d87d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,15 +912,16 @@ def is_copy(self):

def ensure_copy(self):
"""
Ensure that the table owns its data; copy arrays when necessary
Ensure that the table owns its data; copy arrays when necessary.
The check is skipped for sparse matrices since they don't have views like numpy arrays.
"""
if self.X.base is not None:
if not sp.issparse(self.X) and self.X.base is not None:
self.X = self.X.copy()
if self._Y.base is not None:
if not sp.issparse(self._Y) and self._Y.base is not None:
self._Y = self._Y.copy()
if self.metas.base is not None:
if not sp.issparse(self.metas) and self.metas.base is not None:
self.metas = self.metas.copy()
if self.W.base is not None:
if not sp.issparse(self.W) and self.W.base is not None:
self.W = self.W.copy()

def copy(self):
Expand Down

0 comments on commit 77d87d2

Please sign in to comment.