Skip to content

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

Merged
merged 2 commits into from
Nov 17, 2019

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Nov 14, 2019

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?

@topper-123 topper-123 changed the title CLN: Make non-empty kwargs fail CLN: Make non-empty **kwargs in Index.__new__ fail instead of silently dropped Nov 14, 2019
@@ -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)
Copy link
Contributor Author

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")
Copy link
Contributor Author

@topper-123 topper-123 Nov 14, 2019

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.

@topper-123 topper-123 force-pushed the Index._simple_kwargs branch 3 times, most recently from 2942d5e to af7b800 Compare November 15, 2019 10:55
if len(kwargs) == 1:
msg = f"Unexpected keyword argument {list(kwargs)[0]!r}"
else:
msg = f"Unexpected keyword arguments {set(kwargs)!r}"
Copy link
Contributor

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

@jreback jreback added the Clean label Nov 16, 2019
@jreback jreback added this to the 1.0 milestone Nov 16, 2019
@jreback
Copy link
Contributor

jreback commented Nov 16, 2019

lgtm. merge on green.

@topper-123 topper-123 merged commit 797732a into pandas-dev:master Nov 17, 2019
@topper-123 topper-123 deleted the Index._simple_kwargs branch November 17, 2019 10:23
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants