Skip to content

Fix bucket dataset card handling and push metadata accounting#8354

Open
pjh4993 wants to merge 3 commits into
huggingface:mainfrom
pjh4993:fix/db-bucket-dataset-card-and-push-metadata
Open

Fix bucket dataset card handling and push metadata accounting#8354
pjh4993 wants to merge 3 commits into
huggingface:mainfrom
pjh4993:fix/db-bucket-dataset-card-and-push-metadata

Conversation

@pjh4993

@pjh4993 pjh4993 commented Jul 23, 2026

Copy link
Copy Markdown

Four fixes on the buckets/... read/write paths, hit by push_to_hubload_dataset. The loader one crashes on any dataset with a README; the writer ones corrupt uploaded metadata.

Key Changes

  • Bucket card loading (src/datasets/load.py): passed the card object instead of its .data, crashing on load. Now uses .data.
  • Standalone-YAML branch (src/datasets/load.py): the missing-file case wiped the parsed card. Now leaves it intact.
  • Split size (src/datasets/iterable_dataset.py): worker byte count was dropped, so SplitInfo.num_bytes was always 0. Now accumulated.
  • dataset_infos.json (src/datasets/arrow_dataset.py): serialized the wrong variable, always crashing (UnboundLocalError with no README, TypeError with one). Now returns the assembled dict for the caller to encode.

Tests

One hermetic test per fix in tests/test_buckets.py (in-memory filesystems / a stubbed shard worker, no Hub), each verified to fail on the pre-fix code — same order as above:

  • test_bucket_module_uses_dataset_card_data_not_card — guards src/datasets/load.py
  • test_bucket_module_preserves_card_when_standalone_yaml_missing — guards src/datasets/load.py
  • test_push_parquet_shards_reports_dataset_nbytes — guards src/datasets/iterable_dataset.py
  • test_get_updated_dataset_card_returns_legacy_infos_as_dict — guards src/datasets/arrow_dataset.py

pytest tests/test_buckets.py4 passed; ruff check/ruff format --check clean.

🤖 Generated with Claude Code

pjh4993 and others added 3 commits July 23, 2026 17:56
Four fixes along the storage-bucket read/write code paths:

1. load.py (HubBucketDatasetModuleFactory.get_module): the parsed README
   was passed as a DatasetCard instead of DatasetCard.data, so loading any
   bucket dataset with a README.md raised
   "AttributeError: 'DatasetCard' object has no attribute 'get'". Use .data
   like every sibling factory.

2. load.py (same factory): the standalone-YAML `except FileNotFoundError`
   branch clobbered dataset_card_data instead of setting standalone_yaml_data,
   discarding the parsed card. Assign standalone_yaml_data = None.

3. iterable_dataset.py (_push_parquet_shards_to_hub): the per-worker tuple
   yields dataset_nbytes in the 4th position, but the collector unpacked it as
   uploaded_size and never accumulated dataset_nbytes, so the resulting
   SplitInfo.num_bytes was always 0. Accumulate dataset_nbytes.

4. arrow_dataset.py (_get_updated_dataset_card): the legacy-infos branch
   returned json.dumps(dataset_infos) — the wrong variable, which is also
   unbound when no README exists — instead of the assembled legacy infos dict.
   The function is typed Optional[dict] and both call sites json.dumps() the
   result, so returning the dict fixes the double-encoding (dataset_infos.json
   was written as a JSON string, not an object) and the crash.

Adds a hermetic regression test for fix (4) over an in-memory filesystem;
the bucket read/write paths themselves require live Hub credentials.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replaces the single dataset_infos.json test with tests/test_buckets.py,
one hermetic test per fix, each verified to fail on the pre-fix code:

- test_bucket_module_uses_dataset_card_data_not_card (fix 1, load.py)
- test_bucket_module_preserves_card_when_standalone_yaml_missing (fix 2, load.py)
- test_push_parquet_shards_reports_dataset_nbytes (fix 3, iterable_dataset.py)
- test_get_updated_dataset_card_returns_legacy_infos_as_dict (fix 4, arrow_dataset.py)

The loader / push paths are driven in isolation over in-memory filesystems and
a stubbed shard worker, so no live Hub access is needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Repo test files use no module or function docstrings; convert the essential
rationale to brief inline comments to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant