From e69f352dd4504ccc223716e29eba542689bb1eea Mon Sep 17 00:00:00 2001 From: HuaTNA Date: Wed, 23 Sep 2026 13:14:04 -0400 Subject: [PATCH 1/2] fix: preserve nearest interpolation for Jina CLIP --- fastembed/image/transform/operators.py | 4 +-- tests/test_image_transform.py | 47 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/fastembed/image/transform/operators.py b/fastembed/image/transform/operators.py index e6ba4d95f..c5155be45 100644 --- a/fastembed/image/transform/operators.py +++ b/fastembed/image/transform/operators.py @@ -372,7 +372,7 @@ def _get_resize(cls, transforms: list[Transform], config: dict[str, Any]) -> Non if isinstance(interpolation, str): resample = cls._interpolation_resolver(interpolation) else: - resample = interpolation or Image.Resampling.BICUBIC + resample = interpolation if interpolation is not None else Image.Resampling.BICUBIC if "size" in config: resize_mode = config.get("resize_mode", "shortest") @@ -493,7 +493,7 @@ def _interpolation_resolver(resample: str | None = None) -> Image.Resampling: "hamming": Image.Resampling.HAMMING, } - if resample and (method := interpolation_map.get(resample.lower())): + if resample and (method := interpolation_map.get(resample.lower())) is not None: return method raise ValueError(f"Unknown interpolation method: {resample}") diff --git a/tests/test_image_transform.py b/tests/test_image_transform.py index d152719ca..d183b0b22 100644 --- a/tests/test_image_transform.py +++ b/tests/test_image_transform.py @@ -3,6 +3,53 @@ from PIL import Image from fastembed.image.transform.functional import normalize, resize +from fastembed.image.transform.operators import Compose + + +@pytest.mark.parametrize( + ("interpolation", "resample"), + [ + ("nearest", Image.Resampling.NEAREST), + ("NeArEsT", Image.Resampling.NEAREST), + (0, Image.Resampling.NEAREST), + (Image.Resampling.NEAREST, Image.Resampling.NEAREST), + ("lanczos", Image.Resampling.LANCZOS), + ("bilinear", Image.Resampling.BILINEAR), + ("bicubic", Image.Resampling.BICUBIC), + ("box", Image.Resampling.BOX), + ("hamming", Image.Resampling.HAMMING), + (None, Image.Resampling.BICUBIC), + ], +) +def test_jina_clip_interpolation( + interpolation: str | int | None, resample: Image.Resampling +) -> None: + processor = Compose.from_config( + { + "image_processor_type": "JinaCLIPImageProcessor", + "size": 4, + "interpolation": interpolation, + "do_rescale": False, + } + ) + pixels = np.array([[0, 255], [255, 0]], dtype=np.uint8) + image = Image.fromarray(np.repeat(pixels[:, :, None], 3, axis=2)) + + result = processor([image])[0] + expected = np.asarray(image.resize((4, 4), resample=resample)).transpose(2, 0, 1) + np.testing.assert_array_equal(result, expected) + + +@pytest.mark.parametrize("interpolation", ["", "unknown"]) +def test_jina_clip_rejects_unknown_interpolation(interpolation: str) -> None: + with pytest.raises(ValueError, match="Unknown interpolation method"): + Compose.from_config( + { + "image_processor_type": "JinaCLIPImageProcessor", + "size": 4, + "interpolation": interpolation, + } + ) @pytest.mark.parametrize( From 690aaa8b9d68d3b4e8700cf69a68c0500102491f Mon Sep 17 00:00:00 2001 From: George Panchuk Date: Thu, 24 Sep 2026 17:17:52 +0700 Subject: [PATCH 2/2] tests: remove redundant tests --- tests/test_image_transform.py | 47 ----------------------------------- 1 file changed, 47 deletions(-) diff --git a/tests/test_image_transform.py b/tests/test_image_transform.py index d183b0b22..d152719ca 100644 --- a/tests/test_image_transform.py +++ b/tests/test_image_transform.py @@ -3,53 +3,6 @@ from PIL import Image from fastembed.image.transform.functional import normalize, resize -from fastembed.image.transform.operators import Compose - - -@pytest.mark.parametrize( - ("interpolation", "resample"), - [ - ("nearest", Image.Resampling.NEAREST), - ("NeArEsT", Image.Resampling.NEAREST), - (0, Image.Resampling.NEAREST), - (Image.Resampling.NEAREST, Image.Resampling.NEAREST), - ("lanczos", Image.Resampling.LANCZOS), - ("bilinear", Image.Resampling.BILINEAR), - ("bicubic", Image.Resampling.BICUBIC), - ("box", Image.Resampling.BOX), - ("hamming", Image.Resampling.HAMMING), - (None, Image.Resampling.BICUBIC), - ], -) -def test_jina_clip_interpolation( - interpolation: str | int | None, resample: Image.Resampling -) -> None: - processor = Compose.from_config( - { - "image_processor_type": "JinaCLIPImageProcessor", - "size": 4, - "interpolation": interpolation, - "do_rescale": False, - } - ) - pixels = np.array([[0, 255], [255, 0]], dtype=np.uint8) - image = Image.fromarray(np.repeat(pixels[:, :, None], 3, axis=2)) - - result = processor([image])[0] - expected = np.asarray(image.resize((4, 4), resample=resample)).transpose(2, 0, 1) - np.testing.assert_array_equal(result, expected) - - -@pytest.mark.parametrize("interpolation", ["", "unknown"]) -def test_jina_clip_rejects_unknown_interpolation(interpolation: str) -> None: - with pytest.raises(ValueError, match="Unknown interpolation method"): - Compose.from_config( - { - "image_processor_type": "JinaCLIPImageProcessor", - "size": 4, - "interpolation": interpolation, - } - ) @pytest.mark.parametrize(