Skip to content

pandas Styler has no .columns attr defined #1102

Closed
@thatlittleboy

Description

@thatlittleboy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stylerconditional formatting using DataFrame.stylegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions