Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the error message for invalid hue names #5060

Merged
merged 4 commits into from
Mar 30, 2021
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: 2 additions & 0 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def _infer_line_data(darray, x, y, hue):
raise ValueError("For 2D inputs, please specify either hue, x or y.")

if y is None:
if hue is not None:
_assert_valid_xy(darray, hue, "hue")
xname, huename = _infer_xy_labels(darray=darray, x=x, y=hue)
xplt = darray[xname]
if xplt.ndim > 1:
Expand Down
9 changes: 9 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ def test_line_plot_along_1d_coord(self):
line = da.plot(y="time", hue="x")[0]
assert_array_equal(line.get_ydata(), da.coords["time"].values)

def test_line_plot_wrong_hue(self):
da = xr.DataArray(
data=np.array([[0, 1], [5, 9]]),
dims=["x", "t"],
)

with pytest.raises(ValueError, match="hue must be one of"):
da.plot(x="t", hue="wrong_coord")

def test_2d_line(self):
with raises_regex(ValueError, "hue"):
self.darray[:, :, 0].plot.line()
Expand Down