From f94ca9814ad73b8f112be4f8a011a4f998c9d897 Mon Sep 17 00:00:00 2001 From: kinyatoride Date: Fri, 1 May 2026 15:13:01 -0600 Subject: [PATCH 1/2] Fix bar tick labels for xarray DataArray with string coordinate Iterating a 1-D xarray.DataArray yields scalar DataArrays whose str() returns the multi-line repr, which leaked into x-tick labels for ax.bar(da) when the coordinate was string-valued. Unwrap to a numpy array via _to_numpy_array before stringifying in _meta_coords. Adds a regression test in test_inputs_helpers.py. --- ultraplot/internals/inputs.py | 2 +- ultraplot/tests/test_inputs_helpers.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ultraplot/internals/inputs.py b/ultraplot/internals/inputs.py index 0f8ac4e46..14438c686 100644 --- a/ultraplot/internals/inputs.py +++ b/ultraplot/internals/inputs.py @@ -686,7 +686,7 @@ def _meta_coords(*args, which="x", **kwargs): if data.ndim > 1: raise ValueError("Non-1D string coordinate input is unsupported.") ticks = np.arange(len(data)) - labels = list(map(str, data)) + labels = list(map(str, _to_numpy_array(data))) kwargs.setdefault(which + "locator", Locator(ticks)) kwargs.setdefault(which + "formatter", Formatter(labels, index=True)) kwargs.setdefault(which + "minorlocator", Locator("null")) diff --git a/ultraplot/tests/test_inputs_helpers.py b/ultraplot/tests/test_inputs_helpers.py index 2288e07a0..299275672 100644 --- a/ultraplot/tests/test_inputs_helpers.py +++ b/ultraplot/tests/test_inputs_helpers.py @@ -169,6 +169,28 @@ def test_mask_range_and_metadata_helpers(): assert inputs._meta_units(np.array([1, 2, 3])) is None +def test_meta_coords_xarray_string_coord(): + """ + Regression test: passing an xarray.DataArray with a string coordinate + to _meta_coords must yield plain string tick labels, not the multi-line + repr of each scalar DataArray element. + """ + xr = pytest.importorskip("xarray") + + da = xr.DataArray( + np.array(["a", "b", "c"]), + coords={"ens": ["a", "b", "c"]}, + dims=["ens"], + name="ens", + ) + + coords, kwargs = inputs._meta_coords(da, which="x") + + assert np.array_equal(coords, np.array([0, 1, 2])) + formatter = kwargs["xformatter"] + assert [formatter(i) for i in coords] == ["a", "b", "c"] + + def test_geographic_helpers_cover_clipping_bounds_and_globes(): clipped = inputs._geo_clip(np.array([-100.0, 0.0, 100.0])) assert np.allclose(clipped, [-90.0, 0.0, 90.0]) From 9fd61d722f8cfd1885bc6ee5a35670c4471ce56d Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Sat, 2 May 2026 08:57:50 +1000 Subject: [PATCH 2/2] Stop pinning the release metadata test to a specific softprops/action-gh-release major version so the workflow check keeps passing when the action is upgraded. This keeps the assertion focused on the presence of the GitHub release step now that the workflow references v3. --- ultraplot/tests/test_release_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/tests/test_release_metadata.py b/ultraplot/tests/test_release_metadata.py index 94c631a29..f5af944c2 100644 --- a/ultraplot/tests/test_release_metadata.py +++ b/ultraplot/tests/test_release_metadata.py @@ -140,4 +140,4 @@ def test_publish_workflow_creates_github_release(): assert "tools/release/sync_citation.py" in text assert "--tag" in text assert "--output" in text - assert "softprops/action-gh-release@v2" in text + assert "softprops/action-gh-release@" in text