@@ -254,10 +254,12 @@ def _get_axis_coord(obj: DataArray | Dataset, key: str) -> list[str]:
254
254
)
255
255
256
256
search_in = set ()
257
- if "coordinates" in obj .encoding :
258
- search_in .update (obj .encoding ["coordinates" ].split (" " ))
259
- if "coordinates" in obj .attrs :
260
- search_in .update (obj .attrs ["coordinates" ].split (" " ))
257
+ attrs_or_encoding = ChainMap (obj .attrs , obj .encoding )
258
+ coordinates = attrs_or_encoding .get ("coordinates" , None )
259
+ # Handles case where the coordinates attribute is None
260
+ # This is used to tell xarray to not write a coordinates attribute
261
+ if coordinates :
262
+ search_in .update (coordinates .split (" " ))
261
263
if not search_in :
262
264
search_in = set (obj .coords )
263
265
@@ -1596,8 +1598,11 @@ def get_associated_variable_names(
1596
1598
coords : dict [str , list [str ]] = {k : [] for k in keys }
1597
1599
attrs_or_encoding = ChainMap (self ._obj [name ].attrs , self ._obj [name ].encoding )
1598
1600
1599
- if "coordinates" in attrs_or_encoding :
1600
- coords ["coordinates" ] = attrs_or_encoding ["coordinates" ].split (" " )
1601
+ coordinates = attrs_or_encoding .get ("coordinates" , None )
1602
+ # Handles case where the coordinates attribute is None
1603
+ # This is used to tell xarray to not write a coordinates attribute
1604
+ if coordinates :
1605
+ coords ["coordinates" ] = coordinates .split (" " )
1601
1606
1602
1607
if "cell_measures" in attrs_or_encoding :
1603
1608
try :
0 commit comments