Repository: mwaskom/seaborn

Issue:
Warning "passing `palette` without assigning `hue`"
**Context**
Seems related to https://github.com/mwaskom/seaborn/issues/2429, but [the associated gist](https://gist.github.com/mwaskom/9937c53eeb8b9794a450bf1f20b03e2f) didn't help.

I aim to produce a `barplot` with the color varying on the continuous y-axis. It works fine, except that I can't get rid of a new warning message:

```
Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.

  ax = sns.barplot(
/Users/vincentmaladiere/mambaforge/envs/skrub/lib/python3.10/site-packages/seaborn/_base.py:206: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if palette in QUAL_PALETTES:
```

I use the 0.13.0.dev0 version of seaborn on the following script:
```python
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns


x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
y = np.array([17583, 16411, 14014, 10706, 14455, 11458, 16209])

norm = plt.Normalize(y.min(), y.max())
cmap = plt.get_cmap("magma")

ax = sns.barplot(
    x=x,
    y=y,
    palette=cmap(norm(y)),
)
plt.xticks(rotation=30)
plt.ylabel(None)
plt.tight_layout()
```
With this output:
![Screen Shot 2023-08-27 at 10 08 47](https://github.com/mwaskom/seaborn/assets/18560386/152964de-ad2e-429a-9488-0ae46caefddb)

**Expected behavior**
No warning messages.

**Version**
Python 3.10.11
matplotlib 3.7.1
seaborn 0.13.0.dev0

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom) Report
> Merging [#3452](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom) (50c90f1) into [master](https://app.codecov.io/gh/mwaskom/seaborn/commit/07711372d1b7bdd2dd30a1546bbcd1de55232165?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom) (0771137) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452/graphs/tree.svg?width=650&height=150&src=pr&token=SLuzHnA9Bl&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom)](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom)

```diff
@@           Coverage Diff           @@
##           master    #3452   +/-   ##
=======================================
  Coverage   98.32%   98.32%           
=======================================
  Files          75       75           
  Lines       24361    24371   +10     
=======================================
+ Hits        23953    23963   +10     
  Misses        408      408           
```


| [Files Changed](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom) | Coverage Δ | |
|---|---|---|
| [seaborn/\_base.py](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom#diff-c2VhYm9ybi9fYmFzZS5weQ==) | `97.51% <100.00%> (+0.01%)` | :arrow_up: |
| [tests/test\_base.py](https://app.codecov.io/gh/mwaskom/seaborn/pull/3452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Michael+Waskom#diff-dGVzdHMvdGVzdF9iYXNlLnB5) | `99.70% <100.00%> (+<0.01%)` | :arrow_up: |

</details>

Patch:
diff --git a/seaborn/_base.py b/seaborn/_base.py
index 6a1c6083..f27f544d 100644
--- a/seaborn/_base.py
+++ b/seaborn/_base.py
@@ -108,6 +108,15 @@ class HueMapping(SemanticMapping):
 
         data = plotter.plot_data.get("hue", pd.Series(dtype=float))
 
+        if isinstance(palette, np.ndarray):
+            msg = (
+                "Numpy array is not a supported type for `palette`. "
+                "Please convert your palette to a list. "
+                "This will become an error in v0.14"
+            )
+            warnings.warn(msg, stacklevel=4)
+            palette = palette.tolist()
+
         if data.isna().all():
             if palette is not None:
                 msg = "Ignoring `palette` because no `hue` variable has been assigned."


Test patch:
diff --git a/tests/test_base.py b/tests/test_base.py
index d1b352d6..eea967cf 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -451,6 +451,14 @@ class TestSizeMapping:
         with pytest.raises(ValueError):
             SizeMapping(p, sizes="bad_size")
 
+    def test_array_palette_deprecation(self, long_df):
+
+        p = VectorPlotter(long_df, {"y": "y", "hue": "s"})
+        pal = mpl.cm.Blues([.3, .8])[:, :3]
+        with pytest.warns(UserWarning, match="Numpy array is not a supported type"):
+            m = HueMapping(p, pal)
+        assert m.palette == pal.tolist()
+
 
 class TestStyleMapping: