Skip to content

DataTree.__contains__ should support pathlike syntax #9354

Open
@TomNicholas

Description

@TomNicholas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API designtopic-DataTreeRelated to the implementation of a DataTree class

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions