Releases: astropenguin/xarray-dataclasses
v1.2.0 (2022-06-09)
From this release, special type hints (Attr, Coord, Data, Name) can be used within union types.
This would be useful if you want to customize values after dataclass object creation (__post_init__).
The following example automatically sets ranged values to x and y coordinates if they are not specified.
import numpy as np
from dataclasses import dataclass
from typing import Literal, Optional
from xarray_dataclasses import AsDataArray, Coord, Data
X = Literal["x"]
Y = Literal["y"]
@dataclass
class Image(AsDataArray):
"""2D image as DataArray."""
data: Data[tuple[X, Y], float]
x: Optional[Coord[X, int]] = None
y: Optional[Coord[Y, int]] = None
def __post_init__(self) -> None:
"""Set ranged values to x and y."""
shape = np.shape(self.data)
if self.x is None:
self.x = np.arange(shape[0])
if self.y is None:
self.y = np.arange(shape[1])What's Changed
- Update static type check by @astropenguin in #153
- Update typing module by @astropenguin in #158
- Release v1.2.0 by @astropenguin in #161
Full Changelog: v1.1.0...v1.2.0
v1.1.0 (2022-04-14)
What's Changed
- README typo: varible by @thewtex in #145
- Add support of Python 3.10 by @astropenguin in #149
- Release v1.1.0 by @astropenguin in #151
New Contributors
Full Changelog: v1.0.0...v1.1.0
v1.0.0 (2022-03-06)
What's Changed
- Remove deprecated features by @astropenguin in #128
- Update project dependencies by @astropenguin in #130
- Bump ipython from 7.31.0 to 7.31.1 by @dependabot in #134
- Preferentially use data options if they are given in asdata* functions by @astropenguin in #136
- Update data model by @astropenguin in #138
- Release v1.0.0-rc.1 by @astropenguin in #140
- Update protocol for public type hints by @astropenguin in #142
- Release v1.0.0 by @astropenguin in #144
New Contributors
- @dependabot made their first contribution in #134
Full Changelog: v0.9.0...v1.0.0
Update release
What's Changed
- Remove deprecated features by @astropenguin in #128
- Update project dependencies by @astropenguin in #130
- Bump ipython from 7.31.0 to 7.31.1 by @dependabot in #134
- Preferentially use data options if they are given in asdata* functions by @astropenguin in #136
- Update data model by @astropenguin in #138
- Release v1.0.0-rc.1 by @astropenguin in #140
New Contributors
- @dependabot made their first contribution in #134
Full Changelog: v0.9.0...v1.0.0-rc.1
Update release
What's Changed
- Assign dim coords to DataArray first by @astropenguin in #117
- Use name-field value as data-variable name by @astropenguin in #118
- Fix mix-in classes by @astropenguin in #122
- Add classmethod to create a shaped array by @astropenguin in #124
- Release v0.9.0 by @astropenguin in #126
Full Changelog: v0.8.0...v0.9.0
Update release
What's Changed
- Add NumPy-like zeros, ones, ... to Dataset class by @astropenguin in #111
- Add data options by @astropenguin in #113
- Release v0.8.0 by @astropenguin in #115
Full Changelog: v0.7.0...v0.8.0
Update release
What's Changed
- Update dev environment by @astropenguin in #103
- Fix type hints that cause errors in static type check by @astropenguin in #106
- Update NumPy-like zeros, ones, ... to be compatible with sizes by @astropenguin in #107
- Update README and docstrings by @astropenguin in #108
- Release v0.7.0 by @astropenguin in #110
Full Changelog: v0.6.1...v0.7.0
Future breaking changes from v1.0.0
Please note that the following behavior will change from v1.0.0 due to bug fixes and updates.
Dims and dtype specifications with bare strings will raise NameError
Due to the support of PEP 563 (#65), bare strings (i.e. forward references) in a type hint will raise NameError unless the backward type definitions exist. From v1.0.0, for example, the following code will raise NameError.
@dataclass
class Image(AsDataArray):
data: Data[tuple["x", "y"], float]Until v1.0.0, for backward compatibility, such bare strings are forcibly converted to literal type in DataArray or Dataset creation even if backward type definition exists. Since this behavior is not standard in Python, however, we will stop using the workaround from v1.0.0.
To deal with the change, please replace bare strings with literal types in your codes.
@dataclass
class Image(AsDataArray):
data: Data[tuple[Literal["x"], Literal["y"]], float]or define type aliases before the class definition.
X = Literal["x"]
Y = Literal["y"]
@dataclass
class Image(AsDataArray):
data: Data[tuple[X, Y], float]Update release
What's Changed
- Remove copy function by @astropenguin in #95
- Use copy function by @astropenguin in #97
- Add marker file for typing by @astropenguin in #99
- Release v0.6.1 by @astropenguin in #101
Full Changelog: v0.6.0...v0.6.1
Update release
Overview
This release closes the following issues.
Future breaking changes from v1.0.0
Please note that the following behavior will change from v1.0.0 due to bug fixes and updates.
Dims and dtype specifications with bare strings will raise NameError
Due to the support of PEP 563 (#65), bare strings (i.e. forward references) in a type hint will raise NameError unless the backward type definitions exist. From v1.0.0, for example, the following code will raise NameError.
@dataclass
class Image(AsDataArray):
data: Data[tuple["x", "y"], float]Until v1.0.0, for backward compatibility, such bare strings are forcibly converted to literal type in DataArray or Dataset creation even if backward type definition exists. Since this behavior is not standard in Python, however, we will stop using the workaround from v1.0.0.
To deal with the change, please replace bare strings with literal types in your codes.
@dataclass
class Image(AsDataArray):
data: Data[tuple[Literal["x"], Literal["y"]], float]or define type aliases before the class definition.
X = Literal["x"]
Y = Literal["y"]
@dataclass
class Image(AsDataArray):
data: Data[tuple[X, Y], float]Bug-fix release
This release closes the following issues.
- #86 Fix missing default values for default DataArray and Dataset factories