DatasetInfo.read_from_directory reads the deprecated FieldDescriptor.label eagerly, warning on every open

Open Beginner friendly
#11,245 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@jabrailkhalil is already working on this.

Since Oct 12, 2026.

  • #11246 by @jabrailkhalil — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, tensorflow
Domain
backend, data

Research direction

Read tensorflow_datasets/core/dataset_info.py around lines 788–792 and check how read_from_directory restores each field. Reproduce with the issue's python -W error::DeprecationWarning command against a prepared dataset. The issue is resolved when restoring fields no longer reads the deprecated label when is_repeated is available, and the command completes without the warning.

Written by the indexing model from the issue text.

Description

DatasetInfo.read_from_directory evaluates the deprecated protobuf label fallback eagerly on every field it restores, so every open of a prepared dataset emits a protobuf DeprecationWarning (and fails under -W error), even on protobuf versions that provide is_repeated.

tensorflow_datasets/core/dataset_info.py (master, and 4.9.10, lines ~788-792):

is_repeated = getattr(
    field,
    "is_repeated",
    getattr(field, "label", None) == getattr(field, "LABEL_REPEATED", 3),
)

The third argument to getattr is evaluated before getattr runs, so field.label is read even when field.is_repeated exists. With protobuf releases that deprecate FieldDescriptor.label, this warns once per restored field:

DeprecationWarning: label() is deprecated. Use is_required() or is_repeated() instead.

Suggested fix: evaluate the fallback only when is_repeated is missing, e.g.

if hasattr(field, "is_repeated"):
  is_repeated = field.is_repeated
else:
  is_repeated = field.label == field.LABEL_REPEATED

Reproduction: with tensorflow-datasets 4.9.10 and a current protobuf, python -W error::DeprecationWarning -c "import tensorflow_datasets as tfds; tfds.builder('mnist', data_dir=<a prepared dir>).info" raises from dataset_info.py:791.

Dominant language
Python
Stars
4.6k
Forks
1.6k
Avg merge
1d 5h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tensorflow/datasets

All issues in tensorflow/datasets

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.