From 1fe3e0ad714cfe29cd37c66093003e416f188a9d Mon Sep 17 00:00:00 2001 From: burtenshaw Date: Mon, 28 Oct 2024 13:05:55 +0100 Subject: [PATCH] [BUGFIX] Catch None in image feature columns (#5626) # Description This PR fixes this snippet: ```python import argilla as rg from datasets import load_dataset client = rg.Argilla( api_url="https://frascuchon-argilla.hf.space", api_key="argilla.apikey" ) ds = load_dataset("derek-thomas/ScienceQA", name="default", split="train") dataset = client.datasets(name="science_qa", workspace="argilla") dataset.records.log( ds, mapping={"task": "text_0.suggestion", "subject": "text_1.suggestion"} ) ``` Closes # **Type of change** - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Refactor (change restructuring the codebase without changing functionality) - Improvement (change adding some improvement to an existing functionality) - Documentation update **How Has This Been Tested** **Checklist** - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Francisco Aranda --- argilla/src/argilla/_helpers/_media.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/argilla/src/argilla/_helpers/_media.py b/argilla/src/argilla/_helpers/_media.py index 4f2fe8faa6..21153a4e65 100644 --- a/argilla/src/argilla/_helpers/_media.py +++ b/argilla/src/argilla/_helpers/_media.py @@ -16,18 +16,20 @@ import io import warnings from pathlib import Path -from typing import Union +from typing import Union, Optional from PIL import Image -def pil_to_data_uri(image_object: "Image") -> str: +def pil_to_data_uri(image_object: Optional["Image"]) -> Optional[str]: """Convert a PIL image to a base64 data URI string. Parameters: image_object (Image): The PIL image to convert to a base64 data URI. Returns: str: The data URI string. """ + if image_object is None: + return None if not isinstance(image_object, Image.Image): raise ValueError("The image_object must be a PIL Image object.")