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