diff --git a/holoviews/core/util.py b/holoviews/core/util.py index dadba0c088..4b91e612b6 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -2031,7 +2031,9 @@ def is_nan(x): Checks whether value is NaN on arbitrary types """ try: - return np.isnan(x) + # 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 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 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