BUG: read_sql parse_dates does not allow for "errors" arg · Issue #35185 · pandas-dev/pandas (original) (raw)


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.