Skip to content

Commit 1ed54d1

Browse files
authored
Merge pull request #50 from Keysight/feature/numpy-v2
Make the library compatible with numpy >= v1.24 and < v3
2 parents a16caf3 + 3e55d2d commit 1ed54d1

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ packages =
3030
trsfile.engine
3131
trsfile.converters
3232
install_requires =
33-
numpy>=1,<2
33+
numpy>=1.24,<3
3434
include_package_data = True
3535

3636
[options.extras_require]

tests/test_parameter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from io import BytesIO
22
from unittest import TestCase
33

4-
from numpy import ndarray, int16, array, int32, int64, single, double, uint8, int8, uint16, bool8
4+
from numpy import ndarray, int16, array, int32, int64, single, double, uint8, int8, uint16
55

66
from trsfile.traceparameter import BooleanArrayParameter, ByteArrayParameter, DoubleArrayParameter, FloatArrayParameter, \
77
IntegerArrayParameter, ShortArrayParameter, LongArrayParameter, StringParameter
@@ -13,8 +13,8 @@ def test_bool_parameter(self):
1313
param1 = BooleanArrayParameter([True, False, True])
1414
self.assertEqual(serialized_param, param1.serialize())
1515
self.assertEqual(BooleanArrayParameter.deserialize(BytesIO(serialized_param), 3), param1)
16-
param2 = BooleanArrayParameter(ndarray(shape=[3], dtype=bool8,
17-
buffer=array([bool8(val) for val in [True, False, True]])))
16+
param2 = BooleanArrayParameter(ndarray(shape=[3], dtype=bool,
17+
buffer=array([bool(val) for val in [True, False, True]])))
1818
self.assertEqual(param1, param2)
1919

2020
with self.assertRaises(TypeError):
@@ -47,10 +47,10 @@ def test_byte_parameter(self):
4747
ByteArrayParameter([0, '1'])
4848
with self.assertRaises(TypeError):
4949
ByteArrayParameter([bytes([0, 1, 2, 3]), bytes([4, 5, 6, 7])])
50+
with self.assertRaises(OverflowError):
51+
ByteArrayParameter(ndarray(shape=[16], dtype=int8, buffer=array(int_data, dtype=int8)))
5052
with self.assertRaises(TypeError):
51-
ByteArrayParameter(ndarray(shape=[16], dtype=int8, buffer=array([int8(val) for val in int_data])))
52-
with self.assertRaises(TypeError):
53-
ByteArrayParameter(ndarray(shape=[16], dtype=uint16, buffer=array([uint16(val) for val in int_data])))
53+
ByteArrayParameter(ndarray(shape=[16], dtype=uint16, buffer=array(int_data, dtype=uint16)))
5454
with self.assertRaises(ValueError):
5555
ByteArrayParameter([])
5656
with self.assertRaises(ValueError):

trsfile/traceparameter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from io import BytesIO
88
from typing import Any
99

10-
from numpy import ndarray, integer, bool8, uint8, double, single
10+
from numpy import ndarray, integer, uint8, double, single
1111

1212
from trsfile.utils import encode_as_short, read_short
1313

@@ -75,7 +75,7 @@ def deserialize(io_bytes: BytesIO) -> TraceSetParameter:
7575

7676

7777
class BooleanArrayParameter(TraceParameter):
78-
_expected_type_string = "List[bool] or ndarray[bool8]"
78+
_expected_type_string = "List[bool] or ndarray[bool]"
7979

8080
def __len__(self):
8181
return len(bytes(self.value))
@@ -96,7 +96,7 @@ def _has_expected_type(value: Any) -> bool:
9696
if type(value) is list:
9797
return all(isinstance(elem, bool) for elem in value)
9898
elif type(value) is ndarray:
99-
return all(isinstance(elem, bool8) for elem in value)
99+
return value.dtype == bool
100100
return False
101101

102102

0 commit comments

Comments
 (0)