From 029814bd0621c4006e369f8e13f8383afef687b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Wed, 19 Jun 2024 16:44:09 +0200 Subject: [PATCH 1/3] Also check for pd.NA in is_nan --- holoviews/core/util.py | 2 +- .../tests/plotting/bokeh/test_annotationplot.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/holoviews/core/util.py b/holoviews/core/util.py index dadba0c088..bd08ba02a1 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -2031,7 +2031,7 @@ def is_nan(x): Checks whether value is NaN on arbitrary types """ try: - return np.isnan(x) + return bool(pd.isna(x)) except Exception: return False diff --git a/holoviews/tests/plotting/bokeh/test_annotationplot.py b/holoviews/tests/plotting/bokeh/test_annotationplot.py index 4a60a3e823..4520435b2b 100644 --- a/holoviews/tests/plotting/bokeh/test_annotationplot.py +++ b/holoviews/tests/plotting/bokeh/test_annotationplot.py @@ -621,3 +621,15 @@ def test_dynamicmap_overlay_hspans(self): assert plot_el.handles["x_range"].end == plot_dmap.handles["x_range"].end assert plot_el.handles["y_range"].start == plot_dmap.handles["y_range"].start assert plot_el.handles["y_range"].end == plot_dmap.handles["y_range"].end + + def test_hspans_no_upper_range(self): + # Test for: https://github.com/holoviz/holoviews/issues/6289 + + dim = hv.Dimension("p", label="prob", range=(0, None)) + fig = hv.Curve( + [(0, 0.6), (1, 0.3), (2, 0.4), (3, 0.45)], kdims="x", vdims=dim + ) + spans = hv.HSpans([(0, 0.2), (0.4, 0.6)], kdims=["x", dim]) + plot_el = bokeh_renderer.get_plot(spans * fig) + assert plot_el.handles["x_range"].start == 0 + assert plot_el.handles["x_range"].end == 3 From 34fd6591fc041d5aa23d9de8f970f8939187418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 4 Jul 2024 12:28:19 +0200 Subject: [PATCH 2/3] add test for is_nan so it always return a boolean --- holoviews/tests/core/test_utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/holoviews/tests/core/test_utils.py b/holoviews/tests/core/test_utils.py index 560f11245c..41462601d7 100644 --- a/holoviews/tests/core/test_utils.py +++ b/holoviews/tests/core/test_utils.py @@ -21,6 +21,7 @@ dt_to_int, find_range, get_path, + is_nan, isfinite, make_path_unique, max_range, @@ -806,3 +807,13 @@ def test_unique_array_categorial(): ser = pd.Series(np.random.choice(["a", "b", "c"], 100)).astype("category") res = unique_array([ser]) assert sorted(res) == ["a", "b", "c"] + + +def test_is_nan(): + assert is_nan(np.nan) == True + assert is_nan(None) == True + assert is_nan(pd.NA) == True + assert is_nan(pd.NaT) == True + assert is_nan([1, 1]) == False + assert is_nan([np.nan]) == True + assert is_nan([np.nan, np.nan]) == False From f27b8f66db37469ef944d47682e51b404fbfce75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 4 Jul 2024 13:37:17 +0200 Subject: [PATCH 3/3] Update holoviews/core/util.py Co-authored-by: Maxime Liquet <35924738+maximlt@users.noreply.github.com> --- holoviews/core/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/holoviews/core/util.py b/holoviews/core/util.py index bd08ba02a1..4b91e612b6 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -2031,6 +2031,8 @@ def is_nan(x): Checks whether value is NaN on arbitrary types """ try: + # Using pd.isna instead of np.isnan as np.isnan(pd.NA) returns pd.NA! + # Call bool() to raise an error if x is pd.NA, an array, etc. return bool(pd.isna(x)) except Exception: return False