-
-
Notifications
You must be signed in to change notification settings - Fork 309
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 json indent #2546
Fix json indent #2546
Conversation
tests/test_metadata/test_v3.py
Outdated
self.indent = 2 | ||
|
||
# expected has extra ' ' on each line compared with json.dumps( indent=2) | ||
expected = json.dumps(json.loads(d), cls=TestIndentEncoder).encode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json.dumps
takes an indent
keyword argument, so I don't think we need the custom encoder class for this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried that first!
But json.dumps(data, indent=2)
gives a different output than a class derived from json.JSONEncoder
. The json.JSONEncoder
has an extra whitespace at the end of each line (see my comment on line 315 above).
I don't know why this is (I guess it would be nice to know)?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, i would also like to know why this is the case. is the extra whitespace more or less correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirmed this doing a test writing of some zarr data. All the zarr.json
have whitespace at the end of rows that end with a comma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, i would also like to know why this is the case. is the extra whitespace more or less correct?
I would say it's not really correct to have the extra whitespace at the end of lines.
Here, there shouldn't be whitespace after "foo",
>>> json.dumps({"test": "foo", "bar": 2}, cls=TestIndentEncoder)
'{\n "test": "foo", \n "bar": 2\n}'
9744269
to
599eefc
Compare
Co-authored-by: Joe Hamman <jhamman1@gmail.com>
00945a6
to
38d24fd
Compare
38d24fd
to
1442f4a
Compare
There are 4 test failures just now:
I wouldn't expect those to be caused by this PR? Are they passing elsewhere? |
Looking at the failing tests, I do think these are related to this PR: async def test_nbytes_stored_async() -> None:
arr = await zarr.api.asynchronous.create(shape=(100,), chunks=(10,), dtype="i4")
result = await arr.nbytes_stored()
> assert result == 366 # the size of the metadata document. This is a fragile test.
E assert 502 == 366 So it seems the change to the JSON encoding is impacting the size of the metadata document. I agree with the comment in the test "this is a fragile test". I think we should be open to changing this test or set the json encoding for these specific tests. |
I think the info test should not be hard-coding the metadata size but rather comparing the reported metadata size to the actual metadata size, that would make the test much less brittle. |
similarly, |
@d-v-b I wasn't sure how to implement your suggestion from #2546 (comment) - Maybe you could give some more pointers? |
I was thinking that instead of comparing the reported size of the metadata document to a hard-coded value, we could just get the size of the metadata document directly, and ensure that the reported size matches the observed size. We would get the actual size of the metadata document by invoking |
@d-v-b Anything else I need to do here? |
I fixed the docstests in the latest commit - 🤞 this works, and thanks for the PR! |
Great, thanks @dstansby |
This fixes the default json_indent added in #1952.
It was getting ignored in the
V3JsonEncoder
becausekwargs
has"indent": None
so thatkwargs.pop("indent", config.get("json_indent"))
always returnsNone
.TODO: