Conversation
…ngs to h5ad Writing an object array that holds anything other than str (None, nan, numbers) as a string array to h5ad failed with h5py's bare "Can't implicitly convert non-string objects to strings", which does not say what the offending values are. Catch that TypeError in write_vlen_string_array, find the non-str items and raise a TypeError that gives their count, types and the position of the first one, chained to the original error. The happy path is unchanged and there is no cost unless h5py raises. zarr is unaffected: it coerces such items to strings silently, which the new test notes and skips.
SajalDevX
force-pushed
the
fix/h5ad-object-array-error
branch
from
September 29, 2026 12:08
e88ecb7 to
984d1ac
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2667 +/- ##
==========================================
- Coverage 87.62% 85.78% -1.85%
==========================================
Files 49 49
Lines 8129 8145 +16
==========================================
- Hits 7123 6987 -136
- Misses 1006 1158 +152
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Writing an object array that holds non-
stritems (None,nan, ints, …) as a string array to h5ad currently fails with h5py's bareThe key is reported (thanks to #1272), but not what inside the array is wrong, and the
#726thread shows how often people hit this without knowing which values to fix. With this PR the same case raiseschained (
from) to h5py's original error.How
write_vlen_string_array(h5py) wraps thecreate_datasetcall in atry/except TypeError; on failure a small helper scans the object array for non-stritems and raises the descriptive error. If the array is not an object array, or all items arestr, the original exception is re-raised untouched. Nothing runs on the happy path, so there is no cost for valid arrays.Reproducer:
Note on zarr
write_vlen_string_array_zarrbehaves differently: it silently coerces these items to strings (np.array(["a", 1], dtype=object)round-trips as["a", "1"]). I left that alone and only skip the new test for zarr, but it may be worth making the two backends consistent — happy to follow up either way if you tell me which direction you prefer.