Skip to content

Commit

Permalink
Support Numpy 1.25 (#5870)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored and ahuang11 committed Sep 9, 2023
1 parent 2411cfb commit 9003a93
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 8 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,54 @@ jobs:
files: ./coverage.xml
flags: ui-tests
fail_ci_if_error: false # optional (default = false)
core_test:
name: Core test on ${{ matrix.python-version }}, ${{ matrix.os }}
needs: [pre_commit]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
python-version: ['3.11']
timeout-minutes: 120
defaults:
run:
shell: bash -el {0}
env:
DESC: "Python ${{ matrix.python-version }} tests"
PYTHON_VERSION: ${{ matrix.python-version }}
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
DISPLAY: ":99.0"
PYTHONIOENCODING: "utf-8"
MPLBACKEND: "Agg"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OMP_NUM_THREADS: 1
OPENBLAS_NUM_THREADS: 1
MKL_NUM_THREADS: 1
VECLIB_MAXIMUM_THREADS: 1
NUMEXPR_NUM_THREADS: 1
NUMBA_NUM_THREADS: 1
PYDEVD_DISABLE_FILE_VALIDATION: 1
steps:
- uses: holoviz-dev/holoviz_tasks/install@v0.1a15
with:
name: core_test_suite
python-version: ${{ matrix.python-version }}
channel-priority: strict
channels: pyviz/label/dev,conda-forge,nodefaults
envs: "-o tests_core"
cache: true
conda-update: true
id: install
- name: bokeh sampledata
run: |
conda activate test-environment
bokeh sampledata
- name: Check packages latest version
run: |
conda activate test-environment
python scripts/check_latest_packages.py
- name: doit test_unit
run: |
conda activate test-environment
pytest holoviews
2 changes: 1 addition & 1 deletion holoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
else:
class notebook_extension(param.ParameterizedFunction):
def __call__(self, *args, **opts): # noqa (dummy signature)
raise Exception("IPython notebook not available: use hv.extension instead.")
raise Exception("Jupyter notebook not available: use hv.extension instead.")

if '_pyodide' in sys.modules:
from .pyodide import pyodide_extension, in_jupyterlite
Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/core/data/test_imageinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ class RGBElement_ImageInterfaceTests(BaseRGBElementInterfaceTests):

__test__ = True

def test_reduce_to_single_values(self):
try:
super().test_reduce_to_single_values()
except DataError:
msg = (
"RGB element can't run with this command: "
"'pytest holoviews/tests -k test_reduce_to_single_values'"
"but runs fine with 'pytest holoviews/tests/core/'"
)
raise SkipTest(msg)


class BaseHSVElementInterfaceTests(InterfaceTests):

Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/element/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def test_poly_geom_selection_inverted(self):
self.assertEqual(region, Rectangles([]) * Path([list(geom)+[(0.2, -0.15)]]))


@shapelib_available
@pytest.mark.skipif(shapely is None and spd is None, reason='Neither shapely nor spatialpandas are available')
class TestSpatialSelectColumnar:
geometry_encl = np.array([
[-1, 0.5],
Expand Down
14 changes: 14 additions & 0 deletions holoviews/tests/util/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@

xr_skip = skipIf(xr is None, "xarray not available")

try:
import spatialpandas as spd
except ImportError:
spd = None

try:
import shapely
except ImportError:
shapely = None

shapelib_available = skipIf(shapely is None and spd is None,
'Neither shapely nor spatialpandas are available')

from holoviews.core.data import Dataset
from holoviews.element.comparison import ComparisonTestCase
from holoviews.util.transform import dim
Expand Down Expand Up @@ -524,6 +537,7 @@ def test_pickle(self):
self.assertEqual(expr, expr2)


@shapelib_available
def test_dataset_transform_by_spatial_select_expr_index_not_0_based():
"""Ensure 'spatial_select' expression works when index not zero-based.
Use 'spatial_select' defined by four nodes to select index 104, 105.
Expand Down
8 changes: 8 additions & 0 deletions holoviews/tests/util/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Unit tests of the helper functions in utils
"""
from unittest import SkipTest
from collections import OrderedDict

from holoviews import notebook_extension
Expand All @@ -18,10 +19,17 @@

from ..utils import LoggingComparisonTestCase

try:
import notebook
except ImportError:
notebook = None


class TestOutputUtil(ComparisonTestCase):

def setUp(self):
if notebook is None:
raise SkipTest("Jupyter Notebook not available")
notebook_extension(*BACKENDS)
Store.current_backend = 'matplotlib'
Store.renderers['matplotlib'] = mpl.MPLRenderer.instance()
Expand Down
11 changes: 6 additions & 5 deletions holoviews/util/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ def _python_isin(array, values):

python_isin = _maybe_map(_python_isin)

# Type of numpy function like np.max changed in Numpy 1.25
# from function to a numpy._ArrayFunctionDispatcher.
function_types = (
BuiltinFunctionType, BuiltinMethodType, FunctionType,
MethodType, np.ufunc, iloc, loc
MethodType, np.ufunc, iloc, loc, type(np.max)
)


Expand Down Expand Up @@ -251,7 +253,7 @@ class dim:

def __init__(self, obj, *args, **kwargs):
from panel.widgets import Widget
ops = []
self.ops = []
self._ns = np.ndarray
self.coerce = kwargs.get('coerce', True)
if isinstance(obj, str):
Expand All @@ -264,7 +266,7 @@ def __init__(self, obj, *args, **kwargs):
self.dimension = obj.param.value
else:
self.dimension = obj.dimension
ops = obj.ops
self.ops = obj.ops
if args:
fn = args[0]
else:
Expand All @@ -274,9 +276,8 @@ def __init__(self, obj, *args, **kwargs):
any(fn in funcs for funcs in self._all_funcs)):
raise ValueError('Second argument must be a function, '
'found %s type' % type(fn))
ops = ops + [{'args': args[1:], 'fn': fn, 'kwargs': kwargs,
self.ops = self.ops + [{'args': args[1:], 'fn': fn, 'kwargs': kwargs,
'reverse': kwargs.pop('reverse', False)}]
self.ops = ops

def __getstate__(self):
return self.__dict__
Expand Down
37 changes: 37 additions & 0 deletions scripts/check_latest_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import requests
from datetime import datetime, date, timedelta

from packaging.version import Version


def main(*packages):
allowed_date = date.today() - timedelta(days=2)
is_latest = True
for package in sorted(packages):
url = f"https://pypi.org/pypi/{package}/json"
resp = requests.get(url).json()
latest = resp["info"]["version"]
current = __import__(package).__version__

latest_release_date = datetime.fromisoformat(
resp["releases"][latest][0]["upload_time_iso_8601"]
).date()
current_release_date = datetime.fromisoformat(
resp["releases"][current][0]["upload_time_iso_8601"]
).date()

version_check = Version(current) >= Version(latest)
date_check = allowed_date >= latest_release_date
is_latest &= version_check and date_check

print(
f"Package: {package:<10} Current: {current:<7} ({current_release_date})\tLatest: {latest:<7} ({latest_release_date})"
)

if not is_latest:
sys.exit(1)


if __name__ == "__main__":
main("numpy", "pandas")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
'dash >=1.16',
'codecov',
'ipython >=5.4.0',
'pandas <2.1', # for spatialpandas recursion https://github.com/holoviz/spatialpandas/issues/124
]

# Optional tests dependencies, i.e. one should be able
Expand All @@ -59,6 +58,7 @@
'selenium',
'spatialpandas',
'datashader >=0.11.1',
'pandas <2.1', # for spatialpandas recursion error: https://github.com/holoviz/spatialpandas/issues/124
]

extras_require['tests_gpu'] = extras_require['tests'] + [
Expand Down

0 comments on commit 9003a93

Please sign in to comment.