Open alonket opened 1 year ago
agree, being able to write pl.date_range(date(2020, 1, 1), periods=3)
would be very convenient, I've found myself reaching for it a few times
I totally agree. Introducing a periods
argument is really helpful. See also my own question: https://stackoverflow.com/questions/78889556/create-date-range-with-predefined-number-of-periods-in-polars
This issue is open for quite some time now. I am wondering if there exist a concrete plan to incorporate it into the code base?
@andreas-vester it's not high-priority, but if anyone from the community wanted to make a pull request, it would be welcome
Made a start on this today:
In [1]: import polars as pl
In [2]: from datetime import date
In [3]: pl.date_range(date(2020,1,1), periods=3, eager=True)
Out[3]:
shape: (3,)
Series: 'literal' [date]
[
2020-01-01
2020-01-02
2020-01-03
]
In [4]: pl.date_range(date(2020,1,1), date(2020, 1, 5), eager=True)
Out[4]:
shape: (5,)
Series: 'literal' [date]
[
2020-01-01
2020-01-02
2020-01-03
2020-01-04
2020-01-05
]
No promises as to when it'll be finished
Problem description
I'm dealing once in a while with dates and I need to create date ranges. In pandas I can do it very easily:
pd.date_range(pd.to_datetime(date) - pd.Timedelta(days=3), periods=3, freq="D").to_list()
However when I tried to convert it to polars I had to deal with end_date.
Following my question in SO, the answer pointed out(and I agree) that it could be a good Idea to have something like this:
date_range(start_date, period_of_time, interval)
in addition todate_range(start_date, end_date, interval)