Skip to content

Example not working in VSCode #211

@krokosik

Description

@krokosik

The whole reason I'd like to use this package is to have in editor suggestions when working with Xarray. However, even the case provided in the README does not work in the current 1.6.0 version. In particular, the following code produces an error with basic type checking.

from dataclasses import dataclass
from typing import Literal
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: Coord[X, int] = 0
    y: Coord[Y, int] = 0


image = Image.new([[2.0, 2.0], [2.0, 2.0]], x=[0, 1], y=[0, 1])
Argument of type "list[list[float]]" cannot be assigned to parameter "data" of type "Data[tuple[X, Y], float]"
  "list[float]" is incompatible with "float"
  "list[float]" is incompatible with "float"Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions