@@ -104,23 +104,21 @@ def asdataarray(
104
104
dataoptions = DataOptions (xr .DataArray )
105
105
106
106
model = DataModel .from_dataclass (dataclass )
107
- item = next (iter (model .data .values ()))
108
- dataarray = dataoptions .factory (item (reference ))
107
+ dataarray = dataoptions .factory (model .data_vars [0 ](reference ))
109
108
110
- for item in model .coord . values () :
111
- if item .name in dataarray .dims :
112
- dataarray .coords [item .name ] = item (dataarray )
109
+ for entry in model .coords :
110
+ if entry .name in dataarray .dims :
111
+ dataarray .coords [entry .name ] = entry (dataarray )
113
112
114
- for item in model .coord . values () :
115
- if item .name not in dataarray .dims :
116
- dataarray .coords [item .name ] = item (dataarray )
113
+ for entry in model .coords :
114
+ if entry .name not in dataarray .dims :
115
+ dataarray .coords [entry .name ] = entry (dataarray )
117
116
118
- for item in model .attr . values () :
119
- dataarray .attrs [item .name ] = item ()
117
+ for entry in model .attrs :
118
+ dataarray .attrs [entry .name ] = entry ()
120
119
121
- if model .name :
122
- item = next (iter (model .name .values ()))
123
- dataarray .name = item ()
120
+ if model .names :
121
+ dataarray .name = model .names [0 ]()
124
122
125
123
return dataarray
126
124
@@ -213,12 +211,12 @@ def shaped(
213
211
214
212
"""
215
213
model = DataModel .from_dataclass (cls )
216
- name , item = next ( iter ( model .data . items ()))
214
+ key , entry = model .data_vars_items [ 0 ]
217
215
218
216
if isinstance (shape , dict ):
219
- shape = tuple (shape [dim ] for dim in item . type [ " dims" ] )
217
+ shape = tuple (shape [dim ] for dim in entry . dims )
220
218
221
- return asdataarray (cls (** {name : func (shape )}, ** kwargs ))
219
+ return asdataarray (cls (** {key : func (shape )}, ** kwargs ))
222
220
223
221
@overload
224
222
@classmethod
0 commit comments