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

DataTree.__contains__ should support pathlike syntax #9354

Open
TomNicholas opened this issue Aug 13, 2024 · 0 comments
Open

DataTree.__contains__ should support pathlike syntax #9354

TomNicholas opened this issue Aug 13, 2024 · 0 comments
Labels
API design topic-DataTree Related to the implementation of a DataTree class

Comments

@TomNicholas
Copy link
Member

What is your issue?

Summarizing xarray-contrib/datatree#240 (comment):

Basically DataTree.__getitem__ will currently return more things than DataTree.__contains__ will actually tell you are "in" the tree, which can be confusing.

To fix this __contains__ should support path-like syntax.

I also think that it's convenient that we can separate the "is this key in the local node's variables" question from the "is this path in the tree anywhere" question. In the former case the key will never have a / character and the latter case it will always have one, so we could perhaps think of this like overloading the __contains__ method to behave slightly differently for str vs PathLike types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API design topic-DataTree Related to the implementation of a DataTree class
Projects
None yet
Development

No branches or pull requests

1 participant