Skip to content

Commit

Permalink
Fix date_range function (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj committed Nov 6, 2021
1 parent c9eb258 commit 2c66829
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion py-polars/polars/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def date_range(
values = np.append(values, np.array(high, dtype="datetime64[ms]"))
if closed == "right":
values = values[1:]
return pl.Series(name=name, values=values.astype(int)).cast(pl.Datetime)
return pl.Series(name=name, values=values.astype(np.int64)).cast(pl.Datetime)
13 changes: 12 additions & 1 deletion py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime
from datetime import date, datetime, timedelta

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -783,3 +783,14 @@ def test_trigonometry_functions():
assert np.allclose(srs_float.arcsin(), np.array([1.571, 0.0, -1.571]), atol=0.01)
assert np.allclose(srs_float.arccos(), np.array([0.0, 1.571, 3.142]), atol=0.01)
assert np.allclose(srs_float.arctan(), np.array([0.785, 0.0, -0.785]), atol=0.01)


def test_date_range():
result = pl.date_range(
datetime(1985, 1, 1), datetime(2015, 7, 1), timedelta(days=1, hours=12)
)
assert len(result) == 7426
assert result.dt[0] == datetime(1985, 1, 1)
assert result.dt[1] == datetime(1985, 1, 2, 12, 0)
assert result.dt[2] == datetime(1985, 1, 4, 0, 0)
assert result.dt[-1] == datetime(2015, 6, 30, 12, 0)

0 comments on commit 2c66829

Please sign in to comment.