From d02417e411d0a49e00aec0ec2bbe223a38da28ff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Jan 2025 16:25:41 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Tests/test_arrow.py | 25 ++++++++++++++----------- src/libImaging/Storage.c | 37 +++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Tests/test_arrow.py b/Tests/test_arrow.py index c5237c902..69193394d 100644 --- a/Tests/test_arrow.py +++ b/Tests/test_arrow.py @@ -68,11 +68,12 @@ def test_to_array(mode: str, dtype: Any, mask: Any) -> None: assert_image_equal(img, reloaded) + @pytest.mark.parametrize( "mode, dest_modes", ( ("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"]), ("LA", ["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): 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): - Image.fromarrow(img, 'RGB', (10,10)) + Image.fromarrow(img, "RGB", (10, 10)) def test_lifetime(): @@ -137,20 +139,21 @@ def test_lifetime2(): def test_release_schema(): # these should not error out, valgrind should be clean - img = hopper('L') + img = hopper("L") schema = img.__arrow_c_schema__() - del(schema) + del schema + def test_release_array(): # these should not error out, valgrind should be clean - img = hopper('L') + img = hopper("L") array, schema = img.__arrow_c_array__() - del(array) - del(schema) + del array + del schema def test_readonly(): - img = hopper('L') + img = hopper("L") reloaded = Image.fromarrow(img, img.mode, img.size) assert reloaded.readonly == 1 reloaded._readonly = 0 diff --git a/src/libImaging/Storage.c b/src/libImaging/Storage.c index 701e89cef..7ac5f63a5 100644 --- a/src/libImaging/Storage.c +++ b/src/libImaging/Storage.c @@ -571,9 +571,7 @@ ImagingDestroyArrow(Imaging im) { } Imaging -ImagingBorrowArrow(Imaging im, - struct ArrowArray *external_array, - int offset_width) { +ImagingBorrowArrow(Imaging im, struct ArrowArray *external_array, int offset_width) { // offset_width is the # of char* for a single offset from arrow Py_ssize_t y, i; @@ -586,11 +584,12 @@ ImagingBorrowArrow(Imaging im, if (arr->n_buffers == 2) { // buffer 0 is the null list // 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) { - 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++) { @@ -698,12 +697,10 @@ ImagingNewArrow( int64_t pixels = (int64_t)xsize * (int64_t)ysize; // fmt:off // don't reformat this - if (((strcmp(schema->format, "I") == 0 - && im->pixelsize == 4 - && im->bands >= 2) // INT32 into any INT32 Storage mode - || - (strcmp(schema->format, im->arrow_band_format) == 0 - && im->bands == 1)) // Single band match + if (((strcmp(schema->format, "I") == 0 && im->pixelsize == 4 && im->bands >= 2 + ) // INT32 into any INT32 Storage mode + || (strcmp(schema->format, im->arrow_band_format) == 0 && im->bands == 1) + ) // Single band match && pixels == external_array->length) { // one arrow element per, and it matches a pixelsize*char if (ImagingBorrowArrow(im, external_array, im->pixelsize)) { @@ -711,15 +708,15 @@ ImagingNewArrow( } } // linter: don't mess with the formatting here - if (strcmp(schema->format, "+w:4") == 0 // 4 up array - && im->pixelsize == 4 // storage as 32 bpc - && schema->n_children > 0 // make sure schema is well formed. - && schema->children // make sure schema is well formed - && strcmp(schema->children[0]->format, "C") == 0 // Expected format - && strcmp(im->arrow_band_format, "C") == 0 // Expected Format - && pixels == external_array->length // expected length - && external_array->n_children == 1 // array is well formed - && external_array->children // array is well formed + if (strcmp(schema->format, "+w:4") == 0 // 4 up array + && im->pixelsize == 4 // storage as 32 bpc + && schema->n_children > 0 // make sure schema is well formed. + && schema->children // make sure schema is well formed + && strcmp(schema->children[0]->format, "C") == 0 // Expected format + && strcmp(im->arrow_band_format, "C") == 0 // Expected Format + && pixels == external_array->length // expected length + && external_array->n_children == 1 // array is well formed + && external_array->children // array is well formed && 4 * pixels == external_array->children[0]->length) { // 4 up element of char into pixelsize == 4 if (ImagingBorrowArrow(im, external_array, 1)) {