Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,10 @@ def ensure_copy(self):
"""

def is_view(x):
# Sparse matrices don't have views like numpy arrays. Since indexing on
# them creates copies in constructor we can skip this check here.
return not sp.issparse(x) and x.base is not None
if not sp.issparse(x):
return x.base is not None
else:
return x.data.base is not None

if is_view(self._X):
self._X = self._X.copy()
Expand Down
4 changes: 4 additions & 0 deletions Orange/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,13 @@ def test_copy_sparse(self):
self.assertNotEqual(id(t.metas), id(copy.metas))

# ensure that copied sparse arrays do not share data
# and that both are unlockable
with t.unlocked():
t.X[0, 0] = 42
self.assertEqual(copy.X[0, 0], 5.1)
with copy.unlocked():
copy.X[0, 0] = 43
self.assertEqual(t.X[0, 0], 42)

def test_concatenate(self):
d1 = data.Domain(
Expand Down