Add sanitization functions and netcdf export (with cleanup) to FileIO#173
Merged
Add sanitization functions and netcdf export (with cleanup) to FileIO#173
Conversation
martintb
approved these changes
Apr 1, 2025
Collaborator
martintb
left a comment
There was a problem hiding this comment.
See my comments. They're style focused so I'm going to click approve and let you decide if you want to address.
| Returns: | ||
| xarray.DataArray or xarray.Dataset: A copy of the input object with sanitized attributes. | ||
| """ | ||
| def sanitize_value(value): |
Collaborator
There was a problem hiding this comment.
I dislike the nested function, but Copilot seems to think it's justified so I'm not sure what to say. A general utility for jsonifying Python objects doesn't seems like a reasonable thing to put in a utils.py or even this in module.
|
|
||
| """ | ||
| da = self._obj | ||
| # sanitize attrs and make netcdf safe by converting dicts to json strings |
Collaborator
There was a problem hiding this comment.
Why are there two functions which clean up attrs? Is there a case where they would be used separately?
Collaborator
Author
There was a problem hiding this comment.
NetCDF safe is a stricter standard than json serializable.
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.
The current FileIO module is not super useful for two reasons:
This PR attempts to resolve these by adding attrs sanitization functions to the FileIO module and by adding a netcdf export that automatically unstacks multiindexes.