Skip to content

Commit ebef960

Browse files
committed
refactor the index creation
1 parent 0acb855 commit ebef960

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

xdggs/tests/conventions/test_decoders.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ def create_coordinate(grid_name, dim, level, **options):
4848
return xr.Variable(dim, cell_ids, grid_info)
4949

5050

51-
def create_index(name, coord, options):
51+
def create_index(name, coord, options=None):
5252
translations = {"refinement_level": "level", "grid_mapping_name": "grid_name"}
5353

54-
if not options:
55-
options = coord.attrs
54+
if options is None:
55+
options = {}
5656

57-
grid_info = {translations.get(name, name): value for name, value in options.items()}
57+
grid_info = {
58+
translations.get(name, name): value for name, value in coord.attrs.items()
59+
}
5860

59-
return xdggs.HealpixIndex.from_variables({name: coord}, options=grid_info)
61+
return xdggs.HealpixIndex.from_variables({name: coord}, options=grid_info | options)
6062

6163

6264
@pytest.mark.parametrize("obj_type", ["DataArray", "Dataset"])
@@ -175,7 +177,7 @@ def test_cf(obj_type, coord_name, dim, metadata, grid_info, name):
175177

176178
expected = xr.Coordinates(
177179
{coord_name: coord},
178-
indexes={coord_name: create_index(coord_name, coord, grid_info=metadata)},
180+
indexes={coord_name: create_index(coord_name, coord, options=metadata)},
179181
)
180182
actual = decoders.cf(obj, grid_info, name, index_options={})
181183
xr.testing.assert_identical(actual.to_dataset(), expected.to_dataset())

0 commit comments

Comments
 (0)