Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Table.add_column - Do not try to insert data in locked empty array #6743

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

PrimozGodec
Copy link
Contributor

Issue

When a table has no rows add_column still tries to insert (empty) data to the table's array. In case the table's array is empty Orange doesn't unlock it and so inserting fails.

Description of changes

Skip inserting empty data when the array is empty

Includes
  • Code changes
  • Tests
  • Documentation

@janezd janezd self-assigned this Feb 23, 2024
@PrimozGodec
Copy link
Contributor Author

PrimozGodec commented Feb 23, 2024

Here is the PR that introduced skipping locking for empty tables #5714

This avoids numpy's deprecation of making arrays with .base == None that
do not own their data writable. This strange combination appears when
unplickling arrays of size 0.

@janezd
Copy link
Contributor

janezd commented Feb 23, 2024

But it seems that @markotoplak also fixed unlocking for size == 0. Your tests pass even without your change in add_column. I'd keep the tests, but remove the change in add_column - unless there's another scenario that requires it.

@PrimozGodec
Copy link
Contributor Author

But it seems that @markotoplak also fixed unlocking for size == 0.

If I understand correctly, @markotoplak's fix just skips unlocking the table in this case (here: https://github.com/markotoplak/orange3/blob/cd5d384da7a34a2f0f57de0eccee2a2ca83d4de6/Orange/data/table.py#L508-L510).

That is the part of the comment from his PR:

For now, numpy allows unlocking (setting writable = True) for these arrays but shows a deprecation warning. To avoid the warning, the last commit disables unlocking of size=0 tables.

Your tests pass even without your change in add_column. I'd keep the tests but remove the change in add_column - unless there's another scenario that requires it.

On my computer (when setting Table.LOCKING=True), the test fails without a change in the add_column. The underlying array is locked, and I get ValueError: assignment destination is read-only. Did you make sure that Table.LOCKING = True for you? We either need to do this check in add_column or change unlocking, but then we reintroduce the problem that @markotoplak fixed.

@janezd
Copy link
Contributor

janezd commented Feb 23, 2024

You're right, I forgot to enable Table.LOCKIING. I forgot we do it only for tests.

add_column calls set_column and the exception is raised there. Wouldn't this problem also occur when one calls set_column? Perhaps we should rather change set_column, like this

        # 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)

or assert len(data) == 0.

Even if we change add_column, I think we should assert that the length of the data is correct, otherwise assigning a non-empty column to an empty table will fail silently.

@PrimozGodec
Copy link
Contributor Author

I agree it can be moved there, and checking the size is also a good idea.

Initially, I put it inadd_column since unlocking happened there, but it is better to have this check in set_column.

@janezd
Copy link
Contributor

janezd commented Feb 23, 2024

... because unlocking is not a problem, so let us not skip it. Unlocking does not raise an error (it just fails to do anything); setting the data does.

@janezd janezd merged commit 6c99b83 into biolab:master Mar 1, 2024
19 of 25 checks passed
@PrimozGodec PrimozGodec deleted the fix-add-column branch March 13, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants