Skip to content

Timestamp.strptime %z not supported #25016

Closed
@josham

Description

@josham

Code Sample, a copy-pastable example if possible

fmt = '%Y%m%d-%H%M%S-%f%z'
ts = '20190129-235348-183747+0000'
pd.Timestamp.strptime(ts, fmt)
Traceback (most recent call last):
  File "/scratch.py", line 6, in <module>
    pd.Timestamp.strptime(ts, fmt)
  File "/python/lib/python3.6/_strptime.py", line 576, in _strptime_datetime
    return cls(*args)
  File "pandas/_libs/tslibs/timestamps.pyx", line 748, in pandas._libs.tslibs.timestamps.Timestamp.__new__
TypeError: an integer is required

Problem description

Timestamp.strptime does not support %z. Issue was fixed with pd.to_datetime in #19979.

Expected Output

The same as pd.to_datetime(ts, format=fmt):

Timestamp('2019-01-29 23:53:48.183747+0000', tz='UTC')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-43-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C.UTF-8
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.0
pytest: 4.1.1
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.0
bs4: None
html5lib: None
sqlalchemy: 1.2.16
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions