[BUG] create_dataset() raises IndexError instead of ValueError on empty NumPy array
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
L'accesso non verificato data[0] si trova nel blocco di rilevamento del formato di create_dataset() in openml/datasets/functions.py. Esegui lo snippet di riproduzione dell'issue con un array senza righe per confermare l'IndexError. È completato quando un data vuoto solleva un ValueError che include la forma dell'array e un test per quel caso passa.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description:
When create_dataset() is called with a zero-row NumPy array, the
function raises an IndexError instead of a descriptive ValueError.
The error originates from an unchecked data[0] access inside the
format-detection block. The message gives zero indication of what
actually went wrong — a user passing an empty DataFrame export or a
filtered-down dataset with no rows gets a raw index crash with no
context.
No warning, no descriptive message, no hint that the root cause is
simply an empty array. The function just crashes silently with a raw
IndexError pointing deep into openml internals.
Expected Behavior:
A clear ValueError that tells the user exactly what the problem is:
ValueError: 'data' must contain at least one row,
but got an array with shape (0, 2).
Environment
- openml-python version: 0.15.1
- Python version: 3.12
- OS: Ubuntu 24
Error messages, stack traces, or logs
No descriptive error is raised. Just a raw IndexError with no context:
IndexError: index 0 is out of bounds for axis 0 with size 0
The traceback points inside openml internals with no hint that
the root cause is simply an empty array being passed in.
Verified with arrays of shape (0, 2), (0, 5), (0, 10) — all
produce the same IndexError with no useful message.
Steps to reproduce
import numpy as np
import openml
openml.datasets.create_dataset(
name="empty_test",
description="Reproduces the IndexError bug",
creator=None,
contributor=None,
collection_date=None,
language=None,
licence=None,
attributes=[("feature1", "NUMERIC"), ("target", "NUMERIC")],
data=np.array([]).reshape(0, 2), # 0 rows — triggers the bug
default_target_attribute="target",
ignore_attribute=None,
citation="",
)
# Expected: ValueError: 'data' must contain at least one row,
# but got an array with shape (0, 2).
# Actual: IndexError: index 0 is out of bounds for axis 0 with size 0
Additional context
Root cause is this unchecked data[0] access in datasets/functions.py:
# BEFORE (buggy)
if isinstance(data, (list, np.ndarray)):
if isinstance(data[0], (list, np.ndarray)): # crashes if data is empty
data_format = "arff"
elif isinstance(data[0], dict):
data_format = "sparse_arff"
# AFTER (suggested fix)
if isinstance(data, (list, np.ndarray)):
if len(data) == 0: # guard added
raise ValueError(
f"'data' must contain at least one row, "
f"but got an array with shape {np.array(data).shape}."
)
if isinstance(data[0], (list, np.ndarray)):
data_format = "arff"
elif isinstance(data[0], dict):
data_format = "sparse_arff"
Confirmed across 3 consecutive runs on openml==0.15.1 / Python 3.12 / Ubuntu 24.
Happy to open a PR with the fix if this is confirmed.
- Lingua principale
- Python
- Stelle
- 366
- Fork
- 308
- Merge medio
- 1g 16h
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openml/openml-python
-
[BUG] create_task() hardcodes task_type="None" instead of inferring type string from TaskTypeForse già presa @shellyco-code l’ha presa 10 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
openml/openml-python#1766 ·
I maintainer di solito rispondono entro 1 giorno
-
Enhancement: Add missing **kwargs support to list_setups and list_evaluationsForse già presa @shellyco-code l’ha presa 17 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
openml/openml-python#1753 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[ENH] list_estimation_procedures() should include the procedure IDsForse già presa @Jayant-kernel l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
openml/openml-python#1750 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[DOC] Update documentation for running tests with local servicesForse già presa @nishtha-agarwal-211 l’ha presa 220 giorni fa. ApertaDocumentation Good First Issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openml/openml-python#1708 · 8 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[MNT] Add Missing Assertions to Run Function TestsForse già presa @Akarshkushwaha l’ha presa 239 giorni fa. ApertaGood First Issue module:Run testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
openml/openml-python#1646 · 9 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openml/openml-python
Issue simili
-
python triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/semantic-kernel#14615 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
shackett/shackett-utils#19 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
UKGovernmentBEIS/control-arena#917 ·
I maintainer di solito rispondono entro 1 giorno