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

Spans and Lines don’t support half-open hard ranges #6289

Closed
alcrene opened this issue Jun 19, 2024 · 1 comment · Fixed by #6290
Closed

Spans and Lines don’t support half-open hard ranges #6289

alcrene opened this issue Jun 19, 2024 · 1 comment · Fixed by #6290
Labels
type: bug Something isn't correct or isn't working

Comments

@alcrene
Copy link

alcrene commented Jun 19, 2024

ALL software version info

HoloViews: 1.18.1
Pandas: 2.1.4
NumPy: 1.26.3
Bokeh: 3.3.3
Matplotlib: 3.8.2
Python: 3.10.12

Description of error

The *Spans and *Lines annotations don’t support hard ranges unless both ends are specified.
Singular versions (*Span and *Line) are fine.

The issue seems due to converting extents to a Pandas array:

def get_extents(self, element, ranges=None, range_type='combined', **kwargs):
extents = super().get_extents(element, ranges, range_type)
if isinstance(element, HLines):
extents = np.nan, extents[0], np.nan, extents[2]
elif isinstance(element, VLines):
extents = extents[0], np.nan, extents[2], np.nan
elif isinstance(element, HSpans):
extents = pd.array(extents)
extents = np.nan, extents[:2].min(), np.nan, extents[2:].max()
elif isinstance(element, VSpans):
extents = pd.array(extents)
extents = extents[:2].min(), np.nan, extents[2:].max(), np.nan
return extents

which converts nan to pandas.NA. Then these lines filter out NaNs, but not NAs:
lower = [v for v in arr[lidx] if v is not None and not is_nan(v)]
upper = [v for v in arr[uidx] if v is not None and not is_nan(v)]

A search for pd.array(extents) shows this is done in both the Bokeh and Matplotlib renderers.
I also tested that the error occurs with both. I did not test Plotly.

Complete, minimal, self-contained example code that reproduces the issue

The following will raise the exception printed above

import holoviews as hv
hv.extension("bokeh")

dim_prob = 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_prob) \
      * hv.HSpans([(0, .2), (0.4, 0.6)], kdims=["x", dim_prob])
display(fig)   # Error occurs when the figure is displayed

With any of the following changes, the example does work:

  • range=(0, 1) instead of range=(0, None)
  • soft_range=(0, None) instead of range=(0, None)
  • HSpan instead of HSpans

Possible workaround

Use soft_range for half-open ranges.

Stack traceback and/or browser JavaScript console output

Last bit of traceback:

...
File [~/usr/venv/comp/lib/python3.10/site-packages/holoviews/plotting/plot.py:1988](http://localhost:33091/home/rene/usr/venv/comp/lib/python3.10/site-packages/holoviews/plotting/plot.py#line=1987), in GenericOverlayPlot.get_extents(self, overlay, ranges, range_type, dimension, **kwargs)
   1986 subplot_extents = self._get_subplot_extents(overlay, ranges, range_type, dimension)
   1987 zrange = isinstance(self.projection, str) and self.projection == '3d'
-> 1988 extents = {k: util.max_extents(rs, zrange) for k, rs in subplot_extents.items()}
   1989 if range_type != 'combined':
   1990     return extents[range_type]

File [~/usr/venv/comp/lib/python3.10/site-packages/holoviews/plotting/plot.py:1988](http://localhost:33091/home/rene/usr/venv/comp/lib/python3.10/site-packages/holoviews/plotting/plot.py#line=1987), in <dictcomp>(.0)
   1986 subplot_extents = self._get_subplot_extents(overlay, ranges, range_type, dimension)
   1987 zrange = isinstance(self.projection, str) and self.projection == '3d'
-> 1988 extents = {k: util.max_extents(rs, zrange) for k, rs in subplot_extents.items()}
   1989 if range_type != 'combined':
   1990     return extents[range_type]

File [~/usr/venv/comp/lib/python3.10/site-packages/holoviews/core/util.py:1121](http://localhost:33091/home/rene/usr/venv/comp/lib/python3.10/site-packages/holoviews/core/util.py#line=1120), in max_extents(extents, zrange)
   1119 for lidx, uidx in inds:
   1120     lower = [v for v in arr[lidx] if v is not None and not is_nan(v)]
-> 1121     upper = [v for v in arr[uidx] if v is not None and not is_nan(v)]
   1122     if lower and isinstance(lower[0], datetime_types):
   1123         extents[lidx] = np.min(lower)

File [~/usr/venv/comp/lib/python3.10/site-packages/holoviews/core/util.py:1121](http://localhost:33091/home/rene/usr/venv/comp/lib/python3.10/site-packages/holoviews/core/util.py#line=1120), in <listcomp>(.0)
   1119 for lidx, uidx in inds:
   1120     lower = [v for v in arr[lidx] if v is not None and not is_nan(v)]
-> 1121     upper = [v for v in arr[uidx] if v is not None and not is_nan(v)]
   1122     if lower and isinstance(lower[0], datetime_types):
   1123         extents[lidx] = np.min(lower)

File missing.pyx:419, in pandas._libs.missing.NAType.__bool__()

TypeError: boolean value of NA is ambiguous
@hoxbro hoxbro added the type: bug Something isn't correct or isn't working label Jun 20, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants