Skip to content

Commit 055d1f4

Browse files
author
kx79wq
committed
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
1 parent 2a70935 commit 055d1f4

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
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.8', '3.9', '3.10', '3.11', '3.12']
1414
runs-on: ${{ matrix.os }}
1515

1616
steps:

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
# Resources lookup file for histogrammar
2222

2323
import pathlib
24-
from pkg_resources import resource_filename
25-
import histogrammar as hg
24+
25+
ROOT_DIRECTORY = pathlib.Path(__file__).resolve().parent
2626

2727

2828
# data files that are shipped with histogrammar.
2929
_DATA = {
3030
_.name: _
31-
for _ in pathlib.Path(resource_filename(hg.__name__, "test_data")).glob("*")
31+
for _ in pathlib.Path(ROOT_DIRECTORY / "test_data").glob("*")
3232
}
3333

3434
# Tutorial notebooks
3535
_NOTEBOOK = {
3636
_.name: _
37-
for _ in pathlib.Path(resource_filename(hg.__name__, "notebooks")).glob("*.ipynb")
37+
for _ in pathlib.Path(ROOT_DIRECTORY / "notebooks").glob("*.ipynb")
3838
}
3939

4040
# Resource types

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)