Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

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

Closed

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.

@TomNicholas
Copy link
Member

@etienneschalk sorry for missing this - do you want to re-submit this PR to xarray upstream?

@TomNicholas
Copy link
Member

Closing in favour of all the upstream versions of this issue - see links above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
2 participants