Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandas Styler has no .columns attr defined #1102

Open
thatlittleboy opened this issue Jan 29, 2025 · 1 comment
Open

pandas Styler has no .columns attr defined #1102

thatlittleboy opened this issue Jan 29, 2025 · 1 comment
Labels
pandas_docs For issues where there is a conflict in behavior with pandas docs and stubs that needs resolution Styler conditional formatting using DataFrame.style

Comments

@thatlittleboy
Copy link

Describe the bug

pandas Styler has no .columns attr defined in the stubs.

To Reproduce

  1. Minimal example, save in a file named t.py
from typing import reveal_type
import pandas as pd
from pandas.io.formats import style as pd_style


def f(s: pd_style.Styler) -> pd_style.Styler:
    print(s.columns)
    fmt = "{:.2%}"
    return s.format(fmt)


df = pd.DataFrame({"a": [1, 2, 3]})
df2 = df.style.pipe(f)
reveal_type(df2)
  1. Run with mypy mypy t.py
  2. error message
t.py:7: error: "Styler" has no attribute "columns"  [attr-defined]
t.py:14: note: Revealed type is "pandas.io.formats.style.Styler"
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: MacOS
  • OS Version Sonoma 14.4.1
  • python version 3.12
  • version of type checker mypy 1.14.1 (compiled: yes)
  • version of installed pandas-stubs 2.2.3.241126

Additional context

the StyleRenderer base class has columns defined in __init__.

https://github.com/pandas-dev/pandas/blob/8973c551895c2cd3619cadf554362e802b27e02a/pandas/io/formats/style_render.py#L100

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 29, 2025

Issue here is that Styler.columns is not documented in pandas, and the stubs only supports what is documented.

I've created pandas-dev/pandas#60815 . Once that is resolved, then a PR is welcome to fix this here.

@Dr-Irv Dr-Irv added Styler conditional formatting using DataFrame.style Docs pandas_docs For issues where there is a conflict in behavior with pandas docs and stubs that needs resolution and removed Docs labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pandas_docs For issues where there is a conflict in behavior with pandas docs and stubs that needs resolution Styler conditional formatting using DataFrame.style
Projects
None yet
Development

No branches or pull requests

2 participants