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

Make illegal path-like variable names when constructing a DataTree from a Dataset #314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

etienneschalk
Copy link
Contributor

@etienneschalk etienneschalk commented Feb 17, 2024

Technical Note

Regarding Hashable vs str Dataset keys

Note: DataTree keys are Hashable. I only check for slashes in the variable names if they are instance of str.
I never encountered a case (yet) where a Dataset keys are not str but Hashable in the broader case.
We can imagine corner-cases where keys would be other types of Hashable, eg Path from pathlib

In [2]: from pathlib import Path

In [3]: hash(Path("/"))
Out[3]: -3809984204556177651

The choice I made is (1): only apply the check of slashes in the key if the key is an instance of str.
Another choice (2)would be to project the Hashable space onto str space: str(variable_name)
(1) seems more conservative than (2) as I do not pretend to be able to get a string representation for any Hashable.

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.

When creating a DataTree from a Dataset with path-like variable, subgroups are expected to be created
1 participant