Skip to content

Commit

Permalink
Table.from_table_rows: Ensure arrays are not views
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Apr 16, 2021
1 parent c6d92ea commit 4849ad9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,23 @@ def from_table_rows(cls, source, row_indices):
:return: a new table
:rtype: Orange.data.Table
"""
def get_rows(a):
a = a[row_indices]
if isinstance(row_indices, slice) or row_indices is ...:
a = a.copy()
return a

self = cls()
self.domain = source.domain
with self.unlocked():
self.X = source.X[row_indices]
self.X = get_rows(source.X)
if self.X.ndim == 1:
self.X = self.X.reshape(-1, len(self.domain.attributes))
self.Y = source._Y[row_indices]
self.metas = source.metas[row_indices]
self.Y = get_rows(source._Y)
self.metas = get_rows(source.metas)
if self.metas.ndim == 1:
self.metas = self.metas.reshape(-1, len(self.domain.metas))
self.W = source.W[row_indices]
self.W = get_rows(source.W)
self.name = getattr(source, 'name', '')
self.ids = np.array(source.ids[row_indices])
self.attributes = getattr(source, 'attributes', {})
Expand Down

0 comments on commit 4849ad9

Please sign in to comment.