-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Index constructor doesn't validate kwargs #26974
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
Comments
Is the goal in pandas, to raise an exception whenever a non-existing kwarg is used? |
Yes. |
Hi, is there someone working for it? If not, can I make PR for this? |
Sure. Here's how I would do it. Start in pandas/pandas/core/indexes/base.py Line 259 in e26fa2b
**kwargs . This will be index subclasses like Categorical , IntervalIndex , PeriodIndex , etc. Find the set of arguments that those accept. If any of them accept **kwargs , then we should start by narrowing down the valid set of kwargs first (in its own PR, one per subclass).
@jreback @jorisvandenbossche two API questions:
|
They are currently passed through? |
Yes. The method depends a bit on the subclass. I glanced briefly, but |
We could also deprecate that? if you want the specific keywords, you can use the specific class constructor?
I would lean towards first a warning. Users could have unintentionally done this (eg typo). |
Thanks for detail explanation. I'll make a work for this - raise a error or just add warning. |
@TomAugspurger I try to modify code - make a warning for invalid kwargs. |
Here's how I might do this:
Does that make sense? |
@TomAugspurger First, I checked that every subclass doesn't take I was confused about always pass Then is it enough to add validate code below
Then users can see warnings while calling |
I don't think the maintainers have agreed on a desired behavior yet, sorry. In another issue (can't find it now) @WillAyd expressed displeasure with accepting both cc @jreback if you have thoughts on not passing through subclass-specific kwargs. |
I'm not super familiar with all of the classes at play but do we even really need kwargs? Would rather align signatures where possible and handle signature exceptions as needed (is name(s) the only one?) |
we don’t really need kwargs but is simpler for example IntervalIndex has closed kwarg this needs to be passed when u construct from Index (and not II directly) |
But then if a user wants to use this keyword, then can use the |
sure though we currently allow one way to construct indexes via Index |
Yes, sure, so we would need to do this with a deprecation, if we want to do this. In practice, to fix the original issue in this PR (validating kwargs), we don't need to disallow this, as those kwargs could be validated on the level of specific index constructors. This is basically what Tom proposed above at #26974 (comment) |
i agree with this proposed soon: #26974 (comment) |
Alrighty, sorry for bringing that other discussion in here. For now @bartkim0426 can you implement #26974 (comment)?
The idea would be for |
@TomAugspurger I still confused is it the right way to validate all |
Ideally you only need to worry about the last one. Since all the subclass |
This should raise, since
abc
isn't a valid keyword.The text was updated successfully, but these errors were encountered: