Skip to content

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

Merged
mkumar73 merged 2 commits into
OpenTabular:mainfrom
xillig:fix/preprocessor-empty-input
Nov 26, 2026
Merged

mkumar73 merged 2 commits into
OpenTabular:mainfrom
xillig:fix/preprocessor-empty-input

Conversation

@xillig

@xillig xillig commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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.

xillig and others added 2 commits November 11, 2026 05:28
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.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mkumar73 mkumar73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xillig , thank you for your contribution. The changes raises EmptyDataError instead of crashing with division by zero.

  • CI successful.
  • PR approved.

@mkumar73
mkumar73 merged commit 9717fef into OpenTabular:main Nov 26, 2026
35 of 37 checks passed
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.

3 participants