Skip to content

Commit a47ff4e

Browse files
Remove hue_style from plot1d docstring (#7925)
* 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>
1 parent 38e5a0c commit a47ff4e

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Breaking changes
2929

3030
Deprecations
3131
~~~~~~~~~~~~
32-
32+
- `hue_style` is being deprecated for scatter plots. (:issue:`7907`, :pull:`7925`).
33+
By `Jimmy Westling <https://github.com/illviljan>`_.
3334

3435
Bug fixes
3536
~~~~~~~~~
@@ -43,8 +44,6 @@ Internal Changes
4344
~~~~~~~~~~~~~~~~
4445

4546

46-
.. _whats-new.2023.07.0:
47-
4847
v2023.07.0 (July 11, 2023)
4948
--------------------------
5049

xarray/plot/dataarray_plot.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,6 @@ def _plot1d(plotfunc):
733733
If specified plot 3D and use this coordinate for *z* axis.
734734
hue : Hashable or None, optional
735735
Dimension or coordinate for which you want multiple lines plotted.
736-
hue_style: {'discrete', 'continuous'} or None, optional
737-
How to use the ``hue`` variable:
738-
739-
- ``'continuous'`` -- continuous color scale
740-
(default for numeric ``hue`` variables)
741-
- ``'discrete'`` -- a color for each unique value,
742-
using the default color cycle
743-
(default for non-numeric ``hue`` variables)
744-
745736
markersize: Hashable or None, optional
746737
scatter only. Variable by which to vary size of scattered points.
747738
linewidth: Hashable or None, optional
@@ -935,6 +926,19 @@ def newplotfunc(
935926
warnings.warn(msg, DeprecationWarning, stacklevel=2)
936927
del args
937928

929+
if hue_style is not None:
930+
# TODO: Not used since 2022.10. Deprecated since 2023.07.
931+
warnings.warn(
932+
(
933+
"hue_style is no longer used for plot1d plots "
934+
"and the argument will eventually be removed. "
935+
"Convert numbers to string for a discrete hue "
936+
"and use add_legend or add_colorbar to control which guide to display."
937+
),
938+
DeprecationWarning,
939+
stacklevel=2,
940+
)
941+
938942
_is_facetgrid = kwargs.pop("_is_facetgrid", False)
939943

940944
if plotfunc.__name__ == "scatter":

xarray/plot/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,16 @@ def data_is_numeric(self) -> bool:
14381438
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
14391439
>>> _Normalize(a).data_is_numeric
14401440
True
1441+
1442+
>>> # TODO: Datetime should be numeric right?
1443+
>>> a = xr.DataArray(pd.date_range("2000-1-1", periods=4))
1444+
>>> _Normalize(a).data_is_numeric
1445+
False
1446+
1447+
# TODO: Timedelta should be numeric right?
1448+
>>> a = xr.DataArray(pd.timedelta_range("-1D", periods=4, freq="D"))
1449+
>>> _Normalize(a).data_is_numeric
1450+
True
14411451
"""
14421452
return self._data_is_numeric
14431453

xarray/tests/test_plot.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,23 +2708,32 @@ def test_bad_args(
27082708
x=x, y=y, hue=hue, add_legend=add_legend, add_colorbar=add_colorbar
27092709
)
27102710

2711-
@pytest.mark.xfail(reason="datetime,timedelta hue variable not supported.")
2712-
@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
2713-
def test_datetime_hue(self, hue_style: Literal["discrete", "continuous"]) -> None:
2711+
def test_datetime_hue(self) -> None:
27142712
ds2 = self.ds.copy()
2713+
2714+
# TODO: Currently plots as categorical, should it behave as numerical?
27152715
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
2716-
ds2.plot.scatter(x="A", y="B", hue="hue", hue_style=hue_style)
2716+
ds2.plot.scatter(x="A", y="B", hue="hue")
27172717

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

2721-
@pytest.mark.parametrize("hue_style", ["discrete", "continuous"])
2722-
def test_facetgrid_hue_style(
2723-
self, hue_style: Literal["discrete", "continuous"]
2724-
) -> None:
2725-
g = self.ds.plot.scatter(
2726-
x="A", y="B", row="row", col="col", hue="hue", hue_style=hue_style
2727-
)
2721+
def test_facetgrid_hue_style(self) -> None:
2722+
ds2 = self.ds.copy()
2723+
2724+
# Numbers plots as continous:
2725+
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
2726+
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)
2727+
2728+
# Datetimes plots as categorical:
2729+
# TODO: Currently plots as categorical, should it behave as numerical?
2730+
ds2["hue"] = pd.date_range("2000-1-1", periods=4)
2731+
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
2732+
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)
2733+
2734+
# Strings plots as categorical:
2735+
ds2["hue"] = ["a", "a", "b", "b"]
2736+
g = ds2.plot.scatter(x="A", y="B", row="row", col="col", hue="hue")
27282737
assert isinstance(g._mappables[-1], mpl.collections.PathCollection)
27292738

27302739
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)