From 1d2fbad70a1b97daeb91d2a9f848542d8cff7068 Mon Sep 17 00:00:00 2001 From: Moenupa <49304833+Moenupa@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:23:53 +0800 Subject: [PATCH 1/3] [fix] remove emojis from logger.log --- src/prep/api/dataio.py | 18 ++++++++---------- src/prep/api/formatter.py | 26 +++++++++++++++----------- src/prep/constants.py | 5 +++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/prep/api/dataio.py b/src/prep/api/dataio.py index a3c4793..c870d3f 100644 --- a/src/prep/api/dataio.py +++ b/src/prep/api/dataio.py @@ -7,7 +7,7 @@ from datasets import get_dataset_config_names, get_dataset_split_names from rich import print as rprint -from ..constants import HF_PREFIX, PREVIEW_PREFIX, SAVE_PREFIX, SKIP, WARN_PREFIX +from ..constants import HF_PREFIX, SAVE_PREFIX, SKIP from .formatutils import iter_images, write_to_file from .log import get_logger from .pathio import PathIO @@ -140,16 +140,14 @@ def do_preview( ): try: row = d[i] - rprint(f"[bold]Sample {i}[/bold]:", row) - - for j, img in enumerate(iter_images(row)): - path = write_to_file( - img, - save_root / f"{i:06d}_{j:02d}", - ) - rprint(f"{PREVIEW_PREFIX}Preview image saved: {path}") + image_paths = [ + str(write_to_file(img, save_root / f"{i:06d}_{j:02d}")) + for j, img in enumerate(iter_images(row)) + ] + + rprint(f"[bold]Sample {i}[/bold]: (images {image_paths})", row) except Exception as exc: - logger.warning(f"{WARN_PREFIX}Failed to preview {i}th sample: {exc}") + logger.warning(f"Failed to preview {i}th sample: {exc}") continue def do_save( diff --git a/src/prep/api/formatter.py b/src/prep/api/formatter.py index d45e48d..8f7ddfc 100644 --- a/src/prep/api/formatter.py +++ b/src/prep/api/formatter.py @@ -4,7 +4,7 @@ from datasets import ClassLabel, Features, Image, List, Value -from ..constants import ERROR_PREFIX, ID_PATTERN, IMAGE_TAG, WARN_PREFIX +from ..constants import ID_PATTERN, IMAGE_TAG from .log import get_logger from .types import ( DataFormat, @@ -91,7 +91,7 @@ def get( return _FORMATTER_REGISTRY[("_", "show", split)] k = (id_, target_format, split) if k not in _FORMATTER_REGISTRY: - logger.warning(f"{WARN_PREFIX}Formatter pipeline not registered for {k}. ") + logger.warning(f"Formatter pipeline not registered for {k}. ") logger.warning( "Fallback to generic pipeline 'auto'," " which may cause unexpected formatting issues.", @@ -213,7 +213,11 @@ def cast_dataset( case "eval": return FormatterPipeline.cast_eval(d, args) case "cls": - return FormatterPipeline.cast_cls(d, args) + d = FormatterPipeline.cast_cls(d, args) + from collections import Counter + + print("label", Counter(d["label"])) + return d case "show": return d case _: @@ -230,20 +234,20 @@ def load(self, override_src: str | None, args: ProcArgs) -> "Dataset": try: d = self.cast_dataset(d, self.target_format, args) except Warning as e: - logger.warning(f"{WARN_PREFIX}Casting warning {str(self)}") - logger.warning(f"{WARN_PREFIX}{e}") + logger.warning(f"Casting warning {str(self)}") + logger.warning(f"{e}") except Exception as e: - logger.error(f"{ERROR_PREFIX}Casting failed {str(self)}") - logger.error(f"{ERROR_PREFIX}{e}") + logger.error(f"Casting failed {str(self)}") + logger.error(f"{e}") try: for i in range(10): self.check_sample(d[i]) except Warning as e: - logger.warning(f"{WARN_PREFIX}Validation warning {str(self)}") - logger.warning(f"{WARN_PREFIX}{e}") + logger.warning(f"Validation warning {str(self)}") + logger.warning(f"{e}") except Exception as e: - logger.error(f"{ERROR_PREFIX}Validation failed {str(self)}") - logger.error(f"{ERROR_PREFIX}{e}") + logger.error(f"Validation failed {str(self)}") + logger.error(f"{e}") return d diff --git a/src/prep/constants.py b/src/prep/constants.py index cd63a17..c75838f 100644 --- a/src/prep/constants.py +++ b/src/prep/constants.py @@ -23,6 +23,11 @@ def is_env_enabled(env_var: str, default: str = "0") -> bool: FORMATTING_PATTERN = re.compile(r"ANSWER:|||\\boxed\{") ID_PATTERN = re.compile(r"^[a-zA-Z0-9\._-]+$") DEFAULT_UI = None if is_env_enabled("UI", "0") else False +# interactive mode off -> disable progress bars +if DEFAULT_UI is not None: + from datasets import disable_progress_bars + + disable_progress_bars() SAVE_PREFIX = "💾\t" HF_PREFIX = "☁️\t" From 80757d59167de84305a0db018a0223d821dec70c Mon Sep 17 00:00:00 2001 From: Moenupa <49304833+Moenupa@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:36:54 +0800 Subject: [PATCH 2/3] [fix] fix no-image cases and update tests --- src/prep/api/dataio.py | 4 +++- tests/cli/test_clip.py | 2 +- tests/cli/test_cls.py | 13 +++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/prep/api/dataio.py b/src/prep/api/dataio.py index c870d3f..d59e570 100644 --- a/src/prep/api/dataio.py +++ b/src/prep/api/dataio.py @@ -145,7 +145,9 @@ def do_preview( for j, img in enumerate(iter_images(row)) ] - rprint(f"[bold]Sample {i}[/bold]: (images {image_paths})", row) + rprint(f"[bold]Sample {i}[/bold]:" + ( + f" (images {image_paths})" if image_paths else "" + ), row) except Exception as exc: logger.warning(f"Failed to preview {i}th sample: {exc}") continue diff --git a/tests/cli/test_clip.py b/tests/cli/test_clip.py index b8abbb0..04fa6bd 100644 --- a/tests/cli/test_clip.py +++ b/tests/cli/test_clip.py @@ -7,7 +7,7 @@ from prep.cli import app EXPECTED = """\ -WARNING ⚠️ Formatter pipeline not registered for ('auto', 'clip', 'train'). +WARNING Formatter pipeline not registered for ('auto', 'clip', 'train'). WARNING Fallback to generic pipeline 'auto', which may cause unexpected formatting issues.""" diff --git a/tests/cli/test_cls.py b/tests/cli/test_cls.py index 1ea2122..820d398 100644 --- a/tests/cli/test_cls.py +++ b/tests/cli/test_cls.py @@ -4,15 +4,20 @@ from prep.cli import app EXPECTED = """\ -WARNING ⚠️ Formatter pipeline not registered for ('cifar10', 'cls', 'train'). +WARNING Formatter pipeline not registered for ('cifar10', 'cls', 'train'). WARNING Fallback to generic pipeline 'auto', which may cause unexpected formatting issues. +label Counter({0: 5000, 6: 5000, 2: 5000, 7: 5000, 1: 5000, 4: 5000, 5: 5000, 3: 5000, 8: 5000, 9: 5000}) Dataset({ features: ['id', 'image', 'label', 'extra_info'], num_rows: 50000 }) -Sample 0: -{'id': 'cifar10/train00000000', 'image': , 'label': 0, 'extra_info': ''} +Sample 0: (images ['out/cls/cifar10/train/000000_00.png']) +{ + 'id': 'cifar10/train00000000', + 'image': , + 'label': 0, + 'extra_info': '' +} 💾\tAbout to save to disk -> PosixPath('out/cls/cifar10/train')... 💾\tNot saved (pass `--save` to override or `export UI=1` to enable interactive prompts) ☁️\tAbout to upload to HF -> 'cifar10' (subset='default', split='train', private=True)... From 1cefe6ba92ca5ff832712e7ce6a9bfed10d6a873 Mon Sep 17 00:00:00 2001 From: Moenupa <49304833+Moenupa@users.noreply.github.com> Date: Tue, 1 Sep 2026 16:37:39 +0800 Subject: [PATCH 3/3] [format] format --- src/prep/api/dataio.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/prep/api/dataio.py b/src/prep/api/dataio.py index d59e570..6957876 100644 --- a/src/prep/api/dataio.py +++ b/src/prep/api/dataio.py @@ -145,9 +145,11 @@ def do_preview( for j, img in enumerate(iter_images(row)) ] - rprint(f"[bold]Sample {i}[/bold]:" + ( - f" (images {image_paths})" if image_paths else "" - ), row) + rprint( + f"[bold]Sample {i}[/bold]:" + + (f" (images {image_paths})" if image_paths else ""), + row, + ) except Exception as exc: logger.warning(f"Failed to preview {i}th sample: {exc}") continue