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.fromordinal Exception AttributeError #3042

Closed
michaelaye opened this issue Mar 13, 2013 · 4 comments · Fixed by #3138
Closed

Timestamp.fromordinal Exception AttributeError #3042

michaelaye opened this issue Mar 13, 2013 · 4 comments · Fixed by #3138
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@michaelaye
Copy link
Contributor

I have a datetime.datetime, convert it to ordinal and try to read it back with pd.Timestamp.fromordinal(). This produces the following error:

In [112]: dt
Out[112]: datetime.datetime(2011, 4, 16, 0, 0)

In [113]: pd.Timestamp.fromordinal(dt.toordinal())
Exception AttributeError: "'int' object has no attribute 'utcoffset'" in 'pandas.tslib._localize_tso' ignored
Out[113]: <Timestamp: 1970-01-01 00:00:00.000002011>

Am I expecting something wrong by thinking this should work or is it a bug?

@jreback
Copy link
Contributor

jreback commented Mar 22, 2013

This was a bug, fixed in #3138

In [3]: dt = datetime.datetime(2011, 4, 16, 0, 0)

In [5]: pd.Timestamp.fromordinal(dt.toordinal())
Out[5]: <Timestamp: 2011-04-16 00:00:00>

In [6]: pd.Timestamp.fromordinal(dt.toordinal(),tz='US/Eastern')
Out[6]: <Timestamp: 2011-04-16 00:00:00-0400 EDT, tz=US/Eastern>

@jreback jreback closed this as completed Mar 22, 2013
@loretoparisi
Copy link

@jreback I get this error in

root@0886ae974430:~/GRU4Rec/examples/rsc15# python -c "import pandas; print(pandas . __version__)"
0.20.3

and

Traceback (most recent call last):
  File "preprocess.py", line 32, in <module>
    data['Time'] = data.TimeStr.apply(lambda x: dt.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.%fZ').timestamp()) #This is not UTC. It does not really matter.
  File "/usr/local/lib/python2.7/dist-packages/pandas/core/series.py", line 2355, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/_libs/src/inference.pyx", line 1574, in pandas._libs.lib.map_infer (pandas/_libs/lib.c:66645)
  File "preprocess.py", line 32, in <lambda>
    data['Time'] = data.TimeStr.apply(lambda x: dt.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S.%fZ').timestamp()) #This is not UTC. It does not really matter.
AttributeError: 'datetime.datetime' object has no attribute 'timestamp'
root@0886ae974430:~/GRU4Rec/examples/rsc15# python -c "import pandas; print("pandas . __version__)"
bash: syntax error near unexpected token `)'

@michaelaye
Copy link
Contributor Author

michaelaye commented Jul 25, 2017

What's that timestamp method you are trying to use? The dt.datetime object certainly doesn't have such method, as the error precisely says.
But I'm confused, neither me nor Jeff did use a timestamp method?

@loretoparisi
Copy link

@michaelaye Hello, thank you, I have realized that this was due to python3, so I have solved it moving to python3, pip3 etc.!

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

Successfully merging a pull request may close this issue.

3 participants