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: 6 additions & 1 deletion Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,12 @@ def set_column(self, index: Union[int, str, Variable], data):
raise ValueError(f"cannot set data for variable {index.name} "
"with different encoding")
index = self.domain.index(index)
self._get_column_view(index)[:] = data
# Zero-sized arrays cannot be made writeable, yet the below
# assignment would fail despite doing nothing.
if len(self) > 0:
self._get_column_view(index)[:] = data
else:
assert len(self) == len(data)

def _filter_is_defined(self, columns=None, negate=False):
# structure of function is obvious; pylint: disable=too-many-branches
Expand Down
16 changes: 16 additions & 0 deletions Orange/data/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ def test_with_column(self):
tabw.metas,
np.hstack((tab.metas, np.array(list("abcde")).reshape(5, -1))))

def test_add_column_empty(self):
a, b = ContinuousVariable("a"), ContinuousVariable("b")
table = Table.from_list(Domain([a]), [])

new_table = table.add_column(b, [], to_metas=True)
self.assertTupleEqual(new_table.domain.attributes, (a,))
self.assertTupleEqual(new_table.domain.metas, (b,))
self.assertTupleEqual((0, 1), new_table.X.shape)
self.assertTupleEqual((0, 1), new_table.metas.shape)

new_table = table.add_column(ContinuousVariable("b"), [], to_metas=False)
self.assertTupleEqual(new_table.domain.attributes, (a, b))
self.assertTupleEqual(new_table.domain.metas, ())
self.assertTupleEqual((0, 2), new_table.X.shape)
self.assertTupleEqual((0, 0), new_table.metas.shape)

def test_copy(self):
domain = Domain([ContinuousVariable("x")],
ContinuousVariable("y"),
Expand Down