From 2679e4789cb8d497abbecf9415c7411d02c692f9 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Tue, 18 Jun 2024 13:57:32 +0200 Subject: [PATCH 1/3] Fix numpy.bool8 imports --- setup.cfg | 2 +- tests/test_parameter.py | 6 +++--- trsfile/traceparameter.py | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 90cc2f5..9911b21 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ packages = trsfile.engine trsfile.converters install_requires = - numpy>=1,<2 + numpy>=1.24,<3 include_package_data = True [options.extras_require] diff --git a/tests/test_parameter.py b/tests/test_parameter.py index 45636a9..a45a37a 100644 --- a/tests/test_parameter.py +++ b/tests/test_parameter.py @@ -1,7 +1,7 @@ from io import BytesIO from unittest import TestCase -from numpy import ndarray, int16, array, int32, int64, single, double, uint8, int8, uint16, bool8 +from numpy import ndarray, int16, array, int32, int64, single, double, uint8, int8, uint16 from trsfile.traceparameter import BooleanArrayParameter, ByteArrayParameter, DoubleArrayParameter, FloatArrayParameter, \ IntegerArrayParameter, ShortArrayParameter, LongArrayParameter, StringParameter @@ -13,8 +13,8 @@ def test_bool_parameter(self): param1 = BooleanArrayParameter([True, False, True]) self.assertEqual(serialized_param, param1.serialize()) self.assertEqual(BooleanArrayParameter.deserialize(BytesIO(serialized_param), 3), param1) - param2 = BooleanArrayParameter(ndarray(shape=[3], dtype=bool8, - buffer=array([bool8(val) for val in [True, False, True]]))) + param2 = BooleanArrayParameter(ndarray(shape=[3], dtype=bool, + buffer=array([bool(val) for val in [True, False, True]]))) self.assertEqual(param1, param2) with self.assertRaises(TypeError): diff --git a/trsfile/traceparameter.py b/trsfile/traceparameter.py index 494115d..03a80a1 100644 --- a/trsfile/traceparameter.py +++ b/trsfile/traceparameter.py @@ -7,7 +7,8 @@ from io import BytesIO from typing import Any -from numpy import ndarray, integer, bool8, uint8, double, single +import numpy +from numpy import ndarray, integer, uint8, double, single from trsfile.utils import encode_as_short, read_short @@ -75,7 +76,7 @@ def deserialize(io_bytes: BytesIO) -> TraceSetParameter: class BooleanArrayParameter(TraceParameter): - _expected_type_string = "List[bool] or ndarray[bool8]" + _expected_type_string = "List[bool] or ndarray[bool]" def __len__(self): return len(bytes(self.value)) @@ -96,7 +97,7 @@ def _has_expected_type(value: Any) -> bool: if type(value) is list: return all(isinstance(elem, bool) for elem in value) elif type(value) is ndarray: - return all(isinstance(elem, bool8) for elem in value) + return all(isinstance(elem, numpy.bool) for elem in value) return False From eb5c3deaf896859359d30f001ce5b720edb66606 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Tue, 18 Jun 2024 16:38:03 +0200 Subject: [PATCH 2/3] Fixup test_parameter.py --- tests/test_parameter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_parameter.py b/tests/test_parameter.py index a45a37a..05ae071 100644 --- a/tests/test_parameter.py +++ b/tests/test_parameter.py @@ -47,10 +47,10 @@ def test_byte_parameter(self): ByteArrayParameter([0, '1']) with self.assertRaises(TypeError): ByteArrayParameter([bytes([0, 1, 2, 3]), bytes([4, 5, 6, 7])]) + with self.assertRaises(OverflowError): + ByteArrayParameter(ndarray(shape=[16], dtype=int8, buffer=array(int_data, dtype=int8))) with self.assertRaises(TypeError): - ByteArrayParameter(ndarray(shape=[16], dtype=int8, buffer=array([int8(val) for val in int_data]))) - with self.assertRaises(TypeError): - ByteArrayParameter(ndarray(shape=[16], dtype=uint16, buffer=array([uint16(val) for val in int_data]))) + ByteArrayParameter(ndarray(shape=[16], dtype=uint16, buffer=array(int_data, dtype=uint16))) with self.assertRaises(ValueError): ByteArrayParameter([]) with self.assertRaises(ValueError): From 3e55d2de4a51d6a9d2ebe22dfab24e8ee6b69351 Mon Sep 17 00:00:00 2001 From: Matthijs Geers Date: Thu, 20 Mar 2025 11:16:05 +0100 Subject: [PATCH 3/3] Fixup numpy bool deprecation --- trsfile/traceparameter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/trsfile/traceparameter.py b/trsfile/traceparameter.py index 03a80a1..51b5184 100644 --- a/trsfile/traceparameter.py +++ b/trsfile/traceparameter.py @@ -7,7 +7,6 @@ from io import BytesIO from typing import Any -import numpy from numpy import ndarray, integer, uint8, double, single from trsfile.utils import encode_as_short, read_short @@ -97,7 +96,7 @@ def _has_expected_type(value: Any) -> bool: if type(value) is list: return all(isinstance(elem, bool) for elem in value) elif type(value) is ndarray: - return all(isinstance(elem, numpy.bool) for elem in value) + return value.dtype == bool return False