-
Notifications
You must be signed in to change notification settings - Fork 42
Consistency between DataTree methods and pathlib.PurePath methods #283
Comments
Hi @TomNicholas , I would like to help with the code on this one. Do you think this might be a good first issue? Thanks! |
Sure @etienneschalk! I think each of these bullet points is really it's own little issue, so feel free to open a PR for any one of them. (Maybe leave the tree-walking related ones for now though because I think those will be a little more complicated.) |
Once we have completed some of these it would also be nice to add a little section in the documentation that points out this similarity explicitly to users. Also we can then reorganise the grouping of methods in |
Pathlib The following are some notes I taken while reading the pathlib documentation, thinking about equivalences in DataTree usage ListingCurated listThis list only contains methods I did not classified as "Irrelevant". Pure Paths
Concrete PathsConcrete Paths. Could be implemented by a companion DataTreePath class attached to a DataTree instance.
Full listPure Paths
Concrete PathsConcrete Paths. Could be implemented by a companion DataTreePath class attached to a DataTree instance.
Ideas
Ideas of question for a FAQ.
@property
def parent(self: DataTree) -> DataTree | None: |
Closing in favour of pydata/xarray#9448 upstream. |
@eschalkargans suggested in #281 that the API of
DataTree
objects could more closely follow that ofpathlib.PurePath
objects. I think this aligning of APIs/nomenclature is a good idea. In general think it's conceptually useful to think of aDataTree
object as if it were an instance ofpathlib.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 toDataTree.glob
DataTree.match
that returns a boolean likePurePath.match
doesDataTree.lineage
should be renamed to.parents
Add an(this is deprecated in.is_relative_to
methodpathlib
).joinpath
method could be usefulDataTree.relative_to
should possibly have awalk_up
method (see Use new walk_up parameter in pathlib for traversing relative paths #258).with_name
method might be useful.with_segments
method might be usefulInspired by
pathlib.Path
(i.e. concrete paths):DataTree.walk
method might be a better way to expose the logic in iterators.py.rename
method might be useful.replace
method might be useful.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:
api.rst
to have a sectionPath-like methods
The text was updated successfully, but these errors were encountered: