Skip to content

Commit

Permalink
add utility for joining path on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Oct 19, 2024
1 parent dd0280d commit 1f07b63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 0 additions & 4 deletions xarray/core/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ def _to_new_dataset(data: Dataset | Coordinates | None) -> Dataset:
return ds


def _join_path(root: str, name: str) -> str:
return str(NodePath(root) / name)


def _inherited_dataset(ds: Dataset, parent: Dataset) -> Dataset:
return Dataset._construct_direct(
variables=parent._variables | ds._variables,
Expand Down
10 changes: 6 additions & 4 deletions xarray/core/treenode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import collections
import os
import sys
from collections.abc import Iterator, Mapping
from pathlib import PurePosixPath
Expand Down Expand Up @@ -45,6 +44,10 @@ def __init__(self, *pathsegments):
# TODO should we also forbid suffixes to avoid node names with dots in them?


def join_path(base: str, name: str, /) -> str:
return str(NodePath(base) / name)


Tree = TypeVar("Tree", bound="TreeNode")


Expand Down Expand Up @@ -435,8 +438,7 @@ def subtree_with_keys(self: Tree) -> Iterator[tuple[str, Tree]]:
path, node = queue.popleft()
yield path, node
queue.extend(
(os.path.join(path, name), child)
for name, child in node.children.items()
(join_path(path, name), child) for name, child in node.children.items()
)

@property
Expand Down Expand Up @@ -870,7 +872,7 @@ def group_subtrees(

for name in first_node.children:
child_nodes = tuple(node.children[name] for node in active_nodes)
queue.append((os.path.join(path, name), child_nodes))
queue.append((join_path(path, name), child_nodes))


def zip_subtrees(
Expand Down

0 comments on commit 1f07b63

Please sign in to comment.