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

Datashader (rasterize) breaks plotting vector data. ValueError: Geometry type combination is not supported ([]) #6453

Open
1 task
FlorisCalkoen opened this issue Nov 15, 2024 · 3 comments
Labels
type: bug Something isn't correct or isn't working

Comments

@FlorisCalkoen
Copy link

FlorisCalkoen commented Nov 15, 2024

ALL software version info

import holoviews as hv
hv.show_versions()
Python : 3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 15:57:01) [Clang 17.0.6 ]
Operating system : macOS-14.6.1-arm64-arm-64bit
Panel comms : default

holoviews : 1.20.0

bokeh : 3.5.2
colorcet : 3.1.0
cudf : -
cupy : -
dask : 2024.11.2
dask-expr : 1.1.19
datashader : 0.16.3
geoviews : 1.13.0
hvplot : 0.11.1
ibis-framework : -
IPython : 8.17.2
ipywidgets-bokeh : -
jupyter-bokeh : 4.0.5
jupyterlab : 4.3.0
matplotlib : 3.9.2
networkx : 3.4.2
notebook : 6.5.4
numba : 0.60.0
numpy : 2.0.2
pandas : 2.2.3
panel : 1.5.4
param : 2.1.1
pillow : 11.0.0
plotly : -
pyarrow : 17.0.0
pyviz-comms : 3.0.3
scikit-image : 0.24.0
scipy : 1.14.1
spatialpandas : 0.4.10
streamz : -
tsdownsample : -
xarray : 2024.10.0

Description of expected behavior and the observed behavior

Zoom breaks visualization when vector data (geometries) have been rasterized. This shows up while using the holoviews.operations.datashade.datashader as well as when using the hvplot extension with rasterize=True. The plot is made and rendered in a panel, but then when you zoom in a map you get this error.

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

linestrings = [
    "LINESTRING (-121.97625624848078 36.96474939629007, -121.96688469179223 36.948366095134865)",
    "LINESTRING (-121.97664230038448 36.96460468814935, -121.96855460367323 36.94778657367965)",
    "LINESTRING (-121.97645658443105 36.9646156205337, -121.97084873679243 36.94715929907674)",
    "LINESTRING (-122.03956614150331 36.96045115224142, -122.036952745531 36.94254620927747)",
]
gdf = gpd.GeoSeries.from_wkt(linestrings, crs=4326).to_frame("geometry")

# works as expected
pn.Column(gdf.hvplot(geo=True)).show()

# doesn't work. It renders, but then when you zoom things are broken.
pn.Column(gdf.hvplot(geo=True, rasterize=True)).show()

Working version

With this version it is working as expected:

>>> hv.show_versions()
Python              :  3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:13:44) [Clang 16.0.6 ]
Operating system    :  macOS-14.6.1-arm64-arm-64bit
Panel comms         :  default

holoviews           :  1.19.1

bokeh               :  3.4.2
colorcet            :  3.1.0
cudf                :  -
cupy                :  -
dask                :  2024.7.0
dask-expr           :  1.1.7
datashader          :  0.16.3
geoviews            :  1.12.0
hvplot              :  0.10.0
ibis-framework      :  -
IPython             :  8.26.0
ipywidgets-bokeh    :  -
jupyter-bokeh       :  4.0.5
jupyterlab          :  4.2.3
matplotlib          :  3.8.4
networkx            :  3.3
notebook            :  7.2.1
numba               :  0.60.0
numpy               :  1.26.4
pandas              :  2.2.2
panel               :  1.4.4
param               :  2.1.1
pillow              :  10.4.0
plotly              :  -
pyarrow             :  16.1.0
pyviz-comms         :  3.0.2
scikit-image        :  0.24.0
scipy               :  1.14.0
spatialpandas       :  0.4.10
streamz             :  -
tsdownsample        :  -
xarray              :  2024.6.0
>>>

Stack traceback and/or browser JavaScript console output

Although I'm not sure if its related, on a bigger plot example (not super big, like 20k building footprints that usually works fine) I got this traceback. I checked the geometries and they are all valid without any nulls etc.

overture.to_crs(4326).hvplot(
    geo=True,
    rasterize=True,
    cmap=cc.fire,
    colorbar=True,
    clabel="Building Density",
)


File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/plotting/util.py", line 300, in get_plot_frame
    return map_obj[key]
           ~~~~~~~^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 280, in dynamic_mul
    element = self[args]
              ~~~~^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 552, in __call__
    return self.callable()
           ^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/overlay.py", line 34, in dynamic_mul
    element = other[args]
              ~~~~~^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 581, in __call__
    ret = self.callable(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1038, in dynamic_operation
    key, obj = resolve(key, kwargs)
               ^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1027, in resolve
    return key, map_obj[key]
                ~~~~~~~^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 1216, in __getitem__
    val = self._execute_callback(*tuple_key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 983, in _execute_callback
    retval = self.callback(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/spaces.py", line 581, in __call__
    ret = self.callable(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1039, in dynamic_operation
    return apply(obj, *key, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1031, in apply
    processed = self._process(element, key, kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/util/__init__.py", line 1013, in _process
    return self.p.operation.process_element(element, key, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/operation.py", line 194, in process_element
    return self._apply(element, key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/operation.py", line 141, in _apply
    ret = self._process(element, key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/operation/datashader.py", line 1546, in _process
    element = element.map(op, predicate)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/data/__init__.py", line 196, in pipelined_fn
    result = method_fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/data/__init__.py", line 1213, in map
    return super().map(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/dimension.py", line 695, in map
    return map_fn(self) if applies else self
           ^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/operation.py", line 214, in __call__
    return self._apply(element)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/core/operation.py", line 141, in _apply
    ret = self._process(element, key)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/holoviews/operation/datashader.py", line 1431, in _process
    agg = cvs.polygons(data, **agg_kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/core.py", line 784, in polygons
    return bypixel(source, self, glyph, agg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/core.py", line 1340, in bypixel
    return bypixel.pipeline(source, schema, canvas, glyph, agg, antialias=antialias)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/utils.py", line 117, in __call__
    return lk[cls](head, *rest, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/data_libraries/pandas.py", line 17, in pandas_pipeline
    return glyph_dispatch(glyph, df, schema, canvas, summary, antialias=antialias)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/utils.py", line 117, in __call__
    return lk[cls](head, *rest, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/data_libraries/pandas.py", line 59, in default
    extend(bases, source, x_st + y_st, x_range + y_range)
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/glyphs/polygon.py", line 40, in extend
    perform_extend_cpu(
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/datashader/glyphs/polygon.py", line 249, in extend_cpu
    ragged = shapely.to_ragged_array(geometry)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calkoen/mambaforge/envs/coastal-full/lib/python3.12/site-packages/shapely/_ragged_array.py", line 292, in to_ragged_array
    raise ValueError(
ValueError: Geometry type combination is not supported ([])

Screenshots or screencasts of the bug in action

  • I may be interested in making a pull request to address this
@FlorisCalkoen
Copy link
Author

FlorisCalkoen commented Nov 15, 2024

I experience the same issue when plotting raster data. So maybe its something with the wheel zoom tool and datashader.

@hoxbro
Copy link
Member

hoxbro commented Nov 15, 2024

Yes, it's likely either a GeoViews or Datashader bug. I cannot recreate it with hv.Path.

import geopandas as gpd
import geoviews as gv
import holoviews as hv
from holoviews.operation.datashader import rasterize

hv.extension("bokeh")

linestrings = [
    "LINESTRING (-121.97625624848078 36.96474939629007, -121.96688469179223 36.948366095134865)",
    "LINESTRING (-121.97664230038448 36.96460468814935, -121.96855460367323 36.94778657367965)",
    "LINESTRING (-121.97645658443105 36.9646156205337, -121.97084873679243 36.94715929907674)",
    "LINESTRING (-122.03956614150331 36.96045115224142, -122.036952745531 36.94254620927747)",
]
gdf = gpd.GeoSeries.from_wkt(linestrings, crs=4326).to_frame("geometry")

rasterize(hv.Path(gdf)) + rasterize(hv.Path(sdf)) + rasterize(gv.Path(gdf)) + rasterize(gv.Path(sdf))

Image

@FlorisCalkoen
Copy link
Author

When you pin bokeh to bokeh<3.5 it seems to work again.

python
Python 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 15:57:01) [Clang 17.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import holoviews as hv
>>> hv.show_versions()
Python              :  3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 15:57:01) [Clang 17.0.6 ]
Operating system    :  macOS-14.6.1-arm64-arm-64bit
Panel comms         :  default

holoviews           :  1.20.0

bokeh               :  3.4.2
colorcet            :  3.1.0
cudf                :  -
cupy                :  -
dask                :  2024.11.2
dask-expr           :  1.1.19
datashader          :  0.16.3
geoviews            :  1.12.0
hvplot              :  0.11.1
ibis-framework      :  -
IPython             :  8.17.2
ipywidgets-bokeh    :  -
jupyter-bokeh       :  4.0.5
jupyterlab          :  4.3.0
matplotlib          :  3.9.2
networkx            :  3.4.2
notebook            :  6.5.4
numba               :  0.60.0
numpy               :  2.0.2
pandas              :  2.2.3
panel               :  1.4.5
param               :  2.1.1
pillow              :  11.0.0
plotly              :  -
pyarrow             :  17.0.0
pyviz-comms         :  3.0.3
scikit-image        :  0.24.0
scipy               :  1.14.1
spatialpandas       :  0.4.10
streamz             :  -
tsdownsample        :  -
xarray              :  2024.10.0

@hoxbro hoxbro added the type: bug Something isn't correct or isn't working label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

2 participants