Skip to content

Add index and columns as properties to Styler #1135

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

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

Rishab260
Copy link
Contributor

@Rishab260 Rishab260 commented Mar 1, 2025

Changes As Per Discussion

  • Addition of index and columns to Styler in style.pyi
  • Addition of tests in tests/test_style.py for testing index and columns

Related Issues and PRs

Also See [Source: link ]

from typing_extensions 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)

Output:

$ mypy pandas-stubs/mytest/t.py
pandas-stubs/mytest/t.py:14: note: Revealed type is "pandas.io.formats.style.Styler"
Success: no issues found in 1 source file

Additional Comments

First PR on pandas-stubs, your feedback will be highly valuable to me, Thanks!

@Rishab260
Copy link
Contributor Author

/pandas_nightly

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

You have issues with some formatting and ordering of imports.

You should set up the pre-commit so things are properly formatted. See the output here:
https://github.com/pandas-dev/pandas-stubs/actions/runs/13605234204/job/38040314429?pr=1135

And instructions here for setting up your local testing environment:
https://github.com/pandas-dev/pandas-stubs/blob/main/docs/setup.md

@Rishab260
Copy link
Contributor Author

You have issues with some formatting and ordering of imports.

You should set up the pre-commit so things are properly formatted. See the output here:
https://github.com/pandas-dev/pandas-stubs/actions/runs/13605234204/job/38040314429?pr=1135

And instructions here for setting up your local testing environment:
https://github.com/pandas-dev/pandas-stubs/blob/main/docs/setup.md

Sure, I will make the changes, I actually had some trouble setting up the development environment following those instructions. For some reason unless I disable the KMP_AFFINITY pytest just crashes.

@Rishab260
Copy link
Contributor Author

/pandas_nightly

@Rishab260
Copy link
Contributor Author

You have issues with some formatting and ordering of imports.

You should set up the pre-commit so things are properly formatted. See the output here: https://github.com/pandas-dev/pandas-stubs/actions/runs/13605234204/job/38040314429?pr=1135

And instructions here for setting up your local testing environment: https://github.com/pandas-dev/pandas-stubs/blob/main/docs/setup.md

Hi @Dr-Irv, This is now completed, PTAL. Thanks for the instructions and feedback.

@Rishab260 Rishab260 requested a review from Dr-Irv March 2, 2025 09:21
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @Rishab260

@Dr-Irv Dr-Irv merged commit 2d69a57 into pandas-dev:main Mar 3, 2025
11 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.

pandas Styler has no .columns attr defined
2 participants