当源 dtype 已经匹配时,load_dataset 会默默地接受超出范围的 ClassLabel 索引
作者: caiotheodoro创建于 2026年9月10日更新于 2026年9月16日
`table_cast` in `src/datasets/table.py` only runs the feature-level cast (`cast_table_to_schema`, which calls `ClassLabel.cast_storage` and does the range check) when the Arrow schema itself changes. `pa.Schema.__eq__` ignores metadata, so when the file's native dtype (`int64` for JSON/Parquet integers) already equals the `ClassLabel`'s storage dtype, only the schema *metadata* differs and `table_cast` takes the cheap `table.replace_schema_metadata(schema.metadata)` branch, never calling `cast_array_to_feature`. `from_dict`/`from_pylist` don't go through `table_cast` for this — they encode through the feature directly, which is why they still validate.
内容来源: huggingface/datasets