-
Notifications
You must be signed in to change notification settings - Fork 47
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
Partial reading #765
Partial reading #765
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #765 +/- ##
==========================================
+ Coverage 91.95% 92.00% +0.05%
==========================================
Files 47 47
Lines 7293 7331 +38
==========================================
+ Hits 6706 6745 +39
+ Misses 587 586 -1
|
Thanks @aeisenbarth, great PR and very well structured tests! I made some very minor adjustments here: I made a test more strict and replaced |
This PR implements modes for
read_zarr
that allow to continue reading SpatialData elements even if some elements caused read errors, for example due to corrupted files (crash during write, a race condition or copy errors). This is useful, because with growing datasets (by number of elements), a corruption of a single file can make all other elements inaccessible. The ability to read at least the unaffected data helps for data recovery.This is implemented by wrapping element-specific reader calls into a context manager
handle_read_errors
. If enabled withon_bad_files="warn"
, it converts exceptions into warnings, and continues execution. Since execution is not aborted, all subsequent code within an iteration must be wrapped in the context manager to avoid that it is executed after a handled error. In order to identify which element failed to be read, the warning message is prepended with its location, e.g.:At the end, a SpatialData object is always returned, containing only the successfully read elements.
The current implementation is at the granularity level of whole elements, that means if anything in an element causes an error, the whole element is skipped. In principle it could be made more fine-granular, e.g. returning an element with just invalid attributes skipped, or returning a table with unreadable columns skipped. Especially for large single tables with annotations for all elements, this would be very beneficial (although they are column-based, so that a corrupted file would destroy a column's values for all annotations). However, the relevant code is not contained in this repository, but requires changes in
anndata.read_zarr
. To avoid losing annotations due to file corruption, I would recommend not to use a single table, but one table per SpatialData element.For tests, see
test_read_zarr_with_error
andtest_read_zarr_with_warnings
.Closes #457
Release notes