Skip to content

Commit 1297fd3

Browse files
committed
Widen Array1D to fix changes to numpy shape
numpy/numpy#28077 (comment)
1 parent 5712705 commit 1297fd3

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/ophyd_async/core/_signal_backend.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from ._utils import Callback, StrictEnum, T
1111

1212
DTypeScalar_co = TypeVar("DTypeScalar_co", covariant=True, bound=np.generic)
13-
Array1D = np.ndarray[tuple[int], np.dtype[DTypeScalar_co]]
13+
# To be a 1D array shape should really be tuple[int], but np.array()
14+
# currently produces tuple[int, ...] even when it has 1D input args
15+
# https://github.com/numpy/numpy/issues/28077#issuecomment-2566485178
16+
Array1D = np.ndarray[tuple[int, ...], np.dtype[DTypeScalar_co]]
1417
Primitive = bool | int | float | str
1518
# NOTE: if you change this union then update the docs to match
1619
SignalDatatype = (

‎src/ophyd_async/core/_table.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def numpy_table(self, selection: slice | None = None) -> np.ndarray:
101101
v = v[selection]
102102
if array is None:
103103
array = np.empty(v.shape, dtype=self.numpy_dtype())
104-
array[k] = v
104+
array[k] = v # type: ignore
105105
if array is None:
106106
msg = "No arrays found in table"
107107
raise ValueError(msg)

‎tests/core/test_soft_signal_backend.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ async def test_soft_signal_backend_set_callback():
148148
async def test_soft_signal_backend_with_numpy_typing():
149149
soft_backend = SoftSignalBackend(Array1D[np.float64])
150150
await soft_backend.connect(timeout=1)
151+
await soft_backend.put(np.array([1, 2]), wait=True)
151152
array = await soft_backend.get_value()
152-
assert array.shape == (0,)
153+
assert array.shape == (2,)
154+
assert array[0] == 1
153155

154156

155157
async def test_soft_signal_descriptor_fails_for_invalid_class():

‎tests/core/test_table.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class MyTable(Table):
3333
{"bool": [0, 1], "uint": [3, 4], "str": [44, ""]},
3434
"Input should be a valid string [type=string_type, input_value=44,",
3535
),
36+
(
37+
{"bool": [0, 1], "uint": [[3], [4]], "str": ["", ""]},
38+
"Array 2-dimensional; the target dimensions is 1",
39+
),
3640
],
3741
)
3842
def test_table_wrong_types(kwargs, error_msg):

0 commit comments

Comments
 (0)