From 9506e166052e6dc310af6bdfe1f684392287304d Mon Sep 17 00:00:00 2001 From: Rich Signell Date: Mon, 23 Nov 2026 06:54:31 -0500 Subject: [PATCH] Fix wrapped methods with a single positional argument _rewrite_values returns a bare name when a key maps to one name, and _process_signature extended the positional args with it, unpacking the string into characters. cf.transpose('Y') on a 1-D array therefore raised "Dimensions {'o', 't', ...} do not exist". Closes #696 Co-Authored-By: Claude Sonnet 5.5 --- cf_xarray/accessor.py | 5 +++-- cf_xarray/tests/test_accessor.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cf_xarray/accessor.py b/cf_xarray/accessor.py index 5497cbd7..c6ced198 100644 --- a/cf_xarray/accessor.py +++ b/cf_xarray/accessor.py @@ -1851,8 +1851,9 @@ def _process_signature( for arg in var_args: value = arguments.pop(arg, None) if value: - # value should always be Iterable - posargs.extend(value) + # _rewrite_values returns a bare name (not a list) when there is only one, + # which extend would unpack into characters + posargs.extend(always_iterable(value)) # now unwrap the **kwargs type arguments for kw in var_kws: value = arguments.pop(kw, None) diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index 1214546d..372a9a97 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -566,6 +566,14 @@ def test_pos_args_methods() -> None: assert_identical(actual, expected) +@pytest.mark.parametrize("key", ["lon", "longitude", "X"]) +def test_pos_args_methods_single_argument(key) -> None: + # a single positional key used to be unpacked into its characters + da = airds.air.isel(time=0, lat=0) + assert da.dims == ("lon",) + assert_identical(da.cf.transpose(key), da) + + def test_preserve_unused_keys() -> None: ds = airds.copy(deep=False) ds.time.attrs.clear()