tensorflow / tensorflow/datasets

Relative import issue in new dataset boilerplate

Open
#4,023 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.6k
Forks
1.6k
Avg merge
3h 54m
Merged PRs (30d)
1

Description

/!\ PLEASE INCLUDE THE FULL STACKTRACE AND CODE SNIPPET

Short description
In boilerplate datasets created with tfds new, the default import line in the test file is from . import <name>, which seems to raise an error about relative import.

Environment information

  • Operating System: Windows 10.0.19044.1766

  • Python version: 3.10.4

  • tensorflow-datasets/tfds-nightly version: tensorflow-datasets 4.6.0

  • tensorflow/tf-nightly version: tensorflow 2.9.1

  • Does the issue still exists with the last tfds-nightly package (pip install --upgrade tfds-nightly) ? Untested, but presumably yes.

Reproduction instructions

tfds new my_ds
python my_ds/my_ds_test.py

Link to logs

Traceback (most recent call last):
  File "C:\Users\Admin\Downloads\my_ds\my_ds_test.py", line 4, in <module>
    from . import my_ds
ImportError: attempted relative import with no known parent package

Expected behavior
Tests should proceed normally.

Additional context
The boilerplate references info.ds_import:
https://github.com/tensorflow/datasets/blob/fdad1d9e8f1cb34389a336132b2f842cbc7aca57/tensorflow_datasets/scripts/cli/new.py#L207
which curiously defaults to . by design:
https://github.com/tensorflow/datasets/blob/fdad1d9e8f1cb34389a336132b2f842cbc7aca57/tensorflow_datasets/scripts/cli/new.py#L63-L67

In this case, changing the line to just import <name> works.

Contributor guide

Open the contributing guide

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.

Research direction

Start in tensorflow_datasets/scripts/cli/new.py, especially the ds_import default and the template generation around the referenced lines. Reproduce the issue with tfds new my_ds followed by python my_ds/my_ds_test.py, then verify the generated test runs normally with the corrected import behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.