@@ -213,9 +213,7 @@ def _get_axis_coord_single(var: Union[DataArray, Dataset], key: str) -> List[str
213
213
return results
214
214
215
215
216
- def _get_axis_coord_time_accessor (
217
- var : Union [DataArray , Dataset ], key : str
218
- ) -> List [str ]:
216
+ def _get_groupby_time_accessor (var : Union [DataArray , Dataset ], key : str ) -> List [str ]:
219
217
"""
220
218
Helper method for when our key name is of the nature "T.month" and we want to
221
219
isolate the "T" for coordinate mapping
@@ -238,7 +236,11 @@ def _get_axis_coord_time_accessor(
238
236
if "." in key :
239
237
key , ext = key .split ("." , 1 )
240
238
241
- results = _get_axis_coord_single (var , key )
239
+ results = apply_mapper (
240
+ (_get_axis_coord , _get_with_standard_name ), var , key , error = False
241
+ )
242
+ if len (results ) > 1 :
243
+ raise KeyError (f"Multiple results received for { key } ." )
242
244
return [v + "." + ext for v in results ]
243
245
244
246
else :
@@ -370,34 +372,34 @@ def _get_with_standard_name(
370
372
371
373
#: Default mappers for common keys.
372
374
_DEFAULT_KEY_MAPPERS : Mapping [str , Tuple [Mapper , ...]] = {
373
- "dim" : (_get_axis_coord ,),
374
- "dims" : (_get_axis_coord ,), # transpose
375
- "drop_dims" : (_get_axis_coord ,), # drop_dims
376
- "dimensions" : (_get_axis_coord ,), # stack
377
- "dims_dict" : (_get_axis_coord ,), # swap_dims, rename_dims
378
- "shifts" : (_get_axis_coord ,), # shift, roll
379
- "pad_width" : (_get_axis_coord ,), # shift, roll
375
+ "dim" : (_get_axis_coord , _get_with_standard_name ),
376
+ "dims" : (_get_axis_coord , _get_with_standard_name ), # transpose
377
+ "drop_dims" : (_get_axis_coord , _get_with_standard_name ), # drop_dims
378
+ "dimensions" : (_get_axis_coord , _get_with_standard_name ), # stack
379
+ "dims_dict" : (_get_axis_coord , _get_with_standard_name ), # swap_dims, rename_dims
380
+ "shifts" : (_get_axis_coord , _get_with_standard_name ), # shift, roll
381
+ "pad_width" : (_get_axis_coord , _get_with_standard_name ), # shift, roll
380
382
"names" : (
381
383
_get_axis_coord ,
382
384
_get_measure ,
383
385
_get_with_standard_name ,
384
386
), # set_coords, reset_coords, drop_vars
385
387
"labels" : (_get_axis_coord , _get_measure , _get_with_standard_name ), # drop
386
- "coords" : (_get_axis_coord ,), # interp
387
- "indexers" : (_get_axis_coord ,), # sel, isel, reindex
388
+ "coords" : (_get_axis_coord , _get_with_standard_name ), # interp
389
+ "indexers" : (_get_axis_coord , _get_with_standard_name ), # sel, isel, reindex
388
390
# "indexes": (_get_axis_coord,), # set_index
389
- "dims_or_levels" : (_get_axis_coord ,), # reset_index
390
- "window" : (_get_axis_coord ,), # rolling_exp
391
+ "dims_or_levels" : (_get_axis_coord , _get_with_standard_name ), # reset_index
392
+ "window" : (_get_axis_coord , _get_with_standard_name ), # rolling_exp
391
393
"coord" : (_get_axis_coord_single ,), # differentiate, integrate
392
394
"group" : (
393
395
_get_axis_coord_single ,
394
- _get_axis_coord_time_accessor ,
396
+ _get_groupby_time_accessor ,
395
397
_get_with_standard_name ,
396
398
),
397
399
"indexer" : (_get_axis_coord_single ,), # resample
398
400
"variables" : (_get_axis_coord , _get_with_standard_name ), # sortby
399
401
"weights" : (_get_measure_variable ,), # type: ignore
400
- "chunks" : (_get_axis_coord ,), # chunk
402
+ "chunks" : (_get_axis_coord , _get_with_standard_name ), # chunk
401
403
}
402
404
403
405
@@ -430,7 +432,7 @@ def _build_docstring(func):
430
432
mapper_docstrings = {
431
433
_get_axis_coord : f"One or more of { (_AXIS_NAMES + _COORD_NAMES )!r} " ,
432
434
_get_axis_coord_single : f"One of { (_AXIS_NAMES + _COORD_NAMES )!r} " ,
433
- _get_axis_coord_time_accessor : "Time variable accessor e.g. 'T.month'" ,
435
+ _get_groupby_time_accessor : "Time variable accessor e.g. 'T.month'" ,
434
436
_get_with_standard_name : "Standard names" ,
435
437
_get_measure_variable : f"One of { _CELL_MEASURES !r} " ,
436
438
}
@@ -900,7 +902,10 @@ def _rewrite_values(
900
902
901
903
# allow multiple return values here.
902
904
# these are valid for .sel, .isel, .coarsen
903
- all_mappers = ChainMap (key_mappers , dict .fromkeys (var_kws , (_get_axis_coord ,)))
905
+ all_mappers = ChainMap (
906
+ key_mappers ,
907
+ dict .fromkeys (var_kws , (_get_axis_coord , _get_with_standard_name )),
908
+ )
904
909
905
910
for key in set (all_mappers ) & set (kwargs ):
906
911
value = kwargs [key ]
0 commit comments