From 35d369bdefab3d9d48987aef9a976a97523c63dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro?= Date: Mon, 2 Jan 2023 15:04:49 +0100 Subject: [PATCH 1/3] Work with inhomogeneous shape error in numpy 1.24 --- holoviews/core/data/spatialpandas.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/holoviews/core/data/spatialpandas.py b/holoviews/core/data/spatialpandas.py index 9af858daf7..16ef3c8726 100644 --- a/holoviews/core/data/spatialpandas.py +++ b/holoviews/core/data/spatialpandas.py @@ -804,7 +804,7 @@ def to_geom_dict(eltype, data, kdims, vdims, interface=None): xname, yname = (kd.name for kd in kdims[:2]) if isinstance(data, dict): - data = {k: v if isscalar(v) else np.asarray(v) for k, v in data.items()} + data = {k: _asarray(v) for k, v in data.items()} return data new_el = Dataset(data, kdims, vdims) if new_el.interface is interface: @@ -888,4 +888,27 @@ def from_shapely(data): return data +def _asarray(v): + """Convert input to scaler or array + + If the value is scalar it returns it immediately. + + Then it tries with a normal `np.asarray(v)` if this does not work + it tries with `np.asarray(v, dtype=object)`. + + The ValueError raised is because of an inhomogeneous shape of the input, + which raises an error in numpy v1.24 and above. + + Reason why it is not located in holoviews.core.util is that there is a already a + function called `asarray`. + + """ + if isscalar(v): + return v + try: + return np.asarray(v) + except ValueError: + return np.asarray(v, dtype=object) + + Interface.register(SpatialPandasInterface) From 0b60ea1f5f1c1648cf261f609af94995f4079fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro?= Date: Mon, 2 Jan 2023 15:10:02 +0100 Subject: [PATCH 2/3] Update filterwarning --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 0163c79d6f..489a78a99f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ filterwarnings = [ "ignore:make_current is deprecated; start the event loop first:DeprecationWarning:panel.io.server", # 2023-01-02: Numpy 1.24 warnings "ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:bokeh", # https://github.com/bokeh/bokeh/pull/12690 - "ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:cupy", # https://github.com/cupy/cupy/issues/7211 + "ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:cupy", # https://github.com/cupy/cupy/pull/7245 "ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:plotly.express.imshow_utils", # https://github.com/plotly/plotly.py/pull/3997 "ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:skimage.util.dtype", # https://github.com/scikit-image/scikit-image/pull/6637 ] From 08c6d42c88d812aa4f0fa8fb56d46f1d3e6f5791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro?= Date: Tue, 3 Jan 2023 11:40:29 +0100 Subject: [PATCH 3/3] Put isscalar back to dict comprehension --- holoviews/core/data/spatialpandas.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/holoviews/core/data/spatialpandas.py b/holoviews/core/data/spatialpandas.py index 16ef3c8726..d31b0d2aa2 100644 --- a/holoviews/core/data/spatialpandas.py +++ b/holoviews/core/data/spatialpandas.py @@ -804,7 +804,7 @@ def to_geom_dict(eltype, data, kdims, vdims, interface=None): xname, yname = (kd.name for kd in kdims[:2]) if isinstance(data, dict): - data = {k: _asarray(v) for k, v in data.items()} + data = {k: v if isscalar(v) else _asarray(v) for k, v in data.items()} return data new_el = Dataset(data, kdims, vdims) if new_el.interface is interface: @@ -889,11 +889,9 @@ def from_shapely(data): def _asarray(v): - """Convert input to scaler or array + """Convert input to array - If the value is scalar it returns it immediately. - - Then it tries with a normal `np.asarray(v)` if this does not work + First it tries with a normal `np.asarray(v)` if this does not work it tries with `np.asarray(v, dtype=object)`. The ValueError raised is because of an inhomogeneous shape of the input, @@ -901,10 +899,7 @@ def _asarray(v): Reason why it is not located in holoviews.core.util is that there is a already a function called `asarray`. - """ - if isscalar(v): - return v try: return np.asarray(v) except ValueError: