Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.5
rev: v0.16.0
hooks:
- id: ruff-check
args: [--fix] # optional, to autofix lint errors
- id: ruff-format
- repo: https://github.com/fsouza/mirrors-pyright
rev: v1.1.403
rev: v1.1.275
hooks:
- id: pyright
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.24.1
rev: v0.25
hooks:
- id: validate-pyproject
name: "python · Validate pyproject.toml"
Expand Down
16 changes: 6 additions & 10 deletions src/xarray_dataclass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
__all__ = [
"AsDataArray",
"AsDataset",
"DataModel",
"DataOptions",
"Attr",
"Coord",
"Coordof",
"Data",
"DataModel",
"DataOptions",
"Dataof",
"Name",
"__version__",
"asdataarray",
"asdataset",
"dataarray",
"dataset",
"datamodel",
"dataoptions",
"dataset",
"typing",
"__version__",
]


# submodules
from . import dataarray
from . import dataset
from . import datamodel
from . import dataoptions
from . import typing
from . import dataarray, datamodel, dataoptions, dataset, typing
from .__about__ import __version__
from .dataarray import AsDataArray, asdataarray
from .dataset import AsDataset, asdataset
from .datamodel import DataModel
from .dataoptions import DataOptions
from .dataset import AsDataset, asdataset
from .typing import (
Attr,
Coord,
Expand Down
7 changes: 2 additions & 5 deletions src/xarray_dataclass/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
from types import MethodType
from typing import Any, Callable, Optional, Protocol, Type, TypeVar, Union, overload


# dependencies
import numpy as np
import xarray as xr
from typing_extensions import ParamSpec


# submodules
from .datamodel import DataModel
from .dataoptions import DataOptions
from .typing import AnyArray, AnyXarray, DataClass, Order, Shape, Sizes


# type hints
PInit = ParamSpec("PInit")
TDataArray = TypeVar("TDataArray", bound=xr.DataArray)
Expand Down Expand Up @@ -143,8 +140,8 @@ def new(cls: Any) -> Any:
def new(cls: Any, *args: Any, **kwargs: Any) -> Any:
return asdataarray(cls(*args, **kwargs))

setattr(new, "__doc__", cls.__init__.__doc__)
setattr(new, "__signature__", sig)
new.__doc__ = cls.__init__.__doc__
new.__signature__ = sig
return MethodType(new, cls)

@overload
Expand Down
7 changes: 2 additions & 5 deletions src/xarray_dataclass/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@


# standard library
from collections.abc import Hashable
from dataclasses import dataclass, field, is_dataclass
from typing import (
Any,
Dict,
get_type_hints,
Hashable,
List,
Literal,
Optional,
Tuple,
Type,
Union,
cast,
get_type_hints,
)


# dependencies
import numpy as np
import xarray as xr
from typing_extensions import ParamSpec


# submodules
from .typing import (
AnyDType,
Expand All @@ -42,7 +40,6 @@
get_role,
)


# type hints
PInit = ParamSpec("PInit")
AnyDataClass = Union[Type[DataClass[PInit]], DataClass[PInit]]
Expand Down
2 changes: 0 additions & 2 deletions src/xarray_dataclass/dataoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
from dataclasses import dataclass
from typing import Callable, Generic, TypeVar


# submodules
from .typing import AnyXarray


# type hints
TAnyXarray = TypeVar("TAnyXarray", bound=AnyXarray)

Expand Down
7 changes: 2 additions & 5 deletions src/xarray_dataclass/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
from types import MethodType
from typing import Any, Callable, Dict, Optional, Protocol, Type, TypeVar, overload


# dependencies
import numpy as np
import xarray as xr
from typing_extensions import ParamSpec


# submodules
from .datamodel import DataModel
from .dataoptions import DataOptions
from .typing import AnyArray, AnyXarray, DataClass, Order, Shape, Sizes


# type hints
PInit = ParamSpec("PInit")
TDataset = TypeVar("TDataset", bound=xr.Dataset)
Expand Down Expand Up @@ -143,8 +140,8 @@ def new(cls: Any) -> Any:
def new(cls: Any, *args: Any, **kwargs: Any) -> Any:
return asdataset(cls(*args, **kwargs))

setattr(new, "__doc__", cls.__init__.__doc__)
setattr(new, "__signature__", sig)
new.__doc__ = cls.__init__.__doc__
new.__signature__ = sig
return MethodType(new, cls)

@overload
Expand Down
15 changes: 4 additions & 11 deletions src/xarray_dataclass/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,33 @@


# standard library
from collections.abc import Collection, Hashable, Iterable, Sequence
from dataclasses import Field, is_dataclass
from enum import Enum
from itertools import chain
from typing import (
Annotated,
Any,
ClassVar,
Collection,
Dict,
Generic,
get_args,
get_origin,
get_type_hints,
Hashable,
Iterable,
Literal,
Optional,
Protocol,
Sequence,
Tuple,
Type,
TypeVar,
Union,
get_args,
get_origin,
get_type_hints,
)


# dependencies
import numpy as np
import xarray as xr
from typing_extensions import ParamSpec, TypeAlias


# type hints (private)
PInit = ParamSpec("PInit")
T = TypeVar("T")
Expand Down Expand Up @@ -80,8 +75,6 @@ def __init__(self, *args: PInit.args, **kwargs: PInit.kwargs) -> None: ...
class Labeled(Generic[TDims]):
"""Type hint for labeled objects."""

pass


# type hints (public)
class Role(Enum):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# standard library
from collections.abc import Collection
from dataclasses import dataclass
from typing import Collection, Literal as L, Tuple, Union

from typing import Annotated as Ann
from typing import Literal as L
from typing import Tuple, Union

# dependencies
import numpy as np
from typing_extensions import Annotated as Ann
from xarray_dataclass.typing import Attr, Coord, Coordof, Data

from xarray_dataclass.typing import Attr, Coord, Coordof, Data

# type hints
X = L["x"]
Expand Down
2 changes: 0 additions & 2 deletions tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import xarray as xr
from typing_extensions import TypeAlias


# submodules
from xarray_dataclass.dataarray import AsDataArray
from xarray_dataclass.dataoptions import DataOptions
from xarray_dataclass.typing import Attr, Coord, Data, Name


# constants
DIMS = "x", "y"
SHAPE = 10, 10
Expand Down
2 changes: 0 additions & 2 deletions tests/test_datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
from dataclasses import dataclass
from typing import Literal, Tuple


# submodules
from xarray_dataclass.datamodel import DataModel
from xarray_dataclass.typing import Attr, Coord, Coordof, Data, Dataof


# type hints
X = Literal["x"]
Y = Literal["y"]
Expand Down
4 changes: 1 addition & 3 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from dataclasses import dataclass
from typing import Literal, Tuple


# dependencies
import numpy as np
import xarray as xr
from typing_extensions import TypeAlias


# submodules
from xarray_dataclass.dataarray import AsDataArray
from xarray_dataclass.dataset import AsDataset
from xarray_dataclass.dataoptions import DataOptions
from xarray_dataclass.dataset import AsDataset
from xarray_dataclass.typing import Attr, Coord, Data

# constants
Expand Down
8 changes: 3 additions & 5 deletions tests/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# standard library
from typing import Any, Literal as L, Tuple, Union

from typing import Annotated as Ann
from typing import Any, Tuple, Union
from typing import Literal as L

# dependencies
import numpy as np
from pytest import mark
from typing_extensions import Annotated as Ann


# submodules
from xarray_dataclass.typing import (
Expand All @@ -21,7 +20,6 @@
get_role,
)


# test datasets
testdata_dims = [
(Coord[Tuple[()], Any], ()),
Expand Down
Loading