Skip to content

Releases: astropenguin/xarray-dataclasses

v1.2.0 (2022-06-09)

08 Jun 15:33
8508b6e

Choose a tag to compare

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

Full Changelog: v1.1.0...v1.2.0

v1.1.0 (2022-04-14)

14 Apr 12:29
130db6c

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.0.0...v1.1.0

v1.0.0 (2022-03-06)

06 Mar 10:34
5d4b82f

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.9.0...v1.0.0

Update release

17 Feb 11:19
364216e

Choose a tag to compare

Update release Pre-release
Pre-release

What's Changed

New Contributors

Full Changelog: v0.9.0...v1.0.0-rc.1

Update release

09 Jan 04:00
7e4f315

Choose a tag to compare

What's Changed

Full Changelog: v0.8.0...v0.9.0

Update release

01 Dec 00:58
2fe1c18

Choose a tag to compare

What's Changed

Full Changelog: v0.7.0...v0.8.0

Update release

28 Nov 10:45
1e56d4e

Choose a tag to compare

What's Changed

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

27 Oct 04:51
a455dbc

Choose a tag to compare

What's Changed

Full Changelog: v0.6.0...v0.6.1

Update release

26 Sep 16:01
1beed67

Choose a tag to compare

Overview

This release closes the following issues.

  • #89 Release v0.6.0
  • #85 Update docstrings
  • #65 Fix parsing dataclass under future.annotations enabled

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

25 Sep 20:13

Choose a tag to compare

This release closes the following issues.

  • #86 Fix missing default values for default DataArray and Dataset factories