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 xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def format_item(x, timedelta_format=None, quote_strings=True):
if hasattr(x, "dtype"):
x = x.item()
return repr(x) if quote_strings else x
elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating):
elif hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating) and x.shape == ():
return f"{x.item():.4}"
else:
return str(x)
Expand Down
3 changes: 3 additions & 0 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def test_format_item(self) -> None:
(np.float16(1.1234), "1.123"),
(np.float32(1.0111111), "1.011"),
(np.float64(22.222222), "22.22"),
(np.zeros((1, 1)), "[[0.]]"),
(np.zeros(2), "[0. 0.]"),
(np.zeros((2, 2)), "[[0. 0.]\n [0. 0.]]"),
]
for item, expected in cases:
actual = formatting.format_item(item)
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def test_slice_in_title_single_item_array(self) -> None:
darray = self.darray.expand_dims({"d": np.array([10.009])})
darray.plot.line(x="period")
title = plt.gca().get_title()
assert "d = 10.01" == title
assert "d = [10.009]" == title


class TestPlotStep(PlotTestCase):
Expand Down
Loading