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

A Julia equivalent to Pandas date_range function #5

Open
femtotrader opened this issue Nov 9, 2016 · 1 comment
Open

A Julia equivalent to Pandas date_range function #5

femtotrader opened this issue Nov 9, 2016 · 1 comment

Comments

@femtotrader
Copy link
Owner

femtotrader commented Nov 9, 2016

JuliaStats/TimeSeries.jl#264
JuliaLang/julia#18024

TimeFrame could be supported
and we could define a range with not regularly spaced events

Example:

In [1]: import pandas as pd
In [2]: from pandas.tseries.frequencies import to_offset
In [3]: from pandas.tseries.offsets import MonthEnd
In [2]: pd.date_range("2010-01-01", "2020-01-01", freq="MS")
Out[2]:
DatetimeIndex(['2010-01-01', '2010-02-01', '2010-03-01', '2010-04-01',
               '2010-05-01', '2010-06-01', '2010-07-01', '2010-08-01',
               '2010-09-01', '2010-10-01',
               ...
               '2019-04-01', '2019-05-01', '2019-06-01', '2019-07-01',
               '2019-08-01', '2019-09-01', '2019-10-01', '2019-11-01',
               '2019-12-01', '2020-01-01'],
              dtype='datetime64[ns]', length=121, freq='MS')

In [3]: pd.date_range("2010-01-01", "2020-01-01", freq="M")
Out[3]:
DatetimeIndex(['2010-01-31', '2010-02-28', '2010-03-31', '2010-04-30',
               '2010-05-31', '2010-06-30', '2010-07-31', '2010-08-31',
               '2010-09-30', '2010-10-31',
               ...
               '2019-03-31', '2019-04-30', '2019-05-31', '2019-06-30',
               '2019-07-31', '2019-08-31', '2019-09-30', '2019-10-31',
               '2019-11-30', '2019-12-31'],
              dtype='datetime64[ns]', length=120, freq='M')

In [4]: pd.date_range("2010-01-01 20:00:00", "2010-01-04 00:00:00", freq="D")
Out[4]:
DatetimeIndex(['2010-01-01 20:00:00', '2010-01-02 20:00:00',
               '2010-01-03 20:00:00'],
              dtype='datetime64[ns]', freq='D')

In [5]: pd.date_range("2010-01-01", "2010-01-04", freq="D")
Out[5]: DatetimeIndex(['2010-01-01', '2010-01-02', '2010-01-03', '2010-01-04'], dtype='datetime64[ns]', freq='D')
@femtotrader
Copy link
Owner Author

femtotrader commented Nov 18, 2016

julia> collect(range(DateTime(2010, 1, 1, 20), TimeFrame("D"), DateTime(2010, 1, 4)))
3-element Array{DateTime,1}:
 2010-01-01T00:00:00
 2010-01-02T00:00:00
 2010-01-03T00:00:00

seems correct

but

julia> collect(range(Date(2010, 1, 1), Monthly(boundary=Begin), Date(2020, 1, 1)))
120-element Array{Date,1}:
 2010-01-01
 2010-02-01
 2010-03-01
 
 2019-10-01
 2019-11-01
 2019-12-01

2020-01-01 is missing

We need also to compare
collect(range(Date(2010, 1, 1), Monthly(boundary=End), Date(2020, 1, 1)))

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

No branches or pull requests

1 participant