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

GH1139 Series.rename inplace #1140

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

loicdiridollou
Copy link
Contributor

@loicdiridollou loicdiridollou commented Mar 2, 2025

Added some test framework migration as this was how I originally found the issue with rename

Comment on lines 1044 to 1057
def rename( # pyright: ignore[reportOverlappingOverload]
self,
index: Renamer | Hashable | None = ...,
index: Hashable = ...,
*,
axis: Axis | None = ...,
copy: bool = ...,
inplace: Literal[True],
level: Level | None = ...,
errors: IgnoreRaise = ...,
) -> Self: ...
@overload
def rename( # type: ignore[overload-cannot-match]
self,
index: Renamer | None = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

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

reverse the order of these two, and then make the one with Hashable be index: Hashable so that it has to be specified. That will change the ignore-related comments as well.

@@ -1137,7 +1138,6 @@ def test_types_set_flags() -> None:

def test_types_getitem() -> None:
s = pd.Series({"key": [0, 1, 2, 3]})
key: list[int] = s["key"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this was supposed to be a test. Should be

    check(assert_type(s["key"], Any), list)

Comment on lines 1231 to 1234
check(
assert_type(pd.Series([1, 2, 3]).rename("A", inplace=True), "pd.Series[int]"),
pd.Series,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should add a test for specifying inplace=True with index=None being explicit, as well as a test for specifying inplace=True with index being a dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last issue is that when you have a lambda then it will match to Hashable and not Renamer so that is still an issue.
Feel free to offer feedback and release without this one, it is fine to wait till we make it right.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Mar 4, 2025

@loicdiridollou let me know when you think you'll get to this. I'd like to do a new release soon, and want to know if I should wait for this change or not.

@loicdiridollou
Copy link
Contributor Author

loicdiridollou commented Mar 4, 2025 via email

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.

Series().rename(..., inplace=True) can return a Series if the renamer is hashable
2 participants