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

Support numpy 1.24 #608

Merged
merged 6 commits into from
Jan 3, 2023
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
8 changes: 4 additions & 4 deletions geoviews/data/geom_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from holoviews.core.dimension import OrderedDict as cyODict, dimension_name
from holoviews.core.util import isscalar

from ..util import geom_types, geom_to_array, geom_length
from ..util import asarray, geom_types, geom_to_array, geom_length


class GeomDictInterface(DictInterface):
Expand Down Expand Up @@ -61,7 +61,7 @@ def init(cls, eltype, data, kdims, vdims):
unpacked = []
for d, vals in data.items():
if isinstance(d, tuple):
vals = np.asarray(vals)
vals = asarray(vals)
if vals.shape == (0,):
for sd in d:
unpacked.append((sd, np.array([], dtype=vals.dtype)))
Expand All @@ -75,7 +75,7 @@ def init(cls, eltype, data, kdims, vdims):
unpacked.append((d, vals))
else:
if not isscalar(vals):
vals = np.asarray(vals)
vals = asarray(vals)
if not vals.ndim == 1 and d in dimensions:
raise ValueError('DictInterface expects data for each column to be flat.')
unpacked.append((d, vals))
Expand Down Expand Up @@ -300,7 +300,7 @@ def geom_from_dict(geom, xdim, ydim, single_type, multi_type):
Point, LineString, Polygon, MultiPoint, MultiPolygon, MultiLineString
)
if (xdim, ydim) in geom:
xs, ys = np.asarray(geom.pop((xdim, ydim))).T
xs, ys = asarray(geom.pop((xdim, ydim))).T
elif xdim in geom and ydim in geom:
xs, ys = geom.pop(xdim), geom.pop(ydim)
else:
Expand Down
7 changes: 4 additions & 3 deletions geoviews/data/geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
from collections import defaultdict

import numpy as np
import pandas as pd

from holoviews.core.util import isscalar, unique_iterator, unique_array, pd
from holoviews.core.util import isscalar, unique_iterator, unique_array
from holoviews.core.data import Dataset, Interface, MultiInterface
from holoviews.core.data.interface import DataError
from holoviews.core.data import PandasInterface
from holoviews.core.data.spatialpandas import get_value_array
from holoviews.core.dimension import dimension_name
from holoviews.element import Path

from ..util import geom_to_array, geom_types, geom_length
from ..util import asarray, geom_to_array, geom_types, geom_length
from .geom_dict import geom_from_dict


Expand Down Expand Up @@ -599,7 +600,7 @@ def from_multi(eltype, data, kdims, vdims):
for d in data:
types.append(type(d))
if isinstance(d, dict):
d = {k: v if isscalar(v) else np.asarray(v) for k, v in d.items()}
d = {k: v if isscalar(v) else asarray(v) for k, v in d.items()}
new_data.append(d)
continue
new_el = eltype(d, kdims, vdims)
Expand Down
16 changes: 16 additions & 0 deletions geoviews/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,3 +776,19 @@ def get_tile_rgb(tile_source, bbox, zoom_level, bbox_crs=ccrs.PlateCarree()):
return RGB(
rgb, bounds=(x0, y0, x1, y1), crs=ccrs.GOOGLE_MERCATOR, vdims=['R', 'G', 'B'],
).clone(datatype=['grid', 'xarray', 'iris'])[l:r, b:t]


def asarray(v):
"""Convert input to array

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,
which raises an error in numpy v1.24 and above.

"""
try:
return np.asarray(v)
except ValueError:
return np.asarray(v, dtype=object)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def run(self):
'scipy',
'shapely',
'xarray',
'pooch',
]

# Packages not working on python 3.11 becauase of numba
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ nbsmoke_skip_run = .*Homepage\.ipynb$
.*gallery/.*/xarray_image\.ipynb$
.*gallery/.*/xarray_quadmesh\.ipynb$
.*gallery/.*/katrina_track\.ipynb$
filterwarnings =
ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:bokeh
ignore:`.+?` is a deprecated alias for `.+?`.:DeprecationWarning:cupy

[flake8]
include = *.py
Expand Down