Skip to content

Dataset.split silently accepts split ratios outside [0, 1] #2610

Description

@archie0732

Search before asking

  • I have searched the issues and discussions and found no similar bug report.

Bug

[Bug]: Dataset.split silently accepts split ratios outside [0, 1]

Bug

DetectionDataset.split() and ClassificationDataset.split() silently accept
finite ratios below 0 or above 1. They delegate to train_test_split, which
calculates int(len(data) * train_ratio) and uses Python slicing without
validating the ratio.

For a 10-image dataset, split_ratio=-0.2 produces an 8/2 split, while
split_ratio=1.2 (or an accidental percentage such as 80) produces a 10/0
split. A configuration error therefore looks like a successful split and can
leave no held-out data or produce an unintended partition.

This is an input-validation issue; valid ratios do not show a partitioning bug.

Expected behavior

Raise a clear ValueError for ratios outside the inclusive interval [0, 1]
and for non-finite values. Preserve the existing valid behavior of 0.0 and
1.0, which is explicitly covered by current tests, including empty datasets.

NaN and infinity already raise conversion errors; those are secondary error-
message consistency cases, not examples of silently accepted invalid inputs.

Minimal Reproducible Example

import supervision as sv

paths = [f"image_{i}.jpg" for i in range(10)]
dataset = sv.DetectionDataset(
    classes=["object"],
    images=paths,
    annotations={path: sv.Detections.empty() for path in paths},
)

# No actual image files, model, or GPU are needed: split uses image paths.
for ratio in [-0.2, 1.2, 80.0]:
    train, test = dataset.split(split_ratio=ratio, shuffle=False)
    print(ratio, len(train), len(test))

Output:

-0.2 8 2
1.2 10 0
80.0 10 0

Environment and verification

  • Windows, Python 3.12.14, NumPy 2.5.3.
  • Reproduced with the PyPI release supervision==0.30.4.
  • Also reproduced against develop commit
    d79110b149c26d33b4aed6d2d14436dfaa714e5c (source imported via PYTHONPATH).
  • Ran 234 cases per version: three APIs, three dataset sizes (0, 1, 10), two
    shuffle settings, and 13 ratios. Valid ratios preserved partitions and input
    ordering; calls did not change the global random state.
  • Existing upstream split tests: 18 passed.
  • Six proposed out-of-range validation regression tests: all fail with
    DID NOT RAISE ValueError on unmodified develop.
  • OpenCV is not installed; Supervision selected its NumPy fallback. These
    tests do not decode images or call image-processing functions.

Proposed scope

  • Validate the ratio in the shared helper before shuffling or slicing.
  • Document the accepted inclusive range and exception.
  • Add regression tests for both public dataset classes and the helper, covering
    negative/greater-than-one/non-finite ratios, empty input, both shuffle modes,
    and unchanged behavior for valid ratios including 0 and 1.
  • Avoid adding new dataset-splitting APIs or changing rounding behavior.

Related work checked

I did not find an existing issue or PR specifically addressing this validation
gap in the searches performed on 2026-09-21.

Would a focused validation fix preserving the existing [0, 1] behavior be
welcome?

Environment

  • Supervision:
  • Python:
  • OS:

Minimal Reproducible Example

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions