Repository navigation
Keep the fields of structured dtypes in the JSON codec - #871
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #871 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 905 935 +30
=========================================
+ Hits 905 935 +30
🚀 New features to boost your workflow:
|
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.
Fixes #518.
As pointed out in the issue,
JSON.encodestores the dtype asbuf.dtype.str, which is only|V<n>for a structured dtype, so the fields are lost anddecodefails withValueError: setting an array element with a sequence.For structured dtypes the codec now stores
dtype.descrinstead. On decode, the descr is turned back into a dtype (JSON has turned its tuples into lists) and the records are turned back into tuples, recursing into nested structured fields. Two more details were needed for that to round-trip:tolist()on a structured array leaves subarray fields as arrays, whichjsoncannot encode, so those are converted to lists first;Non-structured arrays are encoded exactly as before, and data written before this change still decodes the same way.
TODO:
test_structured_dtypeintests/test_json.pywith the array from Encoding and Decoding Compound Arrays Does not work with JSON Encoder/Decoder #518 (object fields), a 0-d array, a 2-d array with a subarray field, a nested structured field and a subarray of a structured dtype. All five fail before the change.tests/test_json.py,tests/test_zarr3.pyand the json doctest, built in a Linux container.