[BUG] create_dataset() raises IndexError instead of ValueError on empty NumPy array
維護者通常 1 天內回覆
評估
研究方向
未經檢查的 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
- 星號
- 370
- 分支
- 309
- 平均合併
- 1 天 16 小時
- 30 天內合併 PR
- 7
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
openml/openml-python 的其他 Issue
-
[BUG] create_task() hardcodes task_type="None" instead of inferring type string from TaskType可能已有人在做 @shellyco-code 於 16 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 80/100
openml/openml-python#1766 ·
維護者通常 1 天內回覆
-
Enhancement: Add missing **kwargs support to list_setups and list_evaluations可能已有人在做 @shellyco-code 於 23 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
openml/openml-python#1753 · 1 則留言 ·
維護者通常 1 天內回覆
-
[ENH] list_estimation_procedures() should include the procedure IDs可能已有人在做 @Jayant-kernel 於 26 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 70/100
openml/openml-python#1750 · 3 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[DOC] Update documentation for running tests with local services可能已有人在做 @nishtha-agarwal-211 於 226 天前認領。 未關閉Documentation Good First Issue
難度 2/5 1-3 小時 新手友好度 74/100
openml/openml-python#1708 · 8 則留言 ·
維護者通常 1 天內回覆
-
[MNT] Add Missing Assertions to Run Function Tests可能已有人在做 @Akarshkushwaha 於 245 天前認領。 未關閉Good First Issue module:Run testing
難度 2/5 1-3 小時 新手友好度 82/100
openml/openml-python#1646 · 9 則留言 · 3 個 reaction ·
維護者通常 1 天內回覆
查看 openml/openml-python 的全部 Issue
相似的 Issue
-
comp/tools P2 type/bug
難度 2/5 1-3 小時 新手友好度 78/100
NousResearch/hermes-agent#142908 · 1 則留言 ·
-
[oblt-aw][autodoc] Fix malformed headings in new Buildkite docs pages可能已有人在做 @github-actions 今天認領。 未關閉documentation
難度 1/5 1 小時以內 新手友好度 83/100
維護者通常 1 天內回覆
-
[Bug]: fileUploadMatrix.test.ts URL case does a real DNS lookup and fails offline可能已有人在做 @r2jaff 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
ComposioHQ/composio#5054 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
pytorch/tensordict#3286 ·
維護者通常 1 天內回覆