[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2025-01-25 16:25:41 +00:00
parent ad492ee4d8
commit d02417e411
2 changed files with 31 additions and 31 deletions

View File

@ -68,6 +68,7 @@ def test_to_array(mode: str, dtype: Any, mask: Any) -> None:
assert_image_equal(img, reloaded) assert_image_equal(img, reloaded)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"mode, dest_modes", "mode, dest_modes",
( (
@ -89,12 +90,13 @@ def test_invalid_array_type(mode: str, dest_modes: List[str]) -> None:
with pytest.raises(ValueError): with pytest.raises(ValueError):
Image.fromarrow(img, dest_mode, img.size) Image.fromarrow(img, dest_mode, img.size)
def test_invalid_array_size(): def test_invalid_array_size():
img = hopper('RGB') img = hopper("RGB")
assert img.size != (10, 10) assert img.size != (10, 10)
with pytest.raises(ValueError): with pytest.raises(ValueError):
Image.fromarrow(img, 'RGB', (10,10)) Image.fromarrow(img, "RGB", (10, 10))
def test_lifetime(): def test_lifetime():
@ -137,20 +139,21 @@ def test_lifetime2():
def test_release_schema(): def test_release_schema():
# these should not error out, valgrind should be clean # these should not error out, valgrind should be clean
img = hopper('L') img = hopper("L")
schema = img.__arrow_c_schema__() schema = img.__arrow_c_schema__()
del(schema) del schema
def test_release_array(): def test_release_array():
# these should not error out, valgrind should be clean # these should not error out, valgrind should be clean
img = hopper('L') img = hopper("L")
array, schema = img.__arrow_c_array__() array, schema = img.__arrow_c_array__()
del(array) del array
del(schema) del schema
def test_readonly(): def test_readonly():
img = hopper('L') img = hopper("L")
reloaded = Image.fromarrow(img, img.mode, img.size) reloaded = Image.fromarrow(img, img.mode, img.size)
assert reloaded.readonly == 1 assert reloaded.readonly == 1
reloaded._readonly = 0 reloaded._readonly = 0

View File

@ -571,9 +571,7 @@ ImagingDestroyArrow(Imaging im) {
} }
Imaging Imaging
ImagingBorrowArrow(Imaging im, ImagingBorrowArrow(Imaging im, struct ArrowArray *external_array, int offset_width) {
struct ArrowArray *external_array,
int offset_width) {
// offset_width is the # of char* for a single offset from arrow // offset_width is the # of char* for a single offset from arrow
Py_ssize_t y, i; Py_ssize_t y, i;
@ -590,7 +588,8 @@ ImagingBorrowArrow(Imaging im,
} }
if (!borrowed_buffer) { if (!borrowed_buffer) {
return (Imaging)ImagingError_ValueError("Arrow Array, exactly 2 buffers required"); return (Imaging
)ImagingError_ValueError("Arrow Array, exactly 2 buffers required");
} }
for (y = i = 0; y < im->ysize; y++) { for (y = i = 0; y < im->ysize; y++) {
@ -698,12 +697,10 @@ ImagingNewArrow(
int64_t pixels = (int64_t)xsize * (int64_t)ysize; int64_t pixels = (int64_t)xsize * (int64_t)ysize;
// fmt:off // don't reformat this // fmt:off // don't reformat this
if (((strcmp(schema->format, "I") == 0 if (((strcmp(schema->format, "I") == 0 && im->pixelsize == 4 && im->bands >= 2
&& im->pixelsize == 4 ) // INT32 into any INT32 Storage mode
&& im->bands >= 2) // INT32 into any INT32 Storage mode || (strcmp(schema->format, im->arrow_band_format) == 0 && im->bands == 1)
|| ) // Single band match
(strcmp(schema->format, im->arrow_band_format) == 0
&& im->bands == 1)) // Single band match
&& pixels == external_array->length) { && pixels == external_array->length) {
// one arrow element per, and it matches a pixelsize*char // one arrow element per, and it matches a pixelsize*char
if (ImagingBorrowArrow(im, external_array, im->pixelsize)) { if (ImagingBorrowArrow(im, external_array, im->pixelsize)) {