Skip to content

Commit 90b8cd7

Browse files
authored
fix: Make type hints compatible with numpy >= 2.4.x (#260)
* chore(deps): Update numpy to 2.4.2 * fix: npt.DTypeLike no longer includes None * fix: Use separate variables to store reshaped NumPy arrays
1 parent 3304c17 commit 90b8cd7

File tree

9 files changed

+117
-119
lines changed

9 files changed

+117
-119
lines changed

poetry.lock

Lines changed: 73 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nitypes/_numpy1x.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
def asarray( # noqa: D103 - missing docstring in public function
35-
a: npt.ArrayLike, dtype: npt.DTypeLike = None, *, copy: builtins.bool | None = None
35+
a: npt.ArrayLike, dtype: npt.DTypeLike | None = None, *, copy: builtins.bool | None = None
3636
) -> npt.NDArray[Any]:
3737
b = np.asarray(a, dtype)
3838
made_copy = b is not a and b.base is None

src/nitypes/waveform/_analog.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def from_array_1d(
255255
def from_array_1d(
256256
cls,
257257
array: npt.NDArray[Any] | Sequence[Any],
258-
dtype: npt.DTypeLike = ...,
258+
dtype: npt.DTypeLike | None = ...,
259259
*,
260260
copy: bool = ...,
261261
start_index: SupportsIndex | None = ...,
@@ -270,7 +270,7 @@ def from_array_1d(
270270
def from_array_1d( # pyright: ignore[reportIncompatibleMethodOverride]
271271
cls,
272272
array: npt.NDArray[Any] | Sequence[Any],
273-
dtype: npt.DTypeLike = None,
273+
dtype: npt.DTypeLike | None = None,
274274
*,
275275
copy: bool = True,
276276
start_index: SupportsIndex | None = 0,
@@ -341,7 +341,7 @@ def from_array_2d(
341341
def from_array_2d(
342342
cls,
343343
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
344-
dtype: npt.DTypeLike = ...,
344+
dtype: npt.DTypeLike | None = ...,
345345
*,
346346
copy: bool = ...,
347347
start_index: SupportsIndex | None = ...,
@@ -356,7 +356,7 @@ def from_array_2d(
356356
def from_array_2d( # pyright: ignore[reportIncompatibleMethodOverride]
357357
cls,
358358
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
359-
dtype: npt.DTypeLike = None,
359+
dtype: npt.DTypeLike | None = None,
360360
*,
361361
copy: bool = True,
362362
start_index: SupportsIndex | None = 0,
@@ -448,7 +448,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
448448
def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa)
449449
self: AnalogWaveform[Any],
450450
sample_count: SupportsIndex | None = ...,
451-
dtype: npt.DTypeLike = ...,
451+
dtype: npt.DTypeLike | None = ...,
452452
*,
453453
raw_data: npt.NDArray[Any] | None = ...,
454454
start_index: SupportsIndex | None = ...,
@@ -462,7 +462,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
462462
def __init__(
463463
self,
464464
sample_count: SupportsIndex | None = None,
465-
dtype: npt.DTypeLike = None,
465+
dtype: npt.DTypeLike | None = None,
466466
*,
467467
raw_data: npt.NDArray[Any] | None = None,
468468
start_index: SupportsIndex | None = None,

src/nitypes/waveform/_complex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def from_array_1d(
159159
def from_array_1d(
160160
cls,
161161
array: npt.NDArray[Any] | Sequence[Any],
162-
dtype: npt.DTypeLike = ...,
162+
dtype: npt.DTypeLike | None = ...,
163163
*,
164164
copy: bool = ...,
165165
start_index: SupportsIndex | None = ...,
@@ -174,7 +174,7 @@ def from_array_1d(
174174
def from_array_1d( # pyright: ignore[reportIncompatibleMethodOverride]
175175
cls,
176176
array: npt.NDArray[Any] | Sequence[Any],
177-
dtype: npt.DTypeLike = None,
177+
dtype: npt.DTypeLike | None = None,
178178
*,
179179
copy: bool = True,
180180
start_index: SupportsIndex | None = 0,
@@ -245,7 +245,7 @@ def from_array_2d(
245245
def from_array_2d(
246246
cls,
247247
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
248-
dtype: npt.DTypeLike = ...,
248+
dtype: npt.DTypeLike | None = ...,
249249
*,
250250
copy: bool = ...,
251251
start_index: SupportsIndex | None = ...,
@@ -260,7 +260,7 @@ def from_array_2d(
260260
def from_array_2d( # pyright: ignore[reportIncompatibleMethodOverride]
261261
cls,
262262
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
263-
dtype: npt.DTypeLike = None,
263+
dtype: npt.DTypeLike | None = None,
264264
*,
265265
copy: bool = True,
266266
start_index: SupportsIndex | None = 0,
@@ -352,7 +352,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
352352
def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa)
353353
self: ComplexWaveform[Any],
354354
sample_count: SupportsIndex | None = ...,
355-
dtype: npt.DTypeLike = ...,
355+
dtype: npt.DTypeLike | None = ...,
356356
*,
357357
raw_data: npt.NDArray[Any] | None = ...,
358358
start_index: SupportsIndex | None = ...,
@@ -366,7 +366,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
366366
def __init__(
367367
self,
368368
sample_count: SupportsIndex | None = None,
369-
dtype: npt.DTypeLike = None,
369+
dtype: npt.DTypeLike | None = None,
370370
*,
371371
raw_data: npt.NDArray[Any] | None = None,
372372
start_index: SupportsIndex | None = None,

src/nitypes/waveform/_digital/_port.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ def port_to_line_data(
121121
if bitorder != sys.byteorder and port_data.dtype.itemsize > 1:
122122
port_data = port_data.byteswap()
123123

124-
line_data = np.unpackbits(port_data.view(np.uint8), bitorder=bitorder)
125-
line_data = line_data.reshape(len(port_data), port_size)
124+
line_data_1d = np.unpackbits(port_data.view(np.uint8), bitorder=bitorder)
125+
line_data_2d = line_data_1d.reshape(len(port_data), port_size)
126126

127127
if mask == bit_mask(port_size):
128-
return line_data
128+
return line_data_2d
129129
else:
130-
return line_data[:, _mask_to_column_indices(mask, port_size, bitorder)]
130+
return line_data_2d[:, _mask_to_column_indices(mask, port_size, bitorder)]
131131

132132

133133
def _mask_to_column_indices(

src/nitypes/waveform/_digital/_waveform.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def from_lines(
323323
def from_lines(
324324
cls,
325325
array: npt.NDArray[Any] | Sequence[Any],
326-
dtype: npt.DTypeLike = ...,
326+
dtype: npt.DTypeLike | None = ...,
327327
*,
328328
copy: bool = ...,
329329
start_index: SupportsIndex | None = ...,
@@ -337,7 +337,7 @@ def from_lines(
337337
def from_lines(
338338
cls,
339339
array: npt.NDArray[Any] | Sequence[Any],
340-
dtype: npt.DTypeLike = None,
340+
dtype: npt.DTypeLike | None = None,
341341
*,
342342
copy: bool = True,
343343
start_index: SupportsIndex | None = 0,
@@ -433,7 +433,7 @@ def from_port(
433433
cls,
434434
array: npt.NDArray[Any] | Sequence[Any],
435435
mask: SupportsIndex | None = ...,
436-
dtype: npt.DTypeLike = ...,
436+
dtype: npt.DTypeLike | None = ...,
437437
*,
438438
bitorder: Literal["big", "little"] = ...,
439439
start_index: SupportsIndex | None = ...,
@@ -447,7 +447,7 @@ def from_port(
447447
cls,
448448
array: npt.NDArray[Any] | Sequence[Any],
449449
mask: SupportsIndex | None = None,
450-
dtype: npt.DTypeLike = None,
450+
dtype: npt.DTypeLike | None = None,
451451
*,
452452
bitorder: Literal["big", "little"] = "big",
453453
start_index: SupportsIndex | None = 0,
@@ -575,7 +575,7 @@ def from_ports(
575575
cls,
576576
array: npt.NDArray[Any] | Sequence[Any],
577577
masks: Sequence[SupportsIndex] | None = ...,
578-
dtype: npt.DTypeLike = ...,
578+
dtype: npt.DTypeLike | None = ...,
579579
*,
580580
bitorder: Literal["big", "little"] = ...,
581581
start_index: SupportsIndex | None = ...,
@@ -589,7 +589,7 @@ def from_ports(
589589
cls,
590590
array: npt.NDArray[Any] | Sequence[Any],
591591
masks: Sequence[SupportsIndex] | None = None,
592-
dtype: npt.DTypeLike = None,
592+
dtype: npt.DTypeLike | None = None,
593593
*,
594594
bitorder: Literal["big", "little"] = "big",
595595
start_index: SupportsIndex | None = 0,
@@ -765,7 +765,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
765765
self: DigitalWaveform[Any],
766766
sample_count: SupportsIndex | None = ...,
767767
signal_count: SupportsIndex | None = ...,
768-
dtype: npt.DTypeLike = ...,
768+
dtype: npt.DTypeLike | None = ...,
769769
default_value: bool | int | DigitalState | None = ...,
770770
*,
771771
data: npt.NDArray[Any] | None = ...,
@@ -780,7 +780,7 @@ def __init__(
780780
self,
781781
sample_count: SupportsIndex | None = None,
782782
signal_count: SupportsIndex | None = None,
783-
dtype: npt.DTypeLike = None,
783+
dtype: npt.DTypeLike | None = None,
784784
default_value: bool | int | DigitalState | None = None,
785785
*,
786786
data: npt.NDArray[Any] | None = None,
@@ -860,7 +860,7 @@ def _init_with_new_array(
860860
self,
861861
sample_count: SupportsIndex | None = None,
862862
signal_count: SupportsIndex | None = None,
863-
dtype: npt.DTypeLike = None,
863+
dtype: npt.DTypeLike | None = None,
864864
default_value: bool | int | DigitalState | None = None,
865865
*,
866866
start_index: SupportsIndex | None = None,
@@ -895,7 +895,7 @@ def _init_with_new_array(
895895
def _init_with_provided_array(
896896
self,
897897
data: npt.NDArray[TDigitalState],
898-
dtype: npt.DTypeLike = None,
898+
dtype: npt.DTypeLike | None = None,
899899
*,
900900
start_index: SupportsIndex | None = None,
901901
sample_count: SupportsIndex | None = None,

src/nitypes/waveform/_numeric.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _get_supported_scaled_dtypes() -> tuple[npt.DTypeLike, ...]:
9696
def from_array_1d(
9797
cls,
9898
array: npt.NDArray[Any] | Sequence[Any],
99-
dtype: npt.DTypeLike = None,
99+
dtype: npt.DTypeLike | None = None,
100100
*,
101101
copy: bool = True,
102102
start_index: SupportsIndex | None = 0,
@@ -147,7 +147,7 @@ def from_array_1d(
147147
def from_array_2d(
148148
cls,
149149
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
150-
dtype: npt.DTypeLike = None,
150+
dtype: npt.DTypeLike | None = None,
151151
*,
152152
copy: bool = True,
153153
start_index: SupportsIndex | None = 0,
@@ -221,7 +221,7 @@ def from_array_2d(
221221
def __init__(
222222
self,
223223
sample_count: SupportsIndex | None = None,
224-
dtype: npt.DTypeLike = None,
224+
dtype: npt.DTypeLike | None = None,
225225
*,
226226
raw_data: npt.NDArray[_TRaw] | None = None,
227227
start_index: SupportsIndex | None = None,
@@ -284,7 +284,7 @@ def __init__(
284284
def _init_with_new_array(
285285
self,
286286
sample_count: SupportsIndex | None = None,
287-
dtype: npt.DTypeLike = None,
287+
dtype: npt.DTypeLike | None = None,
288288
*,
289289
start_index: SupportsIndex | None = None,
290290
capacity: SupportsIndex | None = None,
@@ -311,7 +311,7 @@ def _init_with_new_array(
311311
def _init_with_provided_array(
312312
self,
313313
data: npt.NDArray[_TRaw],
314-
dtype: npt.DTypeLike = None,
314+
dtype: npt.DTypeLike | None = None,
315315
*,
316316
start_index: SupportsIndex | None = None,
317317
sample_count: SupportsIndex | None = None,
@@ -420,7 +420,7 @@ def get_scaled_data( # noqa: D107 - Missing docstring in __init__ (auto-generat
420420

421421
def get_scaled_data(
422422
self,
423-
dtype: npt.DTypeLike = None,
423+
dtype: npt.DTypeLike | None = None,
424424
*,
425425
start_index: SupportsIndex | None = 0,
426426
sample_count: SupportsIndex | None = None,

src/nitypes/waveform/_spectrum.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def from_array_1d(
139139
def from_array_1d(
140140
cls,
141141
array: npt.NDArray[Any] | Sequence[Any],
142-
dtype: npt.DTypeLike = ...,
142+
dtype: npt.DTypeLike | None = ...,
143143
*,
144144
copy: bool = ...,
145145
start_index: SupportsIndex | None = ...,
@@ -153,7 +153,7 @@ def from_array_1d(
153153
def from_array_1d(
154154
cls,
155155
array: npt.NDArray[Any] | Sequence[Any],
156-
dtype: npt.DTypeLike = None,
156+
dtype: npt.DTypeLike | None = None,
157157
*,
158158
copy: bool = True,
159159
start_index: SupportsIndex | None = 0,
@@ -235,7 +235,7 @@ def from_array_2d(
235235
def from_array_2d(
236236
cls,
237237
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
238-
dtype: npt.DTypeLike = ...,
238+
dtype: npt.DTypeLike | None = ...,
239239
*,
240240
copy: bool = ...,
241241
start_index: SupportsIndex | None = ...,
@@ -249,7 +249,7 @@ def from_array_2d(
249249
def from_array_2d(
250250
cls,
251251
array: npt.NDArray[Any] | Sequence[Sequence[Any]],
252-
dtype: npt.DTypeLike = None,
252+
dtype: npt.DTypeLike | None = None,
253253
*,
254254
copy: bool = True,
255255
start_index: SupportsIndex | None = 0,
@@ -370,7 +370,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
370370
def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa)
371371
self: Spectrum[Any],
372372
sample_count: SupportsIndex | None = ...,
373-
dtype: npt.DTypeLike = ...,
373+
dtype: npt.DTypeLike | None = ...,
374374
*,
375375
data: npt.NDArray[Any] | None = ...,
376376
start_index: SupportsIndex | None = ...,
@@ -384,7 +384,7 @@ def __init__( # noqa: D107 - Missing docstring in __init__ (auto-generated noqa
384384
def __init__(
385385
self,
386386
sample_count: SupportsIndex | None = None,
387-
dtype: npt.DTypeLike = None,
387+
dtype: npt.DTypeLike | None = None,
388388
*,
389389
data: npt.NDArray[Any] | None = None,
390390
start_index: SupportsIndex | None = None,
@@ -442,7 +442,7 @@ def __init__(
442442
def _init_with_new_array(
443443
self,
444444
sample_count: SupportsIndex | None = None,
445-
dtype: npt.DTypeLike = None,
445+
dtype: npt.DTypeLike | None = None,
446446
*,
447447
start_index: SupportsIndex | None = None,
448448
capacity: SupportsIndex | None = None,
@@ -469,7 +469,7 @@ def _init_with_new_array(
469469
def _init_with_provided_array(
470470
self,
471471
data: npt.NDArray[_TData],
472-
dtype: npt.DTypeLike = None,
472+
dtype: npt.DTypeLike | None = None,
473473
*,
474474
start_index: SupportsIndex | None = None,
475475
sample_count: SupportsIndex | None = None,

src/nitypes/xy_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def from_arrays_1d(
127127
cls,
128128
x_array: npt.NDArray[Any] | Sequence[Any],
129129
y_array: npt.NDArray[Any] | Sequence[Any],
130-
dtype: npt.DTypeLike = ...,
130+
dtype: npt.DTypeLike | None = ...,
131131
*,
132132
x_units: str = ...,
133133
y_units: str = ...,
@@ -140,7 +140,7 @@ def from_arrays_1d(
140140
cls,
141141
x_array: npt.NDArray[Any] | Sequence[Any],
142142
y_array: npt.NDArray[Any] | Sequence[Any],
143-
dtype: npt.DTypeLike = None,
143+
dtype: npt.DTypeLike | None = None,
144144
*,
145145
x_units: str = "",
146146
y_units: str = "",
@@ -264,7 +264,7 @@ def _init_with_provided_arrays(
264264
self,
265265
x_data: npt.NDArray[TData],
266266
y_data: npt.NDArray[TData],
267-
dtype: npt.DTypeLike = None,
267+
dtype: npt.DTypeLike | None = None,
268268
) -> None:
269269
if not isinstance(x_data, np.ndarray):
270270
raise invalid_arg_type("x-axis input array", "one-dimensional array", x_data)

0 commit comments

Comments
 (0)