Skip to content

Commit 4929b35

Browse files
px39njakirkhampre-commit-ci[bot]
authored
Fix ZFPY import error (#540)
* Update pyproject.toml When numpy >=2.0.0 from numcodecs.zfpy import ZFPY raise error [ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject] The error is caused by zfpy library crashing with recent ABI breaking of numpy udpate. So we'd better force numpy <2.0 unless zfpy update again. Reference: (https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp) * Update zfpy.py Add warning when user import zfpy but with numpy >=2.0.0 * Update pyproject.toml ensure that the zfpy optional dependency has this constraint. * Update zfpy.py * Update numcodecs/zfpy.py Co-authored-by: jakirkham <[email protected]> * Update numcodecs/zfpy.py Co-authored-by: jakirkham <[email protected]> * Update zfpy.py * Update release.rst * Update release.rst * style: pre-commit fixes * Update zfpy.py --------- Co-authored-by: jakirkham <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 342754d commit 4929b35

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Fix
3131
By :user:`Elliott Sales de Andrade <QuLogic>`, :issue:`487`.
3232
* Fix Upgrade to Zstd 1.5.5 due to potential corruption.
3333
By :user:`Mark Kittisopikul <mkitti>`, :issue:`429`
34+
* Add version constraint(<2.0) for numpy in zfpy.
35+
By :user:`Tom Liang <px39n>`, :issue:`540`.
3436

3537
Maintenance
3638
~~~~~~~~~~~

numcodecs/zfpy.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
from contextlib import suppress
2+
from importlib.metadata import PackageNotFoundError, version
3+
import warnings
24

35
_zfpy = None
4-
with suppress(ImportError):
5-
import zfpy as _zfpy
66

7+
_zfpy_version: tuple = ()
8+
with suppress(PackageNotFoundError):
9+
_zfpy_version = tuple(map(int, version("zfpy").split(".")))
10+
11+
if _zfpy_version:
12+
# Check NumPy version
13+
_numpy_version: tuple = tuple(map(int, version("numpy").split('.')))
14+
if _numpy_version >= (2, 0, 0) and _zfpy_version <= (1, 0, 1):
15+
_zfpy_version = ()
16+
warnings.warn(
17+
"NumPy version >= 2.0.0 detected. The zfpy library is incompatible with this version of NumPy. "
18+
"Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.",
19+
UserWarning,
20+
)
21+
else:
22+
with suppress(ImportError):
23+
import zfpy as _zfpy
724

825
if _zfpy:
926
from .abc import Codec

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ msgpack = [
6464
]
6565
zfpy = [
6666
"zfpy>=1.0.0",
67+
"numpy<2.0.0",
6768
]
6869
pcodec = [
6970
"pcodec>=0.1.0",

0 commit comments

Comments
 (0)