Skip to content

Commit ac50046

Browse files
committed
lint
1 parent c729d4e commit ac50046

2 files changed

Lines changed: 23 additions & 31 deletions

File tree

Tests/test_pyarrow.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from .helper import (
1010
assert_deep_equal,
1111
assert_image_equal,
12-
is_big_endian,
1312
hopper,
13+
is_big_endian,
1414
)
1515

1616
pyarrow = pytest.importorskip("pyarrow", reason="PyArrow not installed")
@@ -37,7 +37,10 @@ def _test_img_equals_pyarray(
3737
if elts_per_pixel == 1:
3838
assert pixel[ix] == arr[y * img.width + x].as_py()[elt]
3939
else:
40-
assert pixel[ix] == arr[(y * img.width + x) * elts_per_pixel + elt].as_py()
40+
assert (
41+
pixel[ix]
42+
== arr[(y * img.width + x) * elts_per_pixel + elt].as_py()
43+
)
4144
else:
4245
assert_deep_equal(px[x, y], arr[y * img.width + x].as_py())
4346

@@ -169,33 +172,27 @@ def test_lifetime2() -> None:
169172
"mode, data_tp, mask",
170173
(
171174
("L", (pyarrow.uint8(), 3, 1), None),
172-
("I", (pyarrow.int32(), 1<<24, 1), None),
175+
("I", (pyarrow.int32(), 1 << 24, 1), None),
173176
("F", (pyarrow.float32(), 3.14159, 1), None),
174177
("LA", UINT_ARR, [0, 3]),
175178
("LA", UINT, [0, 3]),
176179
("RGB", UINT_ARR, [0, 1, 2]),
177180
("RGBA", UINT_ARR, None),
178-
("RGBA", UINT_ARR, None),
179181
("CMYK", UINT_ARR, None),
180-
("YCbCr", UINT_ARR, [0, 1, 2]),
181-
("HSV", UINT_ARR, [0, 1, 2]),
182+
("YCbCr", UINT_ARR, [0, 1, 2]),
183+
("HSV", UINT_ARR, [0, 1, 2]),
182184
("RGB", UINT, [0, 1, 2]),
183185
("RGBA", UINT, None),
184-
("RGBA", UINT, None),
185186
("CMYK", UINT, None),
186-
("YCbCr", UINT, [0, 1, 2]),
187-
("HSV", UINT, [0, 1, 2]),
187+
("YCbCr", UINT, [0, 1, 2]),
188+
("HSV", UINT, [0, 1, 2]),
188189
),
189190
)
190-
def test_fromarray(mode: str,
191-
data_tp: tuple,
192-
mask:list[int] | None) -> None:
193-
(dtype,
194-
elt,
195-
elts_per_pixel) = data_tp
191+
def test_fromarray(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
192+
(dtype, elt, elts_per_pixel) = data_tp
196193

197194
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
198-
arr = pyarrow.array([elt]*(ct_pixels*elts_per_pixel), type=dtype)
195+
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
199196
img = Image.fromarrow(arr, mode, TEST_IMAGE_SIZE)
200197

201198
_test_img_equals_pyarray(img, arr, mask, elts_per_pixel)
@@ -207,21 +204,16 @@ def test_fromarray(mode: str,
207204
("LA", INT32, [0, 3]),
208205
("RGB", INT32, [0, 1, 2]),
209206
("RGBA", INT32, None),
210-
("RGBA", INT32, None),
211207
("CMYK", INT32, None),
212-
("YCbCr", INT32, [0, 1, 2]),
213-
("HSV", INT32, [0, 1, 2]),
208+
("YCbCr", INT32, [0, 1, 2]),
209+
("HSV", INT32, [0, 1, 2]),
214210
),
215211
)
216-
def test_from_int32array(mode: str,
217-
data_tp: tuple,
218-
mask:list[int] | None) -> None:
219-
(dtype,
220-
elt,
221-
elts_per_pixel) = data_tp
212+
def test_from_int32array(mode: str, data_tp: tuple, mask: list[int] | None) -> None:
213+
(dtype, elt, elts_per_pixel) = data_tp
222214

223215
ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
224-
arr = pyarrow.array([elt]*(ct_pixels*elts_per_pixel), type=dtype)
216+
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
225217
img = Image.fromarrow(arr, mode, TEST_IMAGE_SIZE)
226218

227219
_test_img_equals_int32_pyarray(img, arr, mask, elts_per_pixel)

src/libImaging/Storage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,11 @@ ImagingNewArrow(
754754
}
755755
}
756756
// Stored as [r,g,b,a,r,g,b,a....]
757-
if (strcmp(schema->format, "C") == 0 // uint8
758-
&& im->pixelsize == 4 // storage as 32 bpc
759-
&& schema->n_children == 0 // make sure schema is well formed.
760-
&& strcmp(im->arrow_band_format, "C") == 0 // Expected Format
761-
&& 4* pixels == external_array->length) { // expected length
757+
if (strcmp(schema->format, "C") == 0 // uint8
758+
&& im->pixelsize == 4 // storage as 32 bpc
759+
&& schema->n_children == 0 // make sure schema is well formed.
760+
&& strcmp(im->arrow_band_format, "C") == 0 // Expected Format
761+
&& 4 * pixels == external_array->length) { // expected length
762762
// single flat array, interleaved storage.
763763
if (ImagingBorrowArrow(im, external_array, 1, array_capsule)) {
764764
return im;

0 commit comments

Comments
 (0)