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

Writing JSON from npz fails because int64 is not JSON serializable #14

Closed
mlincett opened this issue Jul 28, 2023 · 3 comments · Fixed by #16
Closed

Writing JSON from npz fails because int64 is not JSON serializable #14

mlincett opened this issue Jul 28, 2023 · 3 comments · Fixed by #16

Comments

@mlincett
Copy link
Contributor

I am trying to convert old npz test data to JSON in order to make CI testing of skymap_scanner more transparent. Although such conversion seems to fail.

python examples/npz_to_json.py --input-file skymap_scanner/tests/data/results_npz/millipede_wilks/run00127907.evt000020178442.HESE_1.npz

[...]

TypeError: Object of type int64 is not JSON serializable
@kjmeagher
Copy link
Member

json doesn't understand numpy types, you can call array.tolist() before trying to serialize

@mlincett
Copy link
Contributor Author

json doesn't understand numpy types, you can call array.tolist() before trying to serialize

Makes sense. I was just wondering whether or not this used to work in the past, considering that the CI test seems to output JSON just fine.

I guess when we build SkyScanResult from the runtime scanner output it does not use the numpy type for the internal representation but it does when loading a npz.

@mlincett
Copy link
Contributor Author

mlincett commented Jul 29, 2023

The python exception is annoyingly cryptic about where the problem is. However since the JSON file is sequentially written just up to where the error occurs, it appears that the problem are the metadata (likely the nside field).

Edit: this is due to us storing metadata in the dtype.metadata of numpy, something I'd like to move away from (see new issue #15).

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 a pull request may close this issue.

2 participants