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

Add stub for Styler.map_index #905

Merged
merged 5 commits into from
Apr 10, 2024
Merged

Conversation

cquick01
Copy link
Contributor

@@ -218,6 +218,13 @@ class Styler(StylerRenderer):
level: Level | list[Level] | None = ...,
**kwargs: Any,
) -> Styler: ...
def map_index(
self,
func: Callable[[Series], npt.NDArray[np.str_] | list[str] | Series[str]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on the docs, I think this should be Callable[[Scalar], str]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I updated to Callable[[Scalar], str | None] to match the docs

Comment on lines 66 to 75
def test_map_index() -> None:
def f(s: Series) -> npt.NDArray[np.str_]:
return np.asarray(s, dtype=np.str_)

check(assert_type(DF.style.map_index(f), Styler), Styler)

def f1(s: Series) -> Series[str]:
return Series(s, dtype=str)

check(assert_type(DF.style.map_index(f1), Styler), Styler)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests should be modified to something similar to what you see in the docs for map_index()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to show the first example from the docs. The second one showed the following error

    def f1(s: Scalar):
        return "background-color: yellow;" if "x" in s else None
                                              ~~~~~~~~
Unsupported right operand type for in ("str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex")

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 @cquick01

@Dr-Irv Dr-Irv merged commit b30d777 into pandas-dev:main Apr 10, 2024
13 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.

2 participants