Skip to content

Commit

Permalink
fix lit_date: forgot to cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 13, 2021
1 parent d62a547 commit ffc1aef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion py-polars/polars/lazy/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,15 @@ def lit_date(dt: datetime) -> "pl.Expr":
"""
Converts a Python DateTime to a literal Expression.
.. deprecated:: 0.9.5
Use polars.lit
Parameters
----------
dt
datetime.datetime
"""
return lit(int((dt.replace(tzinfo=timezone.utc)).timestamp() * 1e3))
return lit(int((dt.replace(tzinfo=timezone.utc)).timestamp() * 1e3)).cast(pl.Date64)


def lit(
Expand Down
7 changes: 5 additions & 2 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,12 @@ def test_filter_date():
{"date": ["2020-01-02", "2020-01-03", "2020-01-04"], "index": [1, 2, 3]}
)
df = dataset.with_column(pl.col("date").str.strptime(pl.Date32, "%Y-%m-%d"))

# filter out the data to match only records from the previous year
assert df.filter(col("date") <= pl.lit_date(datetime(2019, 1, 3))).is_empty()
assert df.filter(col("date") < pl.lit_date(datetime(2020, 1, 4))).shape[0] == 2
assert df.filter(col("date") < pl.lit_date(datetime(2020, 1, 5))).shape[0] == 3
assert df.filter(col("date") <= pl.lit(datetime(2019, 1, 3))).is_empty()
assert df.filter(col("date") < pl.lit(datetime(2020, 1, 4))).shape[0] == 2
assert df.filter(col("date") < pl.lit(datetime(2020, 1, 5))).shape[0] == 3


def test_slicing():
Expand Down

0 comments on commit ffc1aef

Please sign in to comment.