Skip to content

[tabulate] Accept pandas.DataFrame in tabulate() - #16730

Open
hrithiksaini99 wants to merge 1 commit into
python:mainfrom
hrithiksaini99:fix/16708-tabulate-dataframe
Open

hrithiksaini99 wants to merge 1 commit into
python:mainfrom
hrithiksaini99:fix/16708-tabulate-dataframe

Conversation

@hrithiksaini99

Copy link
Copy Markdown
Contributor

Problem

tabulate() accepts a pandas.DataFrame at runtime (per the PyPI description), but the stub only allowed Mapping[Any, Iterable[Any]] | Iterable[Iterable[Any]]. A DataFrame iterates as column names (Iterable[Hashable]), so:

import tabulate
import pandas as pd
tabulate.tabulate(pd.DataFrame({}))
# error: Argument 1 to "tabulate" has incompatible type "DataFrame" [arg-type]

(reported in #16708 with pandas-stubs installed)

Fix

  • Widen tabular_data to Mapping[Any, Iterable[Any]] | Iterable[Any] — Iterable[Any] covers DataFrame's column-name iteration and runtime acceptance
  • METADATA.toml: add pandas-stubs dependency for @tests
  • New @tests/test_cases/check_tabulate.py with assert_type coverage for DataFrame, rows, and mapping forms

Verification

python tests/mypy_test.py stubs/tabulate   # success
python tests/regr_test.py tabulate         # success

ruff check + format clean.

Fixes #16708.

Fixes python#16708. tabulate() accepts a pandas.DataFrame at runtime (per
the PyPI description) and it iterates as column names
(Iterable[Hashable]), but the stub only allowed
Mapping[Any, Iterable[Any]] | Iterable[Iterable[Any]], so:

  tabulate(pd.DataFrame({}))

was rejected with arg-type.

- Widen tabular_data to Mapping[Any, Iterable[Any]] | Iterable[Any]
  (Iterable[Any] covers DataFrame's Hashable iteration and runtime
  acceptance; existing Mapping/rows forms still checked)
- METADATA: add pandas-stubs dependency for @tests
- New @tests/test_cases/check_tabulate.py with assert_type coverage

Verified: mypy_test stubs/tabulate success, regr_test tabulate
success, ruff + format clean.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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

1 participant