From aa93aba208f6d3bd7d21978d1cfd17822d5ae77f Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Fri, 29 Jan 2021 14:49:41 +0000 Subject: [PATCH] add support for drop_dims (#146) --- cf_xarray/accessor.py | 1 + cf_xarray/tests/test_accessor.py | 8 ++++++++ doc/whats-new.rst | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cf_xarray/accessor.py b/cf_xarray/accessor.py index d173ebd7..20ec811b 100644 --- a/cf_xarray/accessor.py +++ b/cf_xarray/accessor.py @@ -372,6 +372,7 @@ def _get_with_standard_name( _DEFAULT_KEY_MAPPERS: Mapping[str, Tuple[Mapper, ...]] = { "dim": (_get_axis_coord,), "dims": (_get_axis_coord,), # transpose + "drop_dims": (_get_axis_coord,), # drop_dims "dimensions": (_get_axis_coord,), # stack "dims_dict": (_get_axis_coord,), # swap_dims, rename_dims "shifts": (_get_axis_coord,), # shift, roll diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index dc966825..26099fdf 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -708,3 +708,11 @@ def test_drop_sel_and_reset_coords(obj): assert_identical( obj.reset_coords("air"), obj.cf.reset_coords("air_temperature") ) + + +@pytest.mark.parametrize("ds", datasets) +def test_drop_dims(ds): + + # Axis and coordinate + for cf_name in ["X", "longitude"]: + assert_identical(ds.drop_dims("lon"), ds.cf.drop_dims(cf_name)) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 25ee2264..998e1ec0 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -6,7 +6,7 @@ What's New v0.4.1 (unreleased) =================== -- Support for ``.drop()``, ``.drop_vars()``, ``.drop_sel()``, ``.set_coords()``, ``.reset_coords()``. By `Mattia Almansi`_. +- Support for ``.drop()``, ``.drop_vars()``, ``.drop_sel()``, ``.drop_dims()``, ``.set_coords()``, ``.reset_coords()``. By `Mattia Almansi`_. - Support for using ``standard_name`` in more functions. (:pr:`128`) By `Deepak Cherian`_ - Allow ``DataArray.cf[]`` with standard names. By `Deepak Cherian`_ - Rewrite the ``values`` of ``.cf.coords`` and ``.cf.data_vars`` with objects returned