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
2 changes: 1 addition & 1 deletion ultraplot/internals/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
22 changes: 22 additions & 0 deletions ultraplot/tests/test_inputs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion ultraplot/tests/test_release_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading