From 72710354ecc8470683e15f452ba0af841464e84a Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Tue, 27 Dec 2022 20:27:41 -0500 Subject: [PATCH] Avoid exception from Continuous scale for normed property (#3190) --- doc/whatsnew/v0.12.2.rst | 2 ++ seaborn/_core/scales.py | 2 +- tests/_core/test_scales.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/whatsnew/v0.12.2.rst b/doc/whatsnew/v0.12.2.rst index 927c4fa0a2..423cc58e5c 100644 --- a/doc/whatsnew/v0.12.2.rst +++ b/doc/whatsnew/v0.12.2.rst @@ -14,6 +14,8 @@ v0.12.2 (Unreleased) - |Fix| Fixed a regression in v0.12.0 where manually-added labels could have duplicate legend entries (:pr:`3116`). +- |Fix| Normed properties using a :class:`objects.Continuous` scale no longer raise on boolean data (:pr:`3189`). + - |Fix| Fixed a bug in :func:`histplot` with `kde=True` and `log_scale=True` where the curve was not scaled properly (:pr:`3173`). - |Fix| Fixed a bug in :func:`relplot` where inner axis labels would be shown when axis sharing was disabled (:pr:`3180`). diff --git a/seaborn/_core/scales.py b/seaborn/_core/scales.py index 6c9ecbc902..3c215a60d8 100644 --- a/seaborn/_core/scales.py +++ b/seaborn/_core/scales.py @@ -346,7 +346,7 @@ def _setup( vmin, vmax = data.min(), data.max() else: vmin, vmax = new.norm - vmin, vmax = axis.convert_units((vmin, vmax)) + vmin, vmax = map(float, axis.convert_units((vmin, vmax))) a = forward(vmin) b = forward(vmax) - forward(vmin) diff --git a/tests/_core/test_scales.py b/tests/_core/test_scales.py index 2d967cc217..ac77098c64 100644 --- a/tests/_core/test_scales.py +++ b/tests/_core/test_scales.py @@ -90,6 +90,12 @@ def test_interval_with_range_norm_and_transform(self, x): s = Continuous((2, 3), (10, 100), "log")._setup(x, IntervalProperty()) assert_array_equal(s(x), [1, 2, 3]) + def test_interval_with_bools(self): + + x = pd.Series([True, False, False]) + s = Continuous()._setup(x, IntervalProperty()) + assert_array_equal(s(x), [1, 0, 0]) + def test_color_defaults(self, x): cmap = color_palette("ch:", as_cmap=True)