Skip to content

fix: TextPreprocessor.validate_dataset counts samples while iterating, not with len(dataset) - #17731

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
Lluczel:fix/validate-dataset-sample-count
Nov 14, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
Lluczel:fix/validate-dataset-sample-count

Conversation

@Lluczel

@Lluczel Lluczel commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #17730

validate_dataset set total_samples to len(dataset). For a dict, len() is the number of columns, so {"text": [a, b]} and {"text": []} both reported 1 sample. A datasets.IterableDataset has no __len__, so the call raised TypeError before reading any sample.

Changes

  • unsloth/dataprep/raw_text.py: total_samples starts at 0 and counts each sample in the loop that already reads them. Blank samples are still counted. Dataset and DataFrame inputs report the same counts as before.
  • tests/test_raw_text.py: test_validate_dataset_accepts_objects_without_column_names now asserts total_samples for dict input. New test_validate_dataset_counts_iterable_dataset_without_len covers a dataset with iter() but no __len__.

Test

  • Both tests fail on main (assert 1 == 2 and TypeError) and pass with this change. tests/test_raw_text.py: 19 passed.
  • Checked by hand with datasets 4.8.5: Dataset.to_iterable_dataset() and load_dataset(..., streaming = True) now report the right count.

@danielhanchen danielhanchen self-assigned this Nov 14, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T08:05:15.754780Z 1fb19f2 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 1fb19f2b60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TextPreprocessor.validate_dataset miscounts total_samples for dict input and raises on IterableDataset

2 participants