Skip to content

Commit 6bf791a

Browse files
committed
Use a named tuple for the packed parameters
1 parent ac50046 commit 6bf791a

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

Tests/test_pyarrow.py

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any # undone
3+
from typing import Any, NamedTuple
44

55
import pytest
66

@@ -151,29 +151,37 @@ def test_lifetime2() -> None:
151151
assert isinstance(px[0, 0], int)
152152

153153

154-
UINT_ARR = (
155-
fl_uint8_4_type,
156-
[1,2,3,4],
157-
1
154+
class DataShape(NamedTuple):
155+
dtype: Any
156+
elt: Any
157+
elts_per_pixel: int
158+
159+
160+
UINT_ARR = DataShape(
161+
dtype=fl_uint8_4_type,
162+
elt=[1, 2, 3, 4], # array of 4 uint 8 per pixel
163+
elts_per_pixel=1, # only one array per pixel
158164
)
159-
UINT = (
160-
pyarrow.uint8(),
161-
3,
162-
4
165+
166+
UINT = DataShape(
167+
dtype=pyarrow.uint8(),
168+
elt=3, # one uint8,
169+
elts_per_pixel=4, # but repeated 4x per pixel
163170
)
164-
INT32 = (
165-
pyarrow.uint32(),
166-
0xabcdef45,
167-
1
171+
172+
UINT32 = DataShape(
173+
dtype=pyarrow.uint32(),
174+
elt=0xABCDEF45, # one packed int, doesn't fit in a int32 > 0x80000000
175+
elts_per_pixel=1, # one per pixel
168176
)
169177

170178

171179
@pytest.mark.parametrize(
172180
"mode, data_tp, mask",
173181
(
174-
("L", (pyarrow.uint8(), 3, 1), None),
175-
("I", (pyarrow.int32(), 1 << 24, 1), None),
176-
("F", (pyarrow.float32(), 3.14159, 1), None),
182+
("L", DataShape(pyarrow.uint8(), 3, 1), None),
183+
("I", DataShape(pyarrow.int32(), 1 << 24, 1), None),
184+
("F", DataShape(pyarrow.float32(), 3.14159, 1), None),
177185
("LA", UINT_ARR, [0, 3]),
178186
("LA", UINT, [0, 3]),
179187
("RGB", UINT_ARR, [0, 1, 2]),
@@ -188,7 +196,7 @@ def test_lifetime2() -> None:
188196
("HSV", UINT, [0, 1, 2]),
189197
),
190198
)
191-
def test_fromarray(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
199+
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
192200
(dtype, elt, elts_per_pixel) = data_tp
193201

194202
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
@@ -201,15 +209,15 @@ def test_fromarray(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
201209
@pytest.mark.parametrize(
202210
"mode, data_tp, mask",
203211
(
204-
("LA", INT32, [0, 3]),
205-
("RGB", INT32, [0, 1, 2]),
206-
("RGBA", INT32, None),
207-
("CMYK", INT32, None),
208-
("YCbCr", INT32, [0, 1, 2]),
209-
("HSV", INT32, [0, 1, 2]),
212+
("LA", UINT32, [0, 3]),
213+
("RGB", UINT32, [0, 1, 2]),
214+
("RGBA", UINT32, None),
215+
("CMYK", UINT32, None),
216+
("YCbCr", UINT32, [0, 1, 2]),
217+
("HSV", UINT32, [0, 1, 2]),
210218
),
211219
)
212-
def test_from_int32array(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
220+
def test_from_int32array(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
213221
(dtype, elt, elts_per_pixel) = data_tp
214222

215223
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]

0 commit comments

Comments
 (0)