Skip to content

BUG: read_sql parse_dates does not allow for "errors" arg #35185

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

Closed
2 of 3 tasks
Trollgeir opened this issue Jul 8, 2020 · 1 comment · Fixed by #37823
Closed
2 of 3 tasks

BUG: read_sql parse_dates does not allow for "errors" arg #35185

Trollgeir opened this issue Jul 8, 2020 · 1 comment · Fixed by #37823
Assignees
Labels
Bug IO SQL to_sql, read_sql, read_sql_query
Milestone

Comments

@Trollgeir
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import pandas

query = ...
connection = ...
parse_dates_dict = {'column_name': {'errors': 'coerce'}}
pandas.read_sql(query, parse_dates=parse_dates_dict)

Problem description

According to the api for read_sql, the parse_date argument should be able to contain a dict of dicts with kwargs per column to be passed along to pandas.to_datetime(), as shown in the example above.

However, this will result in the error:
TypeError: to_datetime() got multiple values for keyword argument 'errors'

This is because of this line of code:
return to_datetime(col, errors="ignore", **format) - where format is our kwargs from that specific column.
Specifically, the hardcoded errors argument collides with the passed kwarg.

It seems like the errors argument cannot be overridden by kwargs in this implementation.

Expected Output

Expect errors arg in to be overridden by the kwargs argument, or that the documentation explicitly says that it cannot be overridden for some reason.

@Trollgeir Trollgeir added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 8, 2020
@simonjayhawkins simonjayhawkins added IO SQL to_sql, read_sql, read_sql_query and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 9, 2020
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Jul 9, 2020
@avinashpancham
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
4 participants