@@ -741,20 +741,25 @@ def __getitem__(self, key: Union[str, List[str]]):
741
741
# 2. set measures variables as coordinates
742
742
# 3. set ancillary variables as coordinates
743
743
for name in varnames :
744
- attrs = self ._obj [name ].attrs
745
- if "coordinates" in attrs :
746
- coords .extend (attrs .get ("coordinates" ).split (" " ))
744
+ attrs_or_encoding = ChainMap (
745
+ self ._obj [name ].attrs , self ._obj [name ].encoding
746
+ )
747
+ if "coordinates" in attrs_or_encoding :
748
+ coords .extend (attrs_or_encoding ["coordinates" ].split (" " ))
747
749
748
- if "cell_measures" in attrs :
750
+ if "cell_measures" in attrs_or_encoding :
749
751
measures = [
750
752
_get_measure (self ._obj [name ], measure )
751
753
for measure in _CELL_MEASURES
752
- if measure in attrs ["cell_measures" ]
754
+ if measure in attrs_or_encoding ["cell_measures" ]
753
755
]
754
756
coords .extend (_strip_none_list (* measures ))
755
757
756
- if isinstance (self ._obj , xr .Dataset ) and "ancillary_variables" in attrs :
757
- anames = attrs ["ancillary_variables" ].split (" " )
758
+ if (
759
+ isinstance (self ._obj , xr .Dataset )
760
+ and "ancillary_variables" in attrs_or_encoding
761
+ ):
762
+ anames = attrs_or_encoding ["ancillary_variables" ].split (" " )
758
763
coords .extend (anames )
759
764
760
765
if isinstance (self ._obj , xr .DataArray ):
0 commit comments