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 should have alternate constructor for UTC millisecond timestamps #3540

Closed
wesm opened this issue May 7, 2013 · 3 comments · Fixed by #3818
Closed

Timestamp should have alternate constructor for UTC millisecond timestamps #3540

wesm opened this issue May 7, 2013 · 3 comments · Fixed by #3818
Labels
Datetime Datetime data dtype Enhancement
Milestone

Comments

@wesm
Copy link
Member

wesm commented May 7, 2013

Was surprised at how difficult it was to convert a unix timestamp to a pandas Timestamp recently

@jreback
Copy link
Contributor

jreback commented May 13, 2013

I think an API like:

pd.to_datetime(values, unit='s')
Timestamp(value,unit='s')

might be all that we need, in that the unit is a hint that I am giving you something that this is in these units

e.g. right now the default is (so no conversion from int needed)

In [9]: Timestamp(1368431149000000000, unit='ns')
Out[9]: <Timestamp: 2013-05-13 07:45:49>

http://stackoverflow.com/questions/16517240/pandas-using-unix-epoch-timestamp-as-datetime-index

In [3]: np.array([1368431149, 1368431150]).astype('datetime64[s]')
Out[3]: array([2013-05-13 07:45:49, 2013-05-13 07:45:50], dtype=datetime64[s])

In [4]: pd.to_datetime(np.array([1368431149, 1368431150])*int(1e6))
Out[4]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[1970-01-16 20:07:11.149000, 1970-01-16 20:07:11.150000]
Length: 2, Freq: None, Timezone: None

In [5]: pd.to_datetime(np.array([1368431149, 1368431150])*int(1e9))
Out[5]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-05-13 07:45:49, 2013-05-13 07:45:50]
Length: 2, Freq: None, Timezone: None

@jreback
Copy link
Contributor

jreback commented Jun 9, 2013

@hayd what do u think about this API?

@hayd
Copy link
Contributor

hayd commented Jun 9, 2013

I think unit is descriptive, I like it.

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

Successfully merging a pull request may close this issue.

3 participants