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

Complete support for csv.Reader class signature. #232

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

eduardostalinho
Copy link

This PR is an alternate to #209. It tries to get all parameters from import_from_csv kwargs falling back to its dialect parameters.

The relationship between csv.Reader dialect and the other params is a little intrincated, so we decided to run the merge between dialect and the other params before the readers does and overwrite the user given parameters.

@filipeximenes
Copy link

@eduardostalinho since we are already doing the merge should we drop passing the dialect?

reader = unicodecsv.reader(fobj, encoding=encoding, **reader_kwargs)

@@ -47,6 +47,8 @@ def discover_dialect(sample, encoding):
# Could not detect dialect, fall back to 'excel'
return unicodecsv.excel

def get_dialect_parameters(params, dialect, parameter):
return params.pop(parameter, getattr(dialect, parameter))

Choose a reason for hiding this comment

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

Any special reason for poping the parameter? Should we only get to avoid messing with them? The downside of pop would be someone trying to do something else with kwargs attributes after get_dialect_parameters only to find out the it's not there anymore.

Copy link
Author

Choose a reason for hiding this comment

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

The reason of kwargs poping is not messing the future calls that use kwargs in the same functions.
Using *args and **kwargs is always a decision on where the code will be messed up.

@turicas
Copy link
Owner

turicas commented Jul 27, 2017

@filipeximenes dropping the dialect will break backwards compatibility and also will not follow the Python's csv module API (since you can pass either the dialect or the parameters).

@filipeximenes
Copy link

LGTM

This function pops keys instead of getting them.
@eduardostalinho
Copy link
Author

updated @turicas @filipeximenes

@eduardostalinho
Copy link
Author

@turicas i think you can close this PR without merge.

@turicas turicas force-pushed the develop branch 2 times, most recently from fa144f0 to bbb2c57 Compare November 30, 2018 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants