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

Commit

Permalink
Merge branch 'main' into feature/zarr-v3-support
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas authored Oct 17, 2023
2 parents 7330a50 + c059fb0 commit 98a83ce
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ repos:
- id: isort
# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
# - repo: https://github.com/Carreau/velin
Expand All @@ -32,7 +32,7 @@ repos:
# - id: velin
# args: ["--write", "--compact"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
rev: v1.5.1
hooks:
- id: mypy
# Copied from setup.cfg
Expand All @@ -45,7 +45,7 @@ repos:
types-pytz,
# Dependencies that are typed
numpy,
typing-extensions==3.10.0.0,
typing-extensions>=4.1.0,
]
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
# - repo: https://github.com/asottile/pyupgrade
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ that was more flexible than a single `xarray.Dataset` object.
The initial motivation was to represent netCDF files / Zarr stores with multiple nested groups in a single in-memory object,
but `datatree.DataTree` objects have many other uses.

### Installation
You can install datatree via pip:
```shell
pip install xarray-datatree
```

or via conda-forge
```shell
conda install -c conda-forge xarray-datatree
```

### Why Datatree?

You might want to use datatree for:
Expand Down
6 changes: 3 additions & 3 deletions datatree/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assert_isomorphic(a: DataTree, b: DataTree, from_root: bool = False):
assert_identical
"""
__tracebackhide__ = True
assert type(a) == type(b)
assert isinstance(a, type(b))

if isinstance(a, DataTree):
if from_root:
Expand Down Expand Up @@ -71,7 +71,7 @@ def assert_equal(a: DataTree, b: DataTree, from_root: bool = True):
assert_identical
"""
__tracebackhide__ = True
assert type(a) == type(b)
assert isinstance(a, type(b))

if isinstance(a, DataTree):
if from_root:
Expand Down Expand Up @@ -109,7 +109,7 @@ def assert_identical(a: DataTree, b: DataTree, from_root: bool = True):
"""

__tracebackhide__ = True
assert type(a) == type(b)
assert isinstance(a, type(b))
if isinstance(a, DataTree):
if from_root:
a = a.root
Expand Down
8 changes: 7 additions & 1 deletion datatree/tests/test_treenode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from datatree.iterators import LevelOrderIter, PreOrderIter
from datatree.treenode import InvalidTreeError, NamedNode, TreeNode
from datatree.treenode import InvalidTreeError, NamedNode, NodePath, TreeNode


class TestFamilyTree:
Expand Down Expand Up @@ -369,3 +369,9 @@ def test_render_nodetree(self):
]
for expected_node, printed_node in zip(expected_nodes, printout.splitlines()):
assert expected_node in printed_node


def test_nodepath():
path = NodePath("/Mary")
assert path.root == "/"
assert path.stem == "Mary"
16 changes: 8 additions & 8 deletions datatree/treenode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from collections import OrderedDict
from pathlib import PurePosixPath
from typing import (
Expand Down Expand Up @@ -30,21 +31,20 @@ class NotFoundInTreeError(ValueError):
class NodePath(PurePosixPath):
"""Represents a path from one node to another within a tree."""

def __new__(cls, *args: str | "NodePath") -> "NodePath":
obj = super().__new__(cls, *args)

if obj.drive:
def __init__(self, *pathsegments):
if sys.version_info >= (3, 12):
super().__init__(*pathsegments)
else:
super().__new__(PurePosixPath, *pathsegments)
if self.drive:
raise ValueError("NodePaths cannot have drives")

if obj.root not in ["/", ""]:
if self.root not in ["/", ""]:
raise ValueError(
'Root of NodePath can only be either "/" or "", with "" meaning the path is relative.'
)

# TODO should we also forbid suffixes to avoid node names with dots in them?

return obj


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

Expand Down
3 changes: 3 additions & 0 deletions docs/source/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Deprecations
Bug fixes
~~~~~~~~~

- Ensure nodepath class is compatible with python 3.12 (:pull:`260`)
By `Max Grover <https://github.com/mgrover1>`_.

Documentation
~~~~~~~~~~~~~

Expand Down

0 comments on commit 98a83ce

Please sign in to comment.