Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[BUG] create_dataset() raises IndexError instead of ValueError on empty NumPy array

Ouverte Adaptée aux débutants
#1,777 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
82/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
numpy, python
Domaine
data

Piste de recherche

L'accès non vérifié data[0] se trouve dans le bloc de détection du format de create_dataset() dans openml/datasets/functions.py. Exécute l'extrait de reproduction de l'issue avec un tableau sans ligne pour confirmer l'IndexError. C'est terminé lorsqu'un data vide lève une ValueError qui inclut la forme du tableau, et qu'un test pour ce cas passe.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
366
Forks
308
Merge moyen
1 j 16 h
PR mergées (30 j)
7

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de openml/openml-python

Toutes les issues de openml/openml-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.