Skip to content

Commit

Permalink
Merge pull request #6357 from janezd/table-ensure-copy
Browse files Browse the repository at this point in the history
Table: Fix ensure_copy to also check ids
  • Loading branch information
markotoplak authored Mar 3, 2023
2 parents a2cfc31 + f373309 commit 878ea9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,8 @@ def is_view(x):
self._metas = self._metas.copy()
if is_view(self._W):
self._W = self._W.copy()
if is_view(self.ids):
self.ids = self.ids.copy()

def copy(self):
"""
Expand Down
19 changes: 19 additions & 0 deletions Orange/data/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ def test_with_column(self):
tabw.metas,
np.hstack((tab.metas, np.array(list("abcde")).reshape(5, -1))))

def test_copy(self):
domain = Domain([ContinuousVariable("x")],
ContinuousVariable("y"),
[ContinuousVariable("z")])
data1 = Table.from_list(domain, [[1, 2, 3]], weights=[4])
data1.ids[0]= 5
data2 = data1.copy()
with data2.unlocked():
data2.X += 1
data2.Y += 1
data2.metas += 1
data2.W += 1
data2.ids += 1
self.assertEqual(data1.X, [[1]])
self.assertEqual(data1.Y, [[2]])
self.assertEqual(data1.metas, [[3]])
self.assertEqual(data1.W, [[4]])
self.assertEqual(data1.ids, [[5]])


class TestTableLocking(unittest.TestCase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/visualize/owtreeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from AnyQt.QtGui import QColor, QBrush, QPen, QFontMetrics
from AnyQt.QtCore import Qt, QPointF, QSizeF, QRectF

from orangecanvas.utils.localization import pl
from orangewidget.utils.combobox import ComboBoxSearch

from Orange.base import TreeModel, SklModel
Expand All @@ -20,6 +19,7 @@
from Orange.widgets.visualize.owtreeviewer2d import \
GraphicsNode, GraphicsEdge, OWTreeViewer2D
from Orange.widgets.utils import to_html
from Orange.widgets.utils.localization import pl
from Orange.data import Table
from Orange.util import color_to_hex

Expand Down

0 comments on commit 878ea9b

Please sign in to comment.