Skip to content

pd.to_datetime errors args cause inconsistent behavior wrt to timestamp limitations #19844

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
connerxyz opened this issue Feb 22, 2018 · 1 comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request

Comments

@connerxyz
Copy link

Code Sample

df = pd.DataFrame({"date": ['10000101', '20180220']})

# Timestamp limitations correctly raise exception
pd.to_datetime(df.date, errors='raise')
...
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1000-01-01 00:00:00

# Timestamp limitations correctly coerce to NaT
pd.to_datetime(df.date, errors='coerce')
...
0          NaT
1   2018-02-20
Name: date, dtype: datetime64[ns]

# errors=`ignore` incorrectly results in datetime like object
pd.to_datetime(df.date, errors='ignore', format="%Y%m%d")
0    1000-01-01 00:00:00
1    2018-02-20 00:00:00
Name: date, dtype: object

Problem description

I believe that when errors='ignore', and the timestamp limitations are violated by a datum, the result should be the original input – not a datetime like object.

Expected Output

pd.to_datetime(df.date, errors='ignore', format="%Y%m%d")
0    '10000101'
1    2018-02-20 00:00:00
Name: date, dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.21.0
pytest: 2.9.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
pyarrow: None
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
feather: None
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Feb 23, 2018

this is a duplicate of #14487
@connercowling would you like to do a PR for this?

@jreback jreback closed this as completed Feb 23, 2018
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions API Design Duplicate Report Duplicate issue or pull request labels Feb 23, 2018
@jreback jreback added this to the No action milestone Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants