Skip to content

Commit

Permalink
Fix ZFPY import error (#540)
Browse files Browse the repository at this point in the history
* 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 <jakirkham@gmail.com>

* Update numcodecs/zfpy.py

Co-authored-by: jakirkham <jakirkham@gmail.com>

* Update zfpy.py

* Update release.rst

* Update release.rst

* style: pre-commit fixes

* Update zfpy.py

---------

Co-authored-by: jakirkham <jakirkham@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 8, 2024
1 parent 342754d commit 4929b35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Fix
By :user:`Elliott Sales de Andrade <QuLogic>`, :issue:`487`.
* Fix Upgrade to Zstd 1.5.5 due to potential corruption.
By :user:`Mark Kittisopikul <mkitti>`, :issue:`429`
* Add version constraint(<2.0) for numpy in zfpy.
By :user:`Tom Liang <px39n>`, :issue:`540`.

Maintenance
~~~~~~~~~~~
Expand Down
21 changes: 19 additions & 2 deletions numcodecs/zfpy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
from contextlib import suppress
from importlib.metadata import PackageNotFoundError, version
import warnings

_zfpy = None
with suppress(ImportError):
import zfpy as _zfpy

_zfpy_version: tuple = ()
with suppress(PackageNotFoundError):
_zfpy_version = tuple(map(int, version("zfpy").split(".")))

if _zfpy_version:
# Check NumPy version
_numpy_version: tuple = tuple(map(int, version("numpy").split('.')))
if _numpy_version >= (2, 0, 0) and _zfpy_version <= (1, 0, 1):
_zfpy_version = ()
warnings.warn(
"NumPy version >= 2.0.0 detected. The zfpy library is incompatible with this version of NumPy. "
"Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.",
UserWarning,
)
else:
with suppress(ImportError):
import zfpy as _zfpy

if _zfpy:
from .abc import Codec
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ msgpack = [
]
zfpy = [
"zfpy>=1.0.0",
"numpy<2.0.0",
]
pcodec = [
"pcodec>=0.1.0",
Expand Down

0 comments on commit 4929b35

Please sign in to comment.