meta-pytorch / meta-pytorch/data

`.fork(n)` returns original datapipe for `n==1` instead of singleton list

Open
#1,164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.3k
Forks
179
Avg merge
6d 1h
Merged PRs (30d)
2

Description

🐛 Describe the bug

pipe.fork(n) returns the original pipe when n == 1 and not a list with 1 element. This introduces two issues:

  1. It's unexpected to the user
  2. It requires the user to add extra code to handle this edgecase if the number of forks is dynamically determined during runtime

For instance, consider the following two snippets that will fail if n==1:

pipes = IterableWrapper(self.years).fork(n_vars)
for pipe in pipes:
     process_pipe(pipe)

=> iterates over elements of the original pipe and not over the actual pipes.

pipes = IterableWrapper(self.years).fork(n_vars)
for idx in range(n_vars):
     process_pipe(pipes[idx])

=> Will raise an NotImplementedError from Dataset.__getitem__().

To handle this case, the user needs to add extra code specifically for n==1.

Versions

nightly / latest

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 by locating the implementation of IterableWrapper.fork and the Dataset behavior referenced in the examples. Reproduce the n==1 case and compare it with other fork counts; done means the return shape is consistent for one fork, with regression coverage for both iteration and indexing usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.