Fix bar tick labels for xarray DataArray with string coordinate#711
Merged
cvanelteren merged 3 commits intoUltraplot:mainfrom May 2, 2026
Merged
Conversation
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.
Collaborator
|
I will fix the zenodo stuff; it's not related to this PR |
…-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.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Collaborator
|
Error will fix itself. Thanks @kinyatoride |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ax.bar(da)on a 1-Dxarray.DataArraywith a string coordinate renders the full multi-linexarrayrepr as each x-tick label instead of the underlying string values.Reproducer
Before: each tick label is
"<xarray.DataArray 'ens' ()> Size: 4B\narray('A', dtype='<U1')\nCoordinates:\n ens <U1 4B 'A'"(and similarly for'B','C').After:
['A', 'B', 'C'].Cause
In
ultraplot/internals/inputs.py::_meta_coords,labels = list(map(str, data))did not unwrap thexarray.DataArrayfirst._parse_1d_formatpasses the coordinate through as aDataArray(not a numpy array); iterating a 1-DDataArrayyields scalarDataArrays whosestr()is the multi-line repr.Fix
Wrap
datawith_to_numpy_array(already defined in the same file) before stringifying, so iteration yields the raw element values for bothxarray.DataArrayandpandasinputs.Test
Added
test_meta_coords_xarray_string_coordinultraplot/tests/test_inputs_helpers.py(skipped ifxarrayis not installed).Confirmed broken on
2.2.0; fix verified locally withpytest ultraplot/tests/test_inputs_helpers.pyand an end-to-endax.bar(xr.DataArray)smoke check.