From 2cf72fd784f4d90d24c3d3bb1f3a67fe29cebd5c Mon Sep 17 00:00:00 2001
From: Steve Kowalik <steven@wedontsleep.org>
Date: Tue, 14 Feb 2023 18:00:47 +1100
Subject: [PATCH] Support NumPy >= 1.20
NumPy 1.20 deprecated the usage of aliases of builtin types, such as
np.float and np.int, and NumPy 1.24 removed them entirely. Switch to
using the builtin types everywhere.
---
pypet/parameter.py | 4 ++--
pypet/pypetconstants.py | 11 +++++------
pypet/tests/integration/shared_data_test.py | 4 ++--
pypet/tests/testutils/data.py | 2 +-
pypet/tests/unittests/shared_data_test.py | 6 +++---
5 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/pypet/parameter.py b/pypet/parameter.py
index ce260e41..ba8ef4af 100644
--- a/pypet/parameter.py
+++ b/pypet/parameter.py
@@ -894,8 +894,8 @@ def f_supports(self, data):
# Numpy has many string types that depend on the length of the string,
# We allow all of them
dtype = data.dtype
- if np.issubdtype(dtype, np.str):
- dtype = np.str
+ if np.issubdtype(dtype, str):
+ dtype = str
return dtype in pypetconstants.PARAMETER_SUPPORTED_DATA
diff --git a/pypet/pypetconstants.py b/pypet/pypetconstants.py
index 8b1bcc18..35bd484e 100644
--- a/pypet/pypetconstants.py
+++ b/pypet/pypetconstants.py
@@ -105,23 +105,22 @@
numpy.int16,
numpy.int32,
numpy.int64,
- numpy.int,
numpy.int_,
- numpy.long,
numpy.uint8,
numpy.uint16,
numpy.uint32,
numpy.uint64,
- numpy.bool,
numpy.bool_,
numpy.float32,
numpy.float64,
- numpy.float,
numpy.float_,
numpy.complex64,
- numpy.complex,
numpy.complex_,
numpy.str_,
+ bool,
+ int,
+ complex,
+ float,
str,
bytes)
"""Set of supported scalar types by the storage service and the standard parameter"""
@@ -329,4 +328,4 @@
"""Wildcard replaced by the name of the current run set"""
DEFAULT_LOGGING = 'DEFAULT'
-"""Default logging configuration"""
\ No newline at end of file
+"""Default logging configuration"""
diff --git a/pypet/tests/integration/shared_data_test.py b/pypet/tests/integration/shared_data_test.py
index d823ee75..009fb63b 100644
--- a/pypet/tests/integration/shared_data_test.py
+++ b/pypet/tests/integration/shared_data_test.py
@@ -172,7 +172,7 @@ def tearDown(self):
def add_array_params(self, traj):
length = len(traj)
- da_data = np.zeros(length, dtype=np.int)
+ da_data = np.zeros(length, dtype=int)
traj.f_store(only_init=True)
traj.f_add_result(SharedResult, 'daarrays.a', SharedArray()).create_shared_data(obj=da_data)
traj.f_add_result(SharedResult, 'daarrays.ca', SharedCArray()).create_shared_data( obj=da_data)
@@ -459,4 +459,4 @@ def set_mode(self):
if __name__ == '__main__':
opt_args = parse_args()
- run_suite(**opt_args)
\ No newline at end of file
+ run_suite(**opt_args)
diff --git a/pypet/tests/testutils/data.py b/pypet/tests/testutils/data.py
index 8c98c403..39b9691f 100644
--- a/pypet/tests/testutils/data.py
+++ b/pypet/tests/testutils/data.py
@@ -118,7 +118,7 @@ def add_params(traj,param_dict):
traj.f_add_derived_parameter('Another.crun.String2', 'Really, again?', comment='test4')
- traj.f_add_result('Peter_Jackson',np.str(['is','full','of','suboptimal ideas']),
+ traj.f_add_result('Peter_Jackson', 'is full of suboptimal ideas',
comment='Only my opinion bro!',)
traj.results.f_add_leaf('Test', 42, comment='NC')
diff --git a/pypet/tests/unittests/shared_data_test.py b/pypet/tests/unittests/shared_data_test.py
index 5987d0c0..50e85474 100644
--- a/pypet/tests/unittests/shared_data_test.py
+++ b/pypet/tests/unittests/shared_data_test.py
@@ -267,7 +267,7 @@ def test_all_arrays(self):
traj = Trajectory(name=make_trajectory_name(self), filename=filename)
trajname = traj.v_name
- npearray = np.ones((2, 10, 3), dtype=np.float)
+ npearray = np.ones((2, 10, 3), dtype=float)
thevlarray = np.array(['j'.encode('utf-8'), 22.2, 'gutter'.encode('utf-8')])
traj.f_store(only_init=True)
res = traj.f_add_result(SharedResult, 'arrays')
@@ -345,7 +345,7 @@ def test_errors(self):
filename = make_temp_dir('hdf5errors.hdf5')
traj = Trajectory(name=make_trajectory_name(self), filename=filename)
- npearray = np.ones((2, 10, 3), dtype=np.float)
+ npearray = np.ones((2, 10, 3), dtype=float)
thevlarray = np.array(['j'.encode('utf-8'), 22.2, 'gutter'.encode('utf-8')])
with self.assertRaises(TypeError):
@@ -979,4 +979,4 @@ def test_array_len(self):
if __name__ == '__main__':
opt_args = parse_args()
- run_suite(**opt_args)
\ No newline at end of file
+ run_suite(**opt_args)