Skip to content
forked from pydata/xarray

Commit

Permalink
Remove hue_style from plot1d docstring (pydata#7925)
Browse files Browse the repository at this point in the history
* Remove hue_style from plot1d docstring

* Add deprecation warning

* Remove  hue_style in scatter tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* hmm timedelta is numeric?

* Update utils.py

* Update test_plot.py

* Update whats-new.rst

* fix merge errors

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Illviljan and pre-commit-ci[bot] authored Jul 13, 2023
1 parent 38e5a0c commit a47ff4e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
5 changes: 2 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Breaking changes

Deprecations
~~~~~~~~~~~~

- `hue_style` is being deprecated for scatter plots. (:issue:`7907`, :pull:`7925`).
By `Jimmy Westling <https://github.com/illviljan>`_.

Bug fixes
~~~~~~~~~
Expand All @@ -43,8 +44,6 @@ Internal Changes
~~~~~~~~~~~~~~~~


.. _whats-new.2023.07.0:

v2023.07.0 (July 11, 2023)
--------------------------

Expand Down
22 changes: 13 additions & 9 deletions xarray/plot/dataarray_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,6 @@ def _plot1d(plotfunc):
If specified plot 3D and use this coordinate for *z* axis.
hue : Hashable or None, optional
Dimension or coordinate for which you want multiple lines plotted.
hue_style: {'discrete', 'continuous'} or None, optional
How to use the ``hue`` variable:
- ``'continuous'`` -- continuous color scale
(default for numeric ``hue`` variables)
- ``'discrete'`` -- a color for each unique value,
using the default color cycle
(default for non-numeric ``hue`` variables)
markersize: Hashable or None, optional
scatter only. Variable by which to vary size of scattered points.
linewidth: Hashable or None, optional
Expand Down Expand Up @@ -935,6 +926,19 @@ def newplotfunc(
warnings.warn(msg, DeprecationWarning, stacklevel=2)
del args

if hue_style is not None:
# TODO: Not used since 2022.10. Deprecated since 2023.07.
warnings.warn(
(
"hue_style is no longer used for plot1d plots "
"and the argument will eventually be removed. "
"Convert numbers to string for a discrete hue "
"and use add_legend or add_colorbar to control which guide to display."
),
DeprecationWarning,
stacklevel=2,
)

_is_facetgrid = kwargs.pop("_is_facetgrid", False)

if plotfunc.__name__ == "scatter":
Expand Down
10 changes: 10 additions & 0 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,16 @@ def data_is_numeric(self) -> bool:
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
>>> _Normalize(a).data_is_numeric
True
>>> # TODO: Datetime should be numeric right?
>>> a = xr.DataArray(pd.date_range("2000-1-1", periods=4))
>>> _Normalize(a).data_is_numeric
False
# TODO: Timedelta should be numeric right?
>>> a = xr.DataArray(pd.timedelta_range("-1D", periods=4, freq="D"))
>>> _Normalize(a).data_is_numeric
True
"""
return self._data_is_numeric

Expand Down
33 changes: 21 additions & 12 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2708,23 +2708,32 @@ def test_bad_args(
x=x, y=y, hue=hue, add_legend=add_legend, add_colorbar=add_colorbar
)

@pytest.mark.xfail(reason="datetime,timedelta hue variable not supported.")
@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
def test_datetime_hue(self, hue_style: Literal["discrete", "continuous"]) -> None:
def test_datetime_hue(self) -> None:
ds2 = self.ds.copy()

# TODO: Currently plots as categorical, should it behave as numerical?
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
ds2.plot.scatter(x="A", y="B", hue="hue", hue_style=hue_style)
ds2.plot.scatter(x="A", y="B", hue="hue")

ds2["hue"] = pd.timedelta_range("-1D", periods=4, freq="D")
ds2.plot.scatter(x="A", y="B", hue="hue", hue_style=hue_style)
ds2.plot.scatter(x="A", y="B", hue="hue")

@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
def test_facetgrid_hue_style(
self, hue_style: Literal["discrete", "continuous"]
) -> None:
g = self.ds.plot.scatter(
x="A", y="B", row="row", col="col", hue="hue", hue_style=hue_style
)
def test_facetgrid_hue_style(self) -> None:
ds2 = self.ds.copy()

# Numbers plots as continous:
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

# Datetimes plots as categorical:
# TODO: Currently plots as categorical, should it behave as numerical?
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

# Strings plots as categorical:
ds2["hue"] = ["a", "a", "b", "b"]
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)

@pytest.mark.parametrize(
Expand Down

0 comments on commit a47ff4e

Please sign in to comment.