Skip to content

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

Closed
@Trollgeir

Description

@Trollgeir
  • 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.

Metadata

Metadata

Labels

BugIO SQLto_sql, read_sql, read_sql_query

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions