@@ -92,11 +92,15 @@ def _map_over_subtree(tree, *args, **kwargs):
92
92
return _map_over_subtree
93
93
94
94
95
+ _DATASET_PROPERTIES_TO_EXPOSE = ['dims' , 'variables' , 'encoding' , 'sizes' , 'attrs' , 'nbytes' , 'indexes' , 'xindexes' ,
96
+ 'xindexes' , 'coords' , 'data_vars' , 'chunks' , 'real' , 'imag' ]
97
+
98
+
95
99
class DatasetPropertiesMixin :
96
100
"""Expose properties of wrapped Dataset"""
97
101
98
- # TODO a neater / more succinct way of doing this ?
99
- # we wouldn't need it at all if we inherited directly from Dataset...
102
+ # TODO a neater way of setting all of these ?
103
+ # We wouldn't need this at all if we inherited directly from Dataset...
100
104
101
105
@property
102
106
def dims (self ):
@@ -133,13 +137,73 @@ def attrs(self):
133
137
else :
134
138
raise AttributeError ("property is not defined for a node with no data" )
135
139
140
+
141
+ @property
142
+ def nbytes (self ) -> int :
143
+ return sum (node .ds .nbytes for node in self .subtree_nodes )
144
+
145
+ @property
146
+ def indexes (self ):
147
+ if self .has_data :
148
+ return self .ds .indexes
149
+ else :
150
+ raise AttributeError ("property is not defined for a node with no data" )
151
+
152
+ @property
153
+ def xindexes (self ):
154
+ if self .has_data :
155
+ return self .ds .xindexes
156
+ else :
157
+ raise AttributeError ("property is not defined for a node with no data" )
158
+
159
+ @property
160
+ def coords (self ):
161
+ if self .has_data :
162
+ return self .ds .coords
163
+ else :
164
+ raise AttributeError ("property is not defined for a node with no data" )
165
+
166
+ @property
167
+ def data_vars (self ):
168
+ if self .has_data :
169
+ return self .ds .data_vars
170
+ else :
171
+ raise AttributeError ("property is not defined for a node with no data" )
172
+
173
+ # TODO should this instead somehow give info about the chunking of every node?
174
+ @property
175
+ def chunks (self ):
176
+ if self .has_data :
177
+ return self .ds .chunks
178
+ else :
179
+ raise AttributeError ("property is not defined for a node with no data" )
180
+
181
+ @property
182
+ def real (self ):
183
+ if self .has_data :
184
+ return self .ds .real
185
+ else :
186
+ raise AttributeError ("property is not defined for a node with no data" )
187
+
188
+ @property
189
+ def imag (self ):
190
+ if self .has_data :
191
+ return self .ds .imag
192
+ else :
193
+ raise AttributeError ("property is not defined for a node with no data" )
194
+
136
195
# TODO .loc
137
196
138
197
dims .__doc__ = Dataset .dims .__doc__
139
198
variables .__doc__ = Dataset .variables .__doc__
140
199
encoding .__doc__ = Dataset .encoding .__doc__
141
200
sizes .__doc__ = Dataset .sizes .__doc__
142
201
attrs .__doc__ = Dataset .attrs .__doc__
202
+ indexes .__doc__ = Dataset .indexes .__doc__
203
+ xindexes .__doc__ = Dataset .xindexes .__doc__
204
+ coords .__doc__ = Dataset .coords .__doc__
205
+ data_vars .__doc__ = Dataset .data_vars .__doc__
206
+ chunks .__doc__ = Dataset .chunks .__doc__
143
207
144
208
145
209
_MAPPED_DOCSTRING_ADDENDUM = textwrap .fill ("This method was copied from xarray.Dataset, but has been altered to "
@@ -283,7 +347,7 @@ def __init__(
283
347
self ._add_all_dataset_api ()
284
348
285
349
def _add_all_dataset_api (self ):
286
- # Add methods like .mean (), but wrapped to map over subtrees
350
+ # Add methods like .isel (), but wrapped to map over subtrees
287
351
self ._add_dataset_methods ()
288
352
289
353
# TODO add dataset ops here
@@ -633,7 +697,7 @@ def merge_child_datasets(
633
697
datasets = [self .get (path ).ds for path in paths ]
634
698
return merge (datasets , compat = compat , join = join , fill_value = fill_value , combine_attrs = combine_attrs )
635
699
636
- def as_dataarray (self ) -> DataArray :
700
+ def as_array (self ) -> DataArray :
637
701
return self .ds .as_dataarray ()
638
702
639
703
@property
0 commit comments