12
12
List ,
13
13
Mapping ,
14
14
MutableMapping ,
15
+ Optional ,
15
16
Set ,
16
17
Tuple ,
17
18
Union ,
@@ -608,10 +609,9 @@ def check_results(names, k):
608
609
609
610
try :
610
611
for name in allnames :
611
- extravars = accessor .get_associated_variable_names (name )
612
- # we cannot return bounds variables with scalar keys
613
- if scalar_key :
614
- extravars .pop ("bounds" )
612
+ extravars = accessor .get_associated_variable_names (
613
+ name , skip_bounds = scalar_key
614
+ )
615
615
coords .extend (itertools .chain (* extravars .values ()))
616
616
617
617
if isinstance (obj , DataArray ):
@@ -1209,7 +1209,9 @@ def standard_names(self) -> Dict[str, List[str]]:
1209
1209
1210
1210
return {k : sorted (v ) for k , v in vardict .items ()}
1211
1211
1212
- def get_associated_variable_names (self , name : Hashable ) -> Dict [str , List [str ]]:
1212
+ def get_associated_variable_names (
1213
+ self , name : Hashable , skip_bounds : Optional [bool ] = None
1214
+ ) -> Dict [str , List [str ]]:
1213
1215
"""
1214
1216
Returns a dict mapping
1215
1217
1. "ancillary_variables"
@@ -1223,6 +1225,8 @@ def get_associated_variable_names(self, name: Hashable) -> Dict[str, List[str]]:
1223
1225
1224
1226
name: Hashable
1225
1227
1228
+ skip_bounds: bool, optional
1229
+
1226
1230
Returns
1227
1231
------
1228
1232
@@ -1248,13 +1252,13 @@ def get_associated_variable_names(self, name: Hashable) -> Dict[str, List[str]]:
1248
1252
"ancillary_variables"
1249
1253
].split (" " )
1250
1254
1251
- if "bounds" in attrs_or_encoding :
1252
- coords [ "bounds" ] = [ attrs_or_encoding [ "bounds" ]]
1253
-
1254
- for dim in self ._obj [name ].dims :
1255
- dbounds = self ._obj [dim ].attrs .get ("bounds" , None )
1256
- if dbounds :
1257
- coords ["bounds" ].append (dbounds )
1255
+ if not skip_bounds :
1256
+ if "bounds" in attrs_or_encoding :
1257
+ coords [ "bounds" ] = [ attrs_or_encoding [ "bounds" ]]
1258
+ for dim in self ._obj [name ].dims :
1259
+ dbounds = self ._obj [dim ].attrs .get ("bounds" , None )
1260
+ if dbounds :
1261
+ coords ["bounds" ].append (dbounds )
1258
1262
1259
1263
allvars = itertools .chain (* coords .values ())
1260
1264
missing = set (allvars ) - set (self ._maybe_to_dataset ().variables )
0 commit comments