@@ -254,10 +254,12 @@ def _get_axis_coord(obj: DataArray | Dataset, key: str) -> list[str]:
254254 )
255255
256256 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 (" " ))
261263 if not search_in :
262264 search_in = set (obj .coords )
263265
@@ -1596,8 +1598,11 @@ def get_associated_variable_names(
15961598 coords : dict [str , list [str ]] = {k : [] for k in keys }
15971599 attrs_or_encoding = ChainMap (self ._obj [name ].attrs , self ._obj [name ].encoding )
15981600
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 (" " )
16011606
16021607 if "cell_measures" in attrs_or_encoding :
16031608 try :
0 commit comments