Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

partition_dataset with ratios leaves some items out of every partition

Open Beginner friendly
#9,216 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@mottopanikeiku is already working on this.

Since Oct 22, 2026.

  • #9217 by @mottopanikeiku — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python, pytorch

Research direction

Start in monai/data/utils.py at partition_dataset and its ratio-based size calculation around the linked lines; check the related partition_dataset_classes path as well. Reproduce the reported missing-item case, then run or add focused tests for ratio splits and class-based splits. Done means every input item appears in exactly one partition, including when rounded sizes would otherwise leave items out.

Written by the indexing model from the issue text.

Description

Describe the bug
The text below was written with AI assistance (Claude and GPT-6 Astra).

partition_dataset(data, ratios=...) rounds each partition size on its own (https://github.com/Project-MONAI/MONAI/blob/6920610c310200d683a3b00987a05893ccf1ca5f/monai/data/utils.py#L1217-L1224). When the rounded sizes add up to less than len(data), the remaining items are not in any partition, and nothing reports it. With three ratios this happens for about one length in five (0.8/0.1/0.1: 200 of the lengths 1 to 1000; 1/1/1: 334), and with five equal ratios up to two items are lost. partition_dataset_classes splits each class with the same function, so it can lose one item per class. Two-way splits are not affected.

I found this by reading and testing the code.

To Reproduce

from monai.data import partition_dataset

print(partition_dataset(list(range(10)), ratios=[1, 1, 1]))

data = list(range(63))  # e.g. the 63 training cases of MSD Task06_Lung
train, val, test = partition_dataset(data, ratios=[0.8, 0.1, 0.1], shuffle=True, seed=0)
print(len(train), len(val), len(test), "in no split:", sorted(set(data) - set(train + val + test)))

Output on dev (6920610):

[[0, 1, 2], [3, 4, 5], [6, 7, 8]]
50 6 6 in no split: [44]

The same happens for other Decathlon training-set sizes, e.g. 303 (Task08_HepaticVessel) and 484 (Task01_BrainTumour) with 0.8/0.1/0.1, 63 and 303 with 0.7/0.15/0.15, and 32 (Task05_Prostate) with five equal ratios, which loses two cases. In a Decathlon-style pipeline (load_decathlon_datalist -> partition_dataset -> CacheDataset -> DataLoader) with 63 cases, one case is never loaded by the train, validation or test split.

Expected behavior
Every item should be in exactly one partition, as in the docstring example ([0.6, 0.2, 0.2] on 5 items gives [[1, 2, 3], [4], [5]]). drop_last is documented as not applying to the ratio path.

Environment
MONAI 1.6.1rc0+50.g6920610c (dev), PyTorch 2.14.1+cpu, NumPy 2.5.4, Python 3.12.13, Linux.

Additional context
I have a small fix that gives the leftover items to the partitions whose sizes were rounded down the most and leaves every split that already covers all items unchanged, plus tests, and can open a PR.

I made this report and directed the investigation, with AI assistance from Claude and GPT-6 Astra.

Dominant language
Python
Stars
8.8k
Forks
1.7k
Avg merge
6d 12h
Merged PRs (30d)
14

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 Project-MONAI/MONAI

All issues in Project-MONAI/MONAI

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.