Skip to content

Commit

Permalink
Avoid setting 1D x,y where that dimension clashes with hue. (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jan 22, 2022
1 parent e240e51 commit fd819a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,15 @@ def _get_possible(accessor, criteria):
elif ax_coord_name:
values = [v for v in values if v in ax_coord_name]

values = [v for v in values if v != skip]
if skip is not None:
skipvar = obj.cf[skip]
bad_names = (skip, skipvar.name)
bad_dims = ((skip,), skipvar.dims)
values = [
v
for v in values
if v not in bad_names and obj[v].dims not in bad_dims
]
if len(values) == 1 and not is_scalar(accessor._obj[values[0]]):
return values[0]
else:
Expand Down
8 changes: 8 additions & 0 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,14 @@ def makeds(*dims):
assert _possible_x_y_plot(xtds, "y") is None
assert _possible_x_y_plot(xtds, "x") == "X"

xtds.coords["lon"] = ("X", [1, 2, 3], {"standard_name": "longitude"})
# skip lon (which is 1D on X) if user passes hue="X"
# choose T instead which is a different dimension
# (and so a more meaningful plot)
assert _possible_x_y_plot(xtds, "x", skip="X") == "T"
# now with hue="lon", skip "X"
assert _possible_x_y_plot(xtds, "x", skip="lon") == "T"


def test_groupby_special_ops():
cfgrouped = airds.cf.groupby_bins("latitude", np.arange(20, 50, 10))
Expand Down

0 comments on commit fd819a9

Please sign in to comment.