From 6af0e71fe44ab7aecffbbd76f93ffe7d49a06484 Mon Sep 17 00:00:00 2001 From: mayuriphad Date: Mon, 19 Oct 2026 09:45:18 +0530 Subject: [PATCH] fix: raise a clear ValueError when create_dataset gets an empty array create_dataset read data[0] to detect the data format, so an empty list or numpy array raised IndexError instead of a descriptive ValueError. Signed-off-by: mayuriphad --- openml/datasets/functions.py | 2 ++ tests/test_datasets/test_dataset_functions.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/openml/datasets/functions.py b/openml/datasets/functions.py index 12ad42784..fcd29515d 100644 --- a/openml/datasets/functions.py +++ b/openml/datasets/functions.py @@ -742,6 +742,8 @@ def create_dataset( # noqa: C901, PLR0912, PLR0915 data_format: Literal["arff", "sparse_arff"] if isinstance(data, (list, np.ndarray)): + if len(data) == 0: + raise ValueError("'data' must contain at least one row, but it is empty.") if isinstance(data[0], (list, np.ndarray)): data_format = "arff" elif isinstance(data[0], dict): diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index fae4a1c4e..f5053ea23 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -877,6 +877,10 @@ def test_create_invalid_dataset(self): param["data"] = data[0] self.assertRaises(ValueError, create_dataset, **param) # noqa: PT027 + param["data"] = np.empty((0, 2)) + with pytest.raises(ValueError, match="at least one row"): + create_dataset(**param) + @pytest.mark.test_server def test_get_online_dataset_arff(self): dataset_id = 128 # iris -- one of the few datasets without parquet file