-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Make non-empty **kwargs in Index.__new__ fail instead of silently dropped #29625
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
CLN: Make non-empty **kwargs in Index.__new__ fail instead of silently dropped #29625
Conversation
pandas/core/indexes/base.py
Outdated
@@ -4259,7 +4266,8 @@ def _concat_same_dtype(self, to_concat, name): | |||
Concatenate to_concat which has the same class. | |||
""" | |||
# must be overridden in specific classes | |||
klasses = (ABCDatetimeIndex, ABCTimedeltaIndex, ABCPeriodIndex, ExtensionArray) | |||
klasses = (ABCDatetimeIndex, ABCTimedeltaIndex, ABCPeriodIndex, ExtensionArray, | |||
ABCIntervalIndex) |
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.
Without this, if the first element is a IntervalIndex, a"side" parameter is passed to _shallow_copy_with_infer
ind the call will fail.
) | ||
tm.assert_index_equal(result, expected) | ||
|
||
result = pd.Index(index, names=["A", "B"]) | ||
result = pd.Index(index, name="A") |
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.
Both result and expected are normal Index
instances and instantiating with a names
parameter should fail.
2942d5e
to
af7b800
Compare
af7b800
to
ac76102
Compare
pandas/core/indexes/base.py
Outdated
if len(kwargs) == 1: | ||
msg = f"Unexpected keyword argument {list(kwargs)[0]!r}" | ||
else: | ||
msg = f"Unexpected keyword arguments {set(kwargs)!r}" |
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.
I would just use this one (the set), no need to make a super-detailed error message
lgtm. merge on green. |
30219fc
to
d2cd11e
Compare
In #29624 I made change so random kwargs weren't passed to
Index._simple_new
. I'v found out after merging that the selected solution dropped non-empty kwargs, which isn't great either.This version ensures that passing non-accepted kwargs raises, so
pd.Index(['a'], foo="foo")
raises a TypeError. Instead of raising a TypeError, should we deprecate adding non-accepted kwargs?