Skip to content

Commit dccb919

Browse files
committed
#137 Update runtime codes for Dataset creation
1 parent d209ef8 commit dccb919

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

xarray_dataclasses/dataset.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ def asdataset(
9797
model = DataModel.from_dataclass(dataclass)
9898
dataset = dataoptions.factory()
9999

100-
for item in model.data.values():
101-
dataset[item.name] = item(reference)
100+
for entry in model.data_vars:
101+
dataset[entry.name] = entry(reference)
102102

103-
for item in model.coord.values():
104-
if item.name in dataset.dims:
105-
dataset.coords[item.name] = item(dataset)
103+
for entry in model.coords:
104+
if entry.name in dataset.dims:
105+
dataset.coords[entry.name] = entry(dataset)
106106

107-
for item in model.coord.values():
108-
if item.name not in dataset.dims:
109-
dataset.coords[item.name] = item(dataset)
107+
for entry in model.coords:
108+
if entry.name not in dataset.dims:
109+
dataset.coords[entry.name] = entry(dataset)
110110

111-
for item in model.attr.values():
112-
dataset.attrs[item.name] = item()
111+
for entry in model.attrs:
112+
dataset.attrs[entry.name] = entry()
113113

114114
return dataset
115115

@@ -202,11 +202,11 @@ def shaped(
202202
203203
"""
204204
model = DataModel.from_dataclass(cls)
205-
data_vars: Dict[str, Any] = {}
205+
data_vars: Dict[str, np.ndarray] = {}
206206

207-
for name, item in model.data.items():
208-
shape = tuple(sizes[dim] for dim in item.type["dims"])
209-
data_vars[name] = func(shape)
207+
for key, entry in model.data_vars_items:
208+
shape = tuple(sizes[dim] for dim in entry.dims)
209+
data_vars[key] = func(shape)
210210

211211
return asdataset(cls(**data_vars, **kwargs))
212212

0 commit comments

Comments
 (0)