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

ENH: Deprecate non-keyword arguments for Index.set_names. #41551

Merged
merged 11 commits into from May 27, 2021
Merged

ENH: Deprecate non-keyword arguments for Index.set_names. #41551

merged 11 commits into from May 27, 2021

Conversation

jmholzer
Copy link
Contributor

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM cc @MarcoGorelli

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Nice work, just some small requests

@@ -1526,6 +1527,7 @@ def _set_names(self, values, level=None) -> None:

names = property(fset=_set_names, fget=_get_names)

@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self", "names"])
Copy link
Member

Choose a reason for hiding this comment

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

Can you put version=None? I know I'd originally put version="2.0", but then other reviewers expressed a preference for not specifying the exact version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in my latest commit.

I think these changes also apply to the PR I opened for drop_duplicates (#41500)

Would you like me to make these changes there too?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please, thanks! Your help with these is much appreciated

Comment on lines 357 to 358
with tm.assert_produces_warning(FutureWarning, match=msg):
idx.set_names(["kind", "year"], None)
Copy link
Member

Choose a reason for hiding this comment

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

Can you also check the result? Again, I'm aware that I didn't do this in the example PR I opened, but then other reviewers suggested it - there's an example in #41511 . Same for the Series test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, added in the latest commit.

@simonjayhawkins simonjayhawkins added Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses labels May 21, 2021
@jreback jreback added this to the 1.3 milestone May 21, 2021
idx = MultiIndex.from_product([["python", "cobra"], [2018, 2019]])

msg = (
"In a future version of pandas all arguments of Index.set_names "
Copy link
Member

Choose a reason for hiding this comment

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

same as in the other PR, you'll probably need to define this for MultiIndex too (and remove @final) so that the warning shows MultiIndex.set_names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change in fc525c8.

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

There's a typing failure in multi.py (because we don't yet have overloads here - but those'll come once these deprecation warnings are in) - for now, could you just silence it? So

diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py
index 3c070889c1..269a73cd3c 100644
--- a/pandas/core/indexes/multi.py
+++ b/pandas/core/indexes/multi.py
@@ -3594,7 +3594,8 @@ class MultiIndex(Index):
         """
         names = self._maybe_match_names(other)
         if self.names != names:
-            return self.rename(names)
+            # Incompatible return value type (got "Optional[MultiIndex]", expected "MultiIndex")
+            return self.rename(names)  # type: ignore[return-value]
         return self
 
     def _maybe_match_names(self, other):

@jreback
Copy link
Contributor

jreback commented May 26, 2021

can you merge master

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks good, one suggesting for typing

@@ -3585,7 +3584,9 @@ def _get_reconciled_name_object(self, other) -> MultiIndex:
"""
names = self._maybe_match_names(other)
if self.names != names:
return self.rename(names)
# Incompatible return value type (got "Optional[MultiIndex]", expected
# "MultiIndex")
Copy link
Contributor

Choose a reason for hiding this comment

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

try doing assert isinstance(self, MultiIndex) here

Copy link
Member

Choose a reason for hiding this comment

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

That would work, but for things that will be fixed in the future (e.g. this one once all the overloads are in, which will come after positional arguments are deprecated) I think we've generally been ignoring the error

Copy link
Contributor

Choose a reason for hiding this comment

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

kk, then we can just merge this.

@jreback jreback merged commit 1fc9d7e into pandas-dev:master May 27, 2021
TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants