Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also check for pd.NA in is_nan #6290

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
return False

Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
dt_to_int,
find_range,
get_path,
is_nan,
isfinite,
make_path_unique,
max_range,
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions holoviews/tests/plotting/bokeh/test_annotationplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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