partition_dataset
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read the rounding logic in monai/data/utils.py around lines 1217-1224 where partition_dataset computes each partition's size, and reproduce the bug with the snippet in the issue (e.g. partition_dataset(list(range(10)), ratios=[1,1,1]) drops items). The fix should distribute leftover items to partitions rounded down the most, and the reporter says they have a fix plus tests ready — comment quickly to coordinate before starting, since a PR may appear. Done: every item lands in exactly one partition for the reported ratios/lengths, existing tests in tests for partition_dataset still pass, and new tests cover the leftover-item cases.
Written by the indexing model from the issue text.
Description
When partition_dataset(data, ratios=...) splits a list, it computes every partition's size by rounding independently (see monai/data/utils.py, lines 1217–1224 at commit 6920610). If those rounded sizes add up to less than len(data), the extra items end up in no partition, and no warning or error is raised.
With three ratios this affects roughly one length in five: for 0.8/0.1/0.1 it happens for 200 of the lengths from 1 to 1000, and for 1/1/1 it happens for 334 of them. With five equal ratios, as many as two items can disappear. Because partition_dataset_classes applies the same function to each class, it can lose up to one item per class. Splits into two parts are not affected.
I found this by reading the code and then testing it.
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 thing occurs for other Decathlon training-set sizes. Examples: 303 cases (Task08_HepaticVessel) and 484 cases (Task01_BrainTumour) with 0.8/0.1/0.1; 63 and 303 cases with 0.7/0.15/0.15; and 32 cases (Task05_Prostate) with five equal ratios, where two cases are lost. 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
Each item should land in exactly one partition, as the docstring example shows ([0.6, 0.2, 0.2] on 5 items gives [[1, 2, 3], [4], [5]]). The documentation says drop_last does not apply when ratios are used.
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 ready. It hands the leftover items to the partitions that were rounded down the most, and splits that already cover every item stay unchanged. It comes with tests, and I can open a PR.
- Dominant language
- Python
- Stars
- 8.8k
- Forks
- 1.7k
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 13
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Project-MONAI/MONAI
-
partition_dataset with ratios leaves some items out of every partitionPossibly taken @mottopanikeiku claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Project-MONAI/MONAI#9216 ·
Maintainers usually reply within 3 days
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is setPossibly taken @mottopanikeiku claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Project-MONAI/MONAI#9214 ·
Maintainers usually reply within 3 days
-
DiNTS: missing graph-break regression test (follow-up to #9145)Possibly taken @nilapate claimed this 18 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Project-MONAI/MONAI#9159 ·
Maintainers usually reply within 3 days
-
ProbMapProducer raises IndexError on numpy 2.x: SlidingPatchWSIDataset emits float locationsPossibly taken @nilapate claimed this 29 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Project-MONAI/MONAI#9135 · 1 comment ·
Maintainers usually reply within 3 days
-
RandGridPatch crashes for documented 0 or None patch_size entriesPossibly taken @Rajioba1 claimed this 85 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Project-MONAI/MONAI#9046 ·
Maintainers usually reply within 3 days
All issues in Project-MONAI/MONAI
Similar issues
-
component:benchmark
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
agentic-os-org/ANOLISA#9177 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
distrochooser/distrochooser#520 ·
Maintainers usually reply within 2 days
-
Status: Needs confirmation Status: Needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
[BUG] Published Docker images lack the redis extra: HEADROOM_COMPRESS_SESSION_STORE stops startupPossibly taken @AlessandroSpallina claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
headroomlabs-ai/headroom#4513 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
codespell-project/codespell#4060 ·
Maintainers usually reply within 1 day