Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/metpy/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,10 @@ def parse_cf(self, varname=None, coordinates=None):

# Attempt to build the crs coordinate
crs = None
if 'grid_mapping' in var.attrs:
# Use given CF grid_mapping
proj_name = var.attrs['grid_mapping']

# Check both raw attribute and xarray-handled and moved to encoding
proj_name = var.encoding.get('grid_mapping', var.attrs.get('grid_mapping'))
if proj_name is not None:
try:
proj_var = self._dataset.variables[proj_name]
except KeyError:
Expand Down
15 changes: 6 additions & 9 deletions tests/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
grid_deltas_from_dataarray, preprocess_and_wrap)


@pytest.fixture
def test_ds():
@pytest.fixture(params=[True, 'all'])
def test_ds(request):
"""Provide an xarray dataset for testing."""
return xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))
return xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False),

Check warning

Code scanning / CodeQL

File is not always closed

File is opened but is not closed.
decode_coords=request.param)


@pytest.fixture
Expand All @@ -47,7 +48,8 @@ def test_var(test_ds):
def test_var_multidim_full(test_ds):
"""Provide a variable with x/y coords and multidimensional lat/lon auxiliary coords."""
return (test_ds[{'isobaric': [6, 12], 'y': [95, 96], 'x': [122, 123]}]
.squeeze().set_coords(['lat', 'lon'])['Temperature'])
.squeeze().drop_vars('Lambert_Conformal')
.set_coords(['lat', 'lon'])['Temperature'])


@pytest.fixture
Expand Down Expand Up @@ -676,11 +678,6 @@ def test_find_axis_number_bad_identifier(test_var):
assert 'axis is not valid' in str(exc.value)


def test_cf_parse_with_grid_mapping(test_var):
"""Test cf_parse dont delete grid_mapping attribute."""
assert test_var.grid_mapping == 'Lambert_Conformal'


def test_data_array_loc_get_with_units(test_var):
"""Test the .loc indexer on the metpy accessor."""
truth = test_var.loc[:, 850.]
Expand Down