astropenguin / xarray-dataclasses

:zap: xarray data creation by data classes
https://astropenguin.github.io/xarray-dataclasses/
MIT License
71 stars 4 forks source link

Attributes on data array in dataset. (Feature) #47

Closed shaunc closed 3 years ago

shaunc commented 3 years ago

Currently there seems to be no way to specify attributes for a DataArray in a Dataset. Indeed, even if they are passed to new() in a DataArray, they are discarded.

It would be nice to reuse DataArray specs to be able specify these:


from xarray_datasetclasses import dataarrayclass, datasetspce, Data, Attr, DataArray

@dataarrayclass
class FooSpec:
    data: Data['x', float]
    meta: Attr[int]

@datasetclass
class BarSpec:
    array: DataArray[FooSpec]

Does that look useful? Here DataArray is from xarray_datasetclasses ... if this name isn't good because of conflict with xarray, perhaps ... ArraySpec?

astropenguin commented 3 years ago

@shaunc Please let me close the issue because the feature was implemented by #59 and is now available in v0.4.0. To achieve the feature, I added new type hints (Dataof and Coordof; see also "Advanced usage" in README). Please feel free to raise any issues if you have some requests on the feature. Thank you!

shaunc commented 3 years ago

Sounds good! (Sorry I haven't been of more help -- swamped by other work!)