Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#1,777 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, python
领域
data

调研方向

未经检查的 data[0] 访问位于 openml/datasets/functions.py 中 create_dataset() 的格式检测代码块里。使用零行数组运行 issue 中的复现代码片段,确认会出现 IndexError。当空的 data 抛出包含数组形状的 ValueError,并且针对该情况的测试通过时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
366
派生
308
平均合并
1 天 16 小时
30 天内合并 PR
7

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openml/openml-python 的其他 Issue

查看 openml/openml-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。