Skip to content
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

Timestamp.strptime %z not supported #25016

Closed
josham opened this issue Jan 30, 2019 · 4 comments

Comments

@josham
Copy link
Contributor

commented Jan 30, 2019

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

@mroeschke

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

Thanks for the report.

The fix is luckily straightforward.

--- a/pandas/_libs/tslibs/timestamps.pyx
+++ b/pandas/_libs/tslibs/timestamps.pyx
@@ -736,8 +736,8 @@ class Timestamp(_Timestamp):
             # microsecond[, nanosecond[, tzinfo]]]]]])
             ts_input = datetime(ts_input, freq, tz, unit or 0,
                                 year or 0, month or 0, day or 0)
-            nanosecond = hour
-            tz = minute
+            nanosecond = minute
+            tz = hour
             freq = None

However, we need to make an API change in the Timestamp constructor as well and switch the positions of the tzinfo and nanosecond arguments.

@saurav2608

This comment has been minimized.

Copy link
Contributor

commented Feb 1, 2019

Can I give this a try if no one is working on this?

@alimcmaster1

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2019

Go for it, unless @mroeschke was planning on?

@mroeschke

This comment has been minimized.

Copy link
Member

commented Feb 2, 2019

Sure go for it @saurav2608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.