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

implementation of from_julian_date() #11276

Closed
sebhahn opened this Issue Oct 9, 2015 · 9 comments

Comments

Projects
None yet
4 participants
@sebhahn

sebhahn commented Oct 9, 2015

pandas.DatetimeIndex supports a method called to_julian_date() would it be easily possible to support a function/method doing the opposite, i.e. from_julian_date()?

@chris-b1

This comment has been minimized.

Show comment
Hide comment
@chris-b1

chris-b1 Oct 9, 2015

Contributor

fyi, this is somewhat easy to do with the current to_datetime, just subtract the offset and specify that the unit is days.

In [66]: julian_dates = pd.date_range('2014-1-1', periods=10).to_julian_date().values

In [67]: julian_dates
Out[67]: 
array([ 2456658.5,  2456659.5,  2456660.5,  2456661.5,  2456662.5,
        2456663.5,  2456664.5,  2456665.5,  2456666.5,  2456667.5])

In [68]: pd.to_datetime(julian_dates - pd.Timestamp(0).to_julian_date(), unit='D')
Out[68]: 
DatetimeIndex(['2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04',
               '2014-01-05', '2014-01-06', '2014-01-07', '2014-01-08',
               '2014-01-09', '2014-01-10'],
              dtype='datetime64[ns]', freq=None)
Contributor

chris-b1 commented Oct 9, 2015

fyi, this is somewhat easy to do with the current to_datetime, just subtract the offset and specify that the unit is days.

In [66]: julian_dates = pd.date_range('2014-1-1', periods=10).to_julian_date().values

In [67]: julian_dates
Out[67]: 
array([ 2456658.5,  2456659.5,  2456660.5,  2456661.5,  2456662.5,
        2456663.5,  2456664.5,  2456665.5,  2456666.5,  2456667.5])

In [68]: pd.to_datetime(julian_dates - pd.Timestamp(0).to_julian_date(), unit='D')
Out[68]: 
DatetimeIndex(['2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04',
               '2014-01-05', '2014-01-06', '2014-01-07', '2014-01-08',
               '2014-01-09', '2014-01-10'],
              dtype='datetime64[ns]', freq=None)
@sebhahn

This comment has been minimized.

Show comment
Hide comment
@sebhahn

sebhahn Oct 9, 2015

interesting solution, thank you very much for that!

sebhahn commented Oct 9, 2015

interesting solution, thank you very much for that!

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 9, 2015

Contributor

I think this would not be unreasonable to have pd.to_datetime(....., ,unit='julian')
I guess as long as making things up DatetimeIndex.astype('datetime64[julian]') prob a bit much

We don't have any from_* for this kind of thing

Contributor

jreback commented Oct 9, 2015

I think this would not be unreasonable to have pd.to_datetime(....., ,unit='julian')
I guess as long as making things up DatetimeIndex.astype('datetime64[julian]') prob a bit much

We don't have any from_* for this kind of thing

@sebhahn

This comment has been minimized.

Show comment
Hide comment
@sebhahn

sebhahn Oct 12, 2015

Good idea! So you plan to support this in the future?

sebhahn commented Oct 12, 2015

Good idea! So you plan to support this in the future?

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 12, 2015

Contributor

@sebhahn if you'd like to do a PR with the unit='julian' I think would be reasonable to start.

Contributor

jreback commented Oct 12, 2015

@sebhahn if you'd like to do a PR with the unit='julian' I think would be reasonable to start.

@sumitbinnani

This comment has been minimized.

Show comment
Hide comment
@sumitbinnani

sumitbinnani Oct 13, 2015

@jreback @sebhahn
Is this enhancement being included, and is someone working on the same? If not, I would like to give it a try :-)

sumitbinnani commented Oct 13, 2015

@jreback @sebhahn
Is this enhancement being included, and is someone working on the same? If not, I would like to give it a try :-)

@sebhahn

This comment has been minimized.

Show comment
Hide comment
@sebhahn

sebhahn Oct 13, 2015

@sumitbinnani I haven't started yet, so feel free to implement it 😄

sebhahn commented Oct 13, 2015

@sumitbinnani I haven't started yet, so feel free to implement it 😄

@sumitbinnani

This comment has been minimized.

Show comment
Hide comment
@sumitbinnani

sumitbinnani Oct 16, 2015

@sebhahn: Thanks. Will soon submit a patch :-)

sumitbinnani commented Oct 16, 2015

@sebhahn: Thanks. Will soon submit a patch :-)

@jreback jreback added this to the Someday milestone Oct 16, 2015

sumitbinnani added a commit to sumitbinnani/pandas that referenced this issue Oct 29, 2015

@jreback jreback modified the milestones: 0.18.0, Someday Dec 13, 2015

@jreback jreback modified the milestones: Next Major Release, 0.18.0 Feb 2, 2016

sumitbinnani added a commit to sumitbinnani/pandas that referenced this issue Mar 23, 2016

@jreback jreback modified the milestones: 0.18.1, Next Major Release Apr 20, 2016

@jreback jreback modified the milestones: 0.18.2, 0.18.1 May 1, 2016

jreback added a commit to jreback/pandas that referenced this issue May 1, 2016

@jreback jreback modified the milestones: 0.18.1, 0.18.2 May 1, 2016

@jreback jreback modified the milestones: Next Major Release, 0.18.2 Jul 6, 2016

@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 28, 2017

@jreback jreback closed this in cd24fa9 Apr 2, 2017

@sebhahn

This comment has been minimized.

Show comment
Hide comment
@sebhahn

sebhahn commented Apr 3, 2017

👍

linebp added a commit to linebp/pandas that referenced this issue Apr 17, 2017

ENH: add origin to to_datetime
closes #11276
closes #11745
superseded #11470

Author: Jeff Reback <jeff@reback.net>
Author: Sumit Binnani <sumit.binnani@gmail.com>

Closes #15828 from jreback/datetime-unit and squashes the following commits:

ebb4acd [Jeff Reback] doc fixes & cleanup
209591a [Jeff Reback] bug fix
56663a5 [Jeff Reback] add Timedelta floordiv ops
a24e88c [Jeff Reback] rename epoch -> unix
6a8a779 [Jeff Reback] update docs / tests
ad7356e [Sumit Binnani] BUG: Series creation with datetime64 with non-ns unit as object dtype
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment