Skip to content

Commit 50b76a5

Browse files
authored
Merge pull request #66 from histogrammar/fix_unit_tests
FIX: small fixes to make unit tests pass for numpy<2 and pandas<2
2 parents 2a70935 + 0abadbb commit 50b76a5

File tree

9 files changed

+16
-13
lines changed

9 files changed

+16
-13
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [ubuntu-latest]
13-
python: [3.8, 3.9, 3.10,13, 3.11, 3.12]
13+
python: ['3.9', '3.10', '3.11', '3.12']
1414
runs-on: ${{ matrix.os }}
1515

1616
steps:

histogrammar/notebooks/__init__.py

Whitespace-only changes.

histogrammar/primitives/sparselybin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def __repr__(self):
657657

658658
def __eq__(self, other):
659659
return isinstance(other, SparselyBin) and numeq(self.binWidth, other.binWidth) and \
660-
self.quantity == other.quantity and numeq(self.entries, other.entries) and self.bins == other.bins and \
660+
self.quantity == other.quantity and numeq(self.entries, other.entries) and sorted(self.bins) == sorted(other.bins) and \
661661
self.nanflow == other.nanflow and numeq(self.origin, other.origin)
662662

663663
def __ne__(self, other):

histogrammar/resources.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@
1919

2020

2121
# Resources lookup file for histogrammar
22-
23-
import pathlib
24-
from pkg_resources import resource_filename
25-
import histogrammar as hg
22+
from importlib import resources
23+
from histogrammar import test_data, notebooks
2624

2725

2826
# data files that are shipped with histogrammar.
2927
_DATA = {
3028
_.name: _
31-
for _ in pathlib.Path(resource_filename(hg.__name__, "test_data")).glob("*")
29+
for _ in resources.files(test_data).iterdir()
3230
}
3331

3432
# Tutorial notebooks
3533
_NOTEBOOK = {
36-
_.name: _
37-
for _ in pathlib.Path(resource_filename(hg.__name__, "notebooks")).glob("*.ipynb")
34+
p.name: p
35+
for p in resources.files(notebooks).iterdir() if p.suffix == ".ipynb"
3836
}
3937

4038
# Resource types

histogrammar/test_data/__init__.py

Whitespace-only changes.

requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ jupyter_client>=5.2.3
44
ipykernel>=5.1.3
55
pre-commit>=2.9.0
66
matplotlib
7-
pandas
7+
pandas<2.0.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
numpy>=1.18.0
1+
numpy<2.0.0
22
tqdm
33
joblib>=0.14.0

tests/test_gpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import json
1818
import math
19+
import shutil
1920
import subprocess
2021
import sys
2122
import unittest
22-
from distutils import spawn
2323

2424
from histogrammar.defs import Factory
2525
from histogrammar.primitives.average import Average
@@ -54,7 +54,7 @@ class TestGPU(unittest.TestCase):
5454
except ImportError:
5555
numpy = None
5656

57-
nvcc = spawn.find_executable("nvcc")
57+
nvcc = shutil.which("nvcc")
5858

5959
def runTest(self):
6060
self.testCount()

tests/test_numpy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def compare(self, name, hnp, npdata, hpy, pydata):
236236
startTime = time.time()
237237
hnp.fill.numpy(npdata)
238238
numpyTime = time.time() - startTime
239+
# protect against zero time.
240+
numpyTime = max(numpyTime, 1e-10)
241+
239242

240243
if pydata.dtype != numpy.unicode_:
241244
for key in npdata:
@@ -261,6 +264,8 @@ def compare(self, name, hnp, npdata, hpy, pydata):
261264
d = float(d)
262265
hpy.fill(d)
263266
pyTime = time.time() - startTime
267+
# protect against zero time.
268+
pyTime = max(pyTime, 1e-10)
264269

265270
for h in [hpy2, hpy3, hpy3]:
266271
for d in pydata:

0 commit comments

Comments
 (0)