Skip to content

fix(preprocessor): raise a typed error for input without rows at fit - #138

Open
xillig wants to merge 1 commit into
OpenTabular:mainfrom
xillig:fix/preprocessor-empty-input
Open

xillig wants to merge 1 commit into
OpenTabular:mainfrom
xillig:fix/preprocessor-empty-input

Conversation

@xillig

@xillig xillig commented Nov 11, 2026

Copy link
Copy Markdown

Problem

Preprocessor.fit on input with columns but no rows failed with a bare ZeroDivisionError: column-type detection divides the number of unique values by the row count for the cat_cutoff ratio.

import pandas as pd
from pretab import Preprocessor
Preprocessor().fit(pd.DataFrame({"x": pd.Series([], dtype=float)}), [])  # ZeroDivisionError

Fix

detect_column_types raises EmptyDataError (already exported; a PretabDataError and a ValueError, scikit-learn's convention for empty training data) naming the estimator and the input shape. Input without columns keeps fitting to an empty output.

Tests and docs

Unit tests in tests/compose/test_feature_detection.py, end-to-end tests for DataFrame / ndarray / dict in tests/regression/test_edge_cases.py; the fit docstring and the edge-case list in choosing_a_method.md are updated.

Validation

Checks: full suite (2554 passed, 59 skipped, 7 xfailed, coverage >= 94.79%), ruff format / ruff check, pyright (no new diagnostics), docs build with -W, scripts/quickstart.py. Merges cleanly with main and with #136.

Preprocessor.fit on a frame, array or dict with columns but no rows
failed with a bare ZeroDivisionError: column-type detection divides the
number of unique values by the row count for the cat_cutoff ratio.

detect_column_types now raises EmptyDataError (a PretabDataError and a
ValueError, scikit-learn's convention for empty training data) that names
the estimator and the input shape. Input without columns keeps fitting
to an empty output, as before.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant