Unexpected 'to_datetime' behaviour for datetime strings with different offset in 'arg', when errors='coerce' · Issue #26122 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd arr = ['March 1, 2018 12:00:00+0400', 'March 1, 2018 12:00:00+0500', '20100240'] result = pd.to_datetime(arr, errors='coerce')

>>> result:
Index(['March 1, 2018 12:00:00+0400', 'March 1, 2018 12:00:00+0500', '20100240'], dtype='object')

Problem description

In to_datetime docstring:
- If 'coerce', then invalid parsing will be set as NaT

So.. it seems to me, that this is unexpected behaviour

Expected Output

>>> result:
Index([2018-03-01 12:00:00+04:00, 2018-03-01 12:00:00+05:00, NaT], dtype='object')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.2
pytest: 4.3.0
pip: 19.0.3
setuptools: 39.0.1
Cython: 0.29.3
numpy: 1.16.0
scipy: 1.2.1
pyarrow: None
xarray: 0.11.3
IPython: 7.3.0
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.5.12
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.5
lxml.etree: 4.3.2
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.1
pymysql: 0.9.3
psycopg2: 2.7.7 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.2.0
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None