[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,11 +68,12 @@ 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",
( (
("L", ["I", "F", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]), ("L", ["I", "F", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]),
("I", ["L", "F"]), # Technically I32 can work for any 4x8bit storage. ("I", ["L", "F"]), # Technically I32 can work for any 4x8bit storage.
("F", ["I", "L", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]), ("F", ["I", "L", "LA", "RGB", "RGBA", "RGBX", "CMYK", "YCbCr", "HSV"]),
("LA", ["L", "F"]), ("LA", ["L", "F"]),
("RGB", ["L", "F"]), ("RGB", ["L", "F"]),
@ -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():
img = hopper('RGB')
assert img.size != (10,10) def test_invalid_array_size():
img = hopper("RGB")
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;
@ -586,11 +584,12 @@ ImagingBorrowArrow(Imaging im,
if (arr->n_buffers == 2) { if (arr->n_buffers == 2) {
// buffer 0 is the null list // buffer 0 is the null list
// buffer 1 is the data // buffer 1 is the data
borrowed_buffer = (char *)arr->buffers[1] + (offset_width*arr->offset); borrowed_buffer = (char *)arr->buffers[1] + (offset_width * arr->offset);
} }
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)) {
@ -711,15 +708,15 @@ ImagingNewArrow(
} }
} }
// linter: don't mess with the formatting here // linter: don't mess with the formatting here
if (strcmp(schema->format, "+w:4") == 0 // 4 up array if (strcmp(schema->format, "+w:4") == 0 // 4 up array
&& im->pixelsize == 4 // storage as 32 bpc && im->pixelsize == 4 // storage as 32 bpc
&& schema->n_children > 0 // make sure schema is well formed. && schema->n_children > 0 // make sure schema is well formed.
&& schema->children // make sure schema is well formed && schema->children // make sure schema is well formed
&& strcmp(schema->children[0]->format, "C") == 0 // Expected format && strcmp(schema->children[0]->format, "C") == 0 // Expected format
&& strcmp(im->arrow_band_format, "C") == 0 // Expected Format && strcmp(im->arrow_band_format, "C") == 0 // Expected Format
&& pixels == external_array->length // expected length && pixels == external_array->length // expected length
&& external_array->n_children == 1 // array is well formed && external_array->n_children == 1 // array is well formed
&& external_array->children // array is well formed && external_array->children // array is well formed
&& 4 * pixels == external_array->children[0]->length) { && 4 * pixels == external_array->children[0]->length) {
// 4 up element of char into pixelsize == 4 // 4 up element of char into pixelsize == 4
if (ImagingBorrowArrow(im, external_array, 1)) { if (ImagingBorrowArrow(im, external_array, 1)) {