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

Consistency between DataTree methods and pathlib.PurePath methods #283

Closed
@TomNicholas

Description

@TomNicholas

@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 #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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions