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 · Fixed by #25124
Closed

Timestamp.strptime %z not supported #25016

josham opened this issue Jan 30, 2019 · 4 comments · Fixed by #25124
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@josham
Copy link
Contributor

josham 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
Copy link
Member

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.

@mroeschke mroeschke added Bug Timezones Timezone data dtype labels Jan 30, 2019
@saurav2608
Copy link

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

@alimcmaster1
Copy link
Member

Go for it, unless @mroeschke was planning on?

@mroeschke
Copy link
Member

Sure go for it @saurav2608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants