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

Consistency between DataTree methods and pathlib.PurePath methods #9448

Open
14 tasks
TomNicholas opened this issue Sep 7, 2024 · 0 comments
Open
14 tasks
Labels
API design enhancement topic-DataTree Related to the implementation of a DataTree class

Comments

@TomNicholas
Copy link
Member

What is your issue?

Copied from xarray-contrib/datatree#283

@eschalkargans suggested in #281 that the API of DataTree objects could more closely follow that of pathlib.PurePath objects. I think this aligning of APIs/nomenclature is a good idea. In general think it's conceptually useful to think of a DataTree object as if it were an instance of pathlib.PurePosixPath (even though the actual implementation should not work like that).

There are various methods we might want to add/change to make them more compatible:

Inspired by pathlib.PurePath:

  • DataTree.match should be renamed to DataTree.glob
  • Add a new method DataTree.match that returns a boolean like PurePath.match does
  • DataTree.lineage should be renamed to .parents
  • Add an .is_relative_to method (this is deprecated in pathlib)
  • A new .joinpath method could be useful
  • DataTree.relative_to should possibly have a walk_up method (see Use new walk_up parameter in pathlib for traversing relative paths xarray-contrib/datatree#258)
  • A new .with_name method might be useful
  • A new .with_segments method might be useful

Inspired by pathlib.Path (i.e. concrete paths):

  • A new DataTree.walk method might be a better way to expose the logic in iterators.py
  • A new .rename method might be useful
  • A new .replace method might be useful
  • A new .rglob method (though having this and .glob seems overkill)

Several of these might be useful abstractions internally, especially .joinpath, .walk, and .replace.

EDIT: Let's also document this similarity:

  • Add section to documentation explicitly pointing out this alignment of APIs (#287)
  • Reorganise api.rst to have a section Path-like methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API design enhancement topic-DataTree Related to the implementation of a DataTree class
Projects
None yet
Development

No branches or pull requests

1 participant