pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
26.63k stars 1.63k forks source link

`dtype` ingored in `pl.lit` between date and datetime #16012

Open gab23r opened 2 weeks ago

gab23r commented 2 weeks ago

Checks

Reproducible example

import polars as pl
import datetime

some_datetime = datetime.datetime.now()
pl.select(pl.lit(some_datetime, dtype=pl.Date)).schema.                                 #   <<< Date
# OrderedDict([('literal', Datetime(time_unit='us', time_zone=None))])         #   <<< Datetime

some_date = datetime.date.today()
pl.select(pl.lit(some_date, dtype=pl.Datetime)).schema                                  #   <<< Datetime
# OrderedDict([('literal', Date)])                                #   <<< Date

Log output

No response

Issue description

dtype is silently ignored in these cases (see above).

Expected behavior

I would except either a cast to the provided dtype or a raise.

Installed versions

``` --------Version info--------- Polars: 0.20.23 Index type: UInt32 Platform: macOS-14.1.1-x86_64-i386-64bit Python: 3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)] ----Optional dependencies---- adbc_driver_manager: cloudpickle: connectorx: deltalake: fastexcel: fsspec: gevent: hvplot: matplotlib: nest_asyncio: 1.6.0 numpy: 1.26.4 openpyxl: pandas: 2.2.0 pyarrow: 15.0.0 pydantic: pyiceberg: pyxlsb: sqlalchemy: xlsx2csv: xlsxwriter: ```
mcrumiller commented 2 weeks ago

This is happening on the python side.