-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Conversation
pandas-stubs/io/formats/style.pyi
Outdated
@@ -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]], |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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
tests/test_styler.py
Outdated
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) |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cquick01
Closes #xxxx (Replace xxxx with the Github issue number)
Couldn't find an issue, but it might belong in Version 2.0 Compatibility Tracker #624. This is for this method https://github.com/pandas-dev/pandas/blob/5232bee8df3b57766c44b62152aa3fdd24e40ada/pandas/io/formats/style.py#L2018
The function signature in code is
but this looks to be the same as how
Styler.apply_index
is defined in code, but the stub is a little different so I just copied that insteadTests added: Adds
test_styler.test_map_index
, similarly adapted fromtest_apply_index