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

[WIP] Adds h5py dump #221

Draft
wants to merge 5 commits into
base: serialization
Choose a base branch
from
Draft

Conversation

pluflou
Copy link
Collaborator

@pluflou pluflou commented Jan 24, 2025

No description provided.

elif isinstance(val, dict):
group = f.create_group(key, track_order=True)
recursive_save(val, group)
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep the elif isinstance statements going for the other types, incl. string and ndarrays? Better to be explicit. Maybe just call str() on types that do not match anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean like this? If we call str() on the else statement, then the numpy data structures won't be saved as numpy types

                elif isinstance(val, dict):
                    group = f.create_group(key, track_order=True)
                    recursive_save(val, group)
                elif isinstance(val, str):
                    f.create_dataset(key, data=val, dtype=dt, track_order=True)
                else:
                    f.create_dataset(key, data=val, track_order=True)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but add an isinstance(val, np.ndarray) block in there

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the updated code?

        ...

        self.supported_types = (bool, int, float, np.ndarray, np.integer, np.floating)

        ...
                elif isinstance(val, self.supported_types):
                    f.create_dataset(key, data=val, track_order=True)
                elif isinstance(val, str):
                    # specify string dtype to avoid issues with encodings
                    f.create_dataset(key, data=val, dtype=dt, track_order=True)
                else:
                    f.create_dataset(key, data=str(val), track_order=True)

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 this pull request may close these issues.

2 participants