From 055d1f4d5dcfb05ed5151700181bed3e7793b1b9 Mon Sep 17 00:00:00 2001 From: kx79wq Date: Sat, 7 Dec 2024 12:31:32 +0100 Subject: [PATCH 1/3] FIX: small fixes to code to make sure unit tests pass This is in preparation for migration to numpy>2 and pandas>2. * FIX: python versions used in unit test, including python 3.12 * FIX: get rid of resource_filename for python 3.12 * FIX: remove obsolete distutils from package for python 3.12 * FIX: keep numpy and pandas below v2 for now --- .github/workflows/test.yml | 2 +- histogrammar/primitives/sparselybin.py | 2 +- histogrammar/resources.py | 8 ++++---- requirements-test.txt | 2 +- requirements.txt | 2 +- tests/test_gpu.py | 4 ++-- tests/test_numpy.py | 5 +++++ 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8f2c60..0bdf3a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: [3.8, 3.9, 3.10,13, 3.11, 3.12] + python: ['3.8', '3.9', '3.10', '3.11', '3.12'] runs-on: ${{ matrix.os }} steps: diff --git a/histogrammar/primitives/sparselybin.py b/histogrammar/primitives/sparselybin.py index e3f1c7f..4c2f227 100644 --- a/histogrammar/primitives/sparselybin.py +++ b/histogrammar/primitives/sparselybin.py @@ -657,7 +657,7 @@ def __repr__(self): def __eq__(self, other): return isinstance(other, SparselyBin) and numeq(self.binWidth, other.binWidth) and \ - self.quantity == other.quantity and numeq(self.entries, other.entries) and self.bins == other.bins and \ + self.quantity == other.quantity and numeq(self.entries, other.entries) and sorted(self.bins) == sorted(other.bins) and \ self.nanflow == other.nanflow and numeq(self.origin, other.origin) def __ne__(self, other): diff --git a/histogrammar/resources.py b/histogrammar/resources.py index b347116..1935ca5 100644 --- a/histogrammar/resources.py +++ b/histogrammar/resources.py @@ -21,20 +21,20 @@ # Resources lookup file for histogrammar import pathlib -from pkg_resources import resource_filename -import histogrammar as hg + +ROOT_DIRECTORY = pathlib.Path(__file__).resolve().parent # data files that are shipped with histogrammar. _DATA = { _.name: _ - for _ in pathlib.Path(resource_filename(hg.__name__, "test_data")).glob("*") + for _ in pathlib.Path(ROOT_DIRECTORY / "test_data").glob("*") } # Tutorial notebooks _NOTEBOOK = { _.name: _ - for _ in pathlib.Path(resource_filename(hg.__name__, "notebooks")).glob("*.ipynb") + for _ in pathlib.Path(ROOT_DIRECTORY / "notebooks").glob("*.ipynb") } # Resource types diff --git a/requirements-test.txt b/requirements-test.txt index 9272284..3dbc8db 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -4,4 +4,4 @@ jupyter_client>=5.2.3 ipykernel>=5.1.3 pre-commit>=2.9.0 matplotlib -pandas \ No newline at end of file +pandas<2.0.0 diff --git a/requirements.txt b/requirements.txt index 28d93ce..100320e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -numpy>=1.18.0 +numpy<2.0.0 tqdm joblib>=0.14.0 diff --git a/tests/test_gpu.py b/tests/test_gpu.py index 55800d2..e624111 100644 --- a/tests/test_gpu.py +++ b/tests/test_gpu.py @@ -16,10 +16,10 @@ import json import math +import shutil import subprocess import sys import unittest -from distutils import spawn from histogrammar.defs import Factory from histogrammar.primitives.average import Average @@ -54,7 +54,7 @@ class TestGPU(unittest.TestCase): except ImportError: numpy = None - nvcc = spawn.find_executable("nvcc") + nvcc = shutil.which("nvcc") def runTest(self): self.testCount() diff --git a/tests/test_numpy.py b/tests/test_numpy.py index 54f80cf..8d57f19 100644 --- a/tests/test_numpy.py +++ b/tests/test_numpy.py @@ -236,6 +236,9 @@ def compare(self, name, hnp, npdata, hpy, pydata): startTime = time.time() hnp.fill.numpy(npdata) numpyTime = time.time() - startTime + # protect against zero time. + numpyTime = max(numpyTime, 1e-10) + if pydata.dtype != numpy.unicode_: for key in npdata: @@ -261,6 +264,8 @@ def compare(self, name, hnp, npdata, hpy, pydata): d = float(d) hpy.fill(d) pyTime = time.time() - startTime + # protect against zero time. + pyTime = max(pyTime, 1e-10) for h in [hpy2, hpy3, hpy3]: for d in pydata: From 003b6f8bb2c69d81a9d7c30244e1f75662efde5e Mon Sep 17 00:00:00 2001 From: kx79wq Date: Sun, 8 Dec 2024 22:27:28 +0100 Subject: [PATCH 2/3] ENH: use importlib to collect hg resources - importlib only available since python 3.9 - turn off tests for deprecated python 3.8 --- .github/workflows/test.yml | 2 +- histogrammar/notebooks/__init__.py | 0 histogrammar/resources.py | 11 ++++------- histogrammar/test_data/__init__.py | 0 4 files changed, 5 insertions(+), 8 deletions(-) create mode 100644 histogrammar/notebooks/__init__.py create mode 100644 histogrammar/test_data/__init__.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bdf3a7..4e10c0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python: ['3.9', '3.10', '3.11', '3.12'] runs-on: ${{ matrix.os }} steps: diff --git a/histogrammar/notebooks/__init__.py b/histogrammar/notebooks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/histogrammar/resources.py b/histogrammar/resources.py index 1935ca5..7b52d23 100644 --- a/histogrammar/resources.py +++ b/histogrammar/resources.py @@ -19,22 +19,19 @@ # Resources lookup file for histogrammar - -import pathlib - -ROOT_DIRECTORY = pathlib.Path(__file__).resolve().parent +from importlib import resources # data files that are shipped with histogrammar. _DATA = { _.name: _ - for _ in pathlib.Path(ROOT_DIRECTORY / "test_data").glob("*") + for _ in resources.files("histogrammar.test_data").iterdir() } # Tutorial notebooks _NOTEBOOK = { - _.name: _ - for _ in pathlib.Path(ROOT_DIRECTORY / "notebooks").glob("*.ipynb") + p.name: p + for p in resources.files("histogrammar.notebooks").iterdir() if p.suffix == ".ipynb" } # Resource types diff --git a/histogrammar/test_data/__init__.py b/histogrammar/test_data/__init__.py new file mode 100644 index 0000000..e69de29 From 0abadbb3aef9cb8b44bc1722ccd787457d50de76 Mon Sep 17 00:00:00 2001 From: kx79wq Date: Mon, 9 Dec 2024 09:40:31 +0100 Subject: [PATCH 3/3] ENH: use modules for importlib instead of strings --- histogrammar/resources.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/histogrammar/resources.py b/histogrammar/resources.py index 7b52d23..2c67cf2 100644 --- a/histogrammar/resources.py +++ b/histogrammar/resources.py @@ -20,18 +20,19 @@ # Resources lookup file for histogrammar from importlib import resources +from histogrammar import test_data, notebooks # data files that are shipped with histogrammar. _DATA = { _.name: _ - for _ in resources.files("histogrammar.test_data").iterdir() + for _ in resources.files(test_data).iterdir() } # Tutorial notebooks _NOTEBOOK = { p.name: p - for p in resources.files("histogrammar.notebooks").iterdir() if p.suffix == ".ipynb" + for p in resources.files(notebooks).iterdir() if p.suffix == ".ipynb" } # Resource types