From a71720e24422abc8c60fb1e69e8ffcfb8a7d7382 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Sat, 29 Jun 2024 23:10:34 +0800 Subject: [PATCH 01/11] 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) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c1868168..5e4d368b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ A Python package providing buffer compression and transformation codecs \ for use in data storage and communication applications.""" readme = "README.rst" dependencies = [ - "numpy>=1.7", + "numpy>=1.7, <2.0", ] requires-python = ">=3.10" dynamic = [ From 1122eda4c2cdf6edd66c984ee35652fea5163355 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:02:12 +0800 Subject: [PATCH 02/11] Update zfpy.py Add warning when user import zfpy but with numpy >=2.0.0 --- numcodecs/zfpy.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index 788b1f24..8397b7b7 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -1,9 +1,22 @@ from contextlib import suppress +import warnings +import numpy as np _zfpy = None -with suppress(ImportError): - import zfpy as _zfpy +# Check NumPy version +numpy_version = np.__version__ +numpy_version_tuple = tuple(map(int, numpy_version.split('.'))) +if numpy_version_tuple >= (2, 0, 0): + _zfpy = None + 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 From cc92bcea8b14d7507759da8189e0b23c11fda2ab Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:12:27 +0800 Subject: [PATCH 03/11] Update pyproject.toml ensure that the zfpy optional dependency has this constraint. --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5e4d368b..9826168f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ A Python package providing buffer compression and transformation codecs \ for use in data storage and communication applications.""" readme = "README.rst" dependencies = [ - "numpy>=1.7, <2.0", + "numpy>=1.7", ] requires-python = ">=3.10" dynamic = [ @@ -64,6 +64,7 @@ msgpack = [ ] zfpy = [ "zfpy>=1.0.0", + "numpy<2.0.0", ] pcodec = [ "pcodec>=0.1.0", From 56f6b6d1bf6e04de756037007cd966f43debbec9 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:14:48 +0800 Subject: [PATCH 04/11] Update zfpy.py --- numcodecs/zfpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index 8397b7b7..9d216842 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -16,7 +16,7 @@ ) else: with suppress(ImportError): - import zfpy as _zfpy + import zfpy as _zfpy if _zfpy: from .abc import Codec From 0eec08fdb8d45de00e844259238c5fe7a6d4a65c Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:27:09 +0800 Subject: [PATCH 05/11] Update numcodecs/zfpy.py Co-authored-by: jakirkham --- numcodecs/zfpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index 9d216842..f0f3a3b1 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -1,6 +1,6 @@ from contextlib import suppress +from importlib.metadata import PackageNotFoundError, version import warnings -import numpy as np _zfpy = None From 6633248bf8a62cfb3b91e96046fac96055d0b8ef Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:28:03 +0800 Subject: [PATCH 06/11] Update numcodecs/zfpy.py Co-authored-by: jakirkham --- numcodecs/zfpy.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index f0f3a3b1..29b20ada 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -4,16 +4,20 @@ _zfpy = None -# Check NumPy version -numpy_version = np.__version__ -numpy_version_tuple = tuple(map(int, numpy_version.split('.'))) -if numpy_version_tuple >= (2, 0, 0): - _zfpy = None - 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 - ) +_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_tuple >= (2, 0, 0) and zfpy_version_tuple <= (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 From da03546ab38766b69dd545870b09bf958bac6821 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:34:37 +0800 Subject: [PATCH 07/11] Update zfpy.py --- numcodecs/zfpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index 29b20ada..d0963363 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -11,7 +11,7 @@ if _zfpy_version: # Check NumPy version _numpy_version: tuple = tuple(map(int, version("numpy").split('.'))) - if numpy_version_tuple >= (2, 0, 0) and zfpy_version_tuple <= (1, 0, 1): + 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. " From 1c39bb8cfc6ee452e6ccdce8fc36fde6ce9a50c9 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:44:13 +0800 Subject: [PATCH 08/11] Update release.rst --- docs/release.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release.rst b/docs/release.rst index 8d36c444..c7ac0354 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -31,6 +31,8 @@ Fix By :user:`Elliott Sales de Andrade `, :issue:`487`. * Fix Upgrade to Zstd 1.5.5 due to potential corruption. By :user:`Mark Kittisopikul `, :issue:`429` +* Add version constraint(<2.0) for numpy in zfpy. + By :user:`Tom Liang `, :issue:540. Maintenance ~~~~~~~~~~~ From fc21f3d4b8894275136c8fe37fe2f0eaaf349d26 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:45:20 +0800 Subject: [PATCH 09/11] Update release.rst --- docs/release.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release.rst b/docs/release.rst index c7ac0354..b569015c 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -32,7 +32,7 @@ Fix * Fix Upgrade to Zstd 1.5.5 due to potential corruption. By :user:`Mark Kittisopikul `, :issue:`429` * Add version constraint(<2.0) for numpy in zfpy. - By :user:`Tom Liang `, :issue:540. + By :user:`Tom Liang `, :issue:`540`. Maintenance ~~~~~~~~~~~ From 968607aee2b92a9a4778c5a7189a13fc92e8bb37 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 07:15:54 +0000 Subject: [PATCH 10/11] style: pre-commit fixes --- numcodecs/zfpy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index d0963363..7fce3358 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -16,11 +16,11 @@ 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 + UserWarning, ) else: with suppress(ImportError): - import zfpy as _zfpy + import zfpy as _zfpy if _zfpy: from .abc import Codec From 577ca5ae6b5ee0b353a1711b5d1b6433975399a4 Mon Sep 17 00:00:00 2001 From: px39n <53490111+px39n@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:36:00 +0800 Subject: [PATCH 11/11] Update zfpy.py --- numcodecs/zfpy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numcodecs/zfpy.py b/numcodecs/zfpy.py index 7fce3358..40d6b8e4 100644 --- a/numcodecs/zfpy.py +++ b/numcodecs/zfpy.py @@ -18,9 +18,9 @@ "Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.", UserWarning, ) -else: - with suppress(ImportError): - import zfpy as _zfpy + else: + with suppress(ImportError): + import zfpy as _zfpy if _zfpy: from .abc import Codec