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

Added a decorator function to validate parameters #22193

Closed
wants to merge 3 commits into from
Closed

Added a decorator function to validate parameters #22193

wants to merge 3 commits into from

Conversation

shantanuo
Copy link

read_excel method needs to check if it has received valid parameters only. Use of **kwds allows any parameter that leads to confusion and bugs.

to be used as a decorator to validate keyword arguments
@pep8speaks
Copy link

pep8speaks commented Aug 3, 2018

Hello @shantanuo! Thanks for updating the PR.

Line 282:1: E302 expected 2 blank lines, found 1

Line 8:1: E302 expected 2 blank lines, found 1
Line 12:26: E225 missing whitespace around operator
Line 12:50: E231 missing whitespace after ','
Line 12:80: E501 line too long (122 > 79 characters)
Line 12:123: W291 trailing whitespace
Line 13:16: E128 continuation line under-indented for visual indent
Line 13:44: E241 multiple spaces after ','
Line 13:80: E501 line too long (120 > 79 characters)
Line 14:16: E128 continuation line under-indented for visual indent
Line 14:80: E501 line too long (85 > 79 characters)
Line 16:61: W291 trailing whitespace

Comment last updated on August 04, 2018 at 03:46 Hours UTC

@jbrockmendel
Copy link
Member

Take a look at pandas.util._validators.validate_kwargs

@WillAyd
Copy link
Member

WillAyd commented Aug 3, 2018

First and foremost this needs tests.

If this is only for read_excel then I think the decorator is overkill - would be better served directly within the function body.

Is this in reference a particular issue #? If so can you update your post to link to it?

@shantanuo
Copy link
Author

This is not only related to "read_excel" function. All read_* methods accept *kwargs due to which non-valid parameters are allowed.

#22189

This is the only issue that is holding me back from using pandas and therefore I tried to fix it :)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

I still think the wrapper is overcomplicating things. As mentioned before tests are the most critical thing here and ideally should come before any other coding changes

def _validate_kwarg(func):
@wraps(func)
def wrapper(*args, **kwargs):
expected_keys=['io', 'sheet_name','header', 'names', 'index_col', 'usecols', 'squeeze', 'dtype', 'engine',
Copy link
Member

Choose a reason for hiding this comment

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

Just instantiate this as a set

'date_parser', 'thousands', 'comment', 'skipfooter', 'convert_float']

if set(kwargs.keys()).difference(set(expected_keys)):
raise ValueError('invalid parameter found')
Copy link
Member

@WillAyd WillAyd Aug 4, 2018

Choose a reason for hiding this comment

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

Would be nice to be explicit about which parameter isn't working. Also need a test

@WillAyd WillAyd added the Error Reporting Incorrect or improved errors from pandas label Aug 4, 2018
@TomAugspurger
Copy link
Contributor

I think we should focus our efforts on removing the need for **kwargs from the signature, rather than trying to work around it.

@shantanuo
Copy link
Author

sure. Decorator was my shortcut to incorporate the functionality that I needed desperately :)

@jbrockmendel
Copy link
Member

Am I missing something? Why is the existing validate_kwargs decorator not up to the task?

@shantanuo
Copy link
Author

I checked the existing validate_kwargs decorator, but could not figure out how to use it :)
Removing **kwargs seems to be ideal though. Any one of the two (that is practical, easy and quick) approach should be adopted.

@jbrockmendel
Copy link
Member

@shantanuo any plans to add a test to this? I doubt this implementation will be merged, but a test could help us figure out how to use the existing decorators for this purpose.

@jreback
Copy link
Contributor

jreback commented Nov 23, 2018

closing as stale. if you'd like to continue, pls ping.

@jreback jreback closed this Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants