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

HdfStorage.read: fix rowNumbers for all start/end values #430

Closed
wants to merge 1 commit into from

Conversation

sbesson
Copy link
Member

@sbesson sbesson commented Sep 19, 2024

Under some conditions, the rowNumbers array returned as part of the data was inconsistent with the range of rows selected by the tables.Table.read() API. As the start/end parameters are expected to have the same meaning as the built-in Python slices, this modifies the current implementation to slice all row numbers using these values using start/end.

Discovered as part of the work on ome/openmicroscopy#6412 to cover the different cases of the current table reading API. With this change included, all the test cases in testReadStartEnd introduced in ome/openmicroscopy#6412 should pass. Without it, several of the rowNumbers checks will fail.

This can also be tested manually e.g. by loading an existing table and calling table.read() with start/end values outside the [0 getNumberOfRows() - 1] range e.g.

>>> n = table.getNumberOfRows()
>>> table.read([0], -1, n)
>>> table.read([0], 0, n + 10)
>>> table.read([0], 0, -1)
>>> table.read([0], 0, -n + 1)

Without this change, the above should return incorrect values for rowNumbers. With this change, the rowNumbers should be consistent with the [start:end] slice and the columns value

Under some conditions, the rowNumbers array returned as part
of the data was inconsistent with the range of rows selected
by the tables.Table.read() API. As the start/end parameters
are expected to have the same meaning as the built-in Python
slices, this modifies the current implementation to slice
all row numbers using these values using start/end.
Copy link
Member

@chris-allan chris-allan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously the concept is what we need the thing I worry about is the performance when slicing a large table. If the table has 10M rows asking for a few hundred with row numbers included is going to perform very poorly with this implementation.

For example:

In [2]: %timeit list(range(0, 10_000_000))
198 ms ± 2.28 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

@sbesson
Copy link
Member Author

sbesson commented Sep 20, 2024

Completely agreed, this was the most generic way to solve all scenarios but has a real performance implication in the scenario you are describing above.

It should be each to add extra checks on whether start and end are within the [0 nrows-1] range. From there, I see two possible behaviors up for discussion:

  1. only apply the slice to the full list as a fallback i.e. if start and or end are outside the[0 nrows-1].
  2. decide that start,end values outside the [0 nrows-1] were never declared as part of the API contract and the implementation has been broken for 10+ years and should not supported

@sbesson
Copy link
Member Author

sbesson commented Sep 25, 2024

Reading this more carefully, I am finding there are multiple issues:

As indicated in ome/openmicroscopy#6412 (comment), the typical scenario of calling table.read(colNumbers, start, end) with 0 <= start < end < nrows works as expected and the new tests added should cover this.

I'll close this and open a separate issue to discuss the API expectation depending on the values of start/end and possible solutions

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