[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of Polars.
Reproducible example
> dt = pd.Timestamp.now(tz="America/New_York").to_pydatetime()
> pl.select(x=dt).select(pl.col.x.map_elements(lambda x: x, pl.Datetime(time_zone="America/New_York")))
SchemaError: expected output type 'Datetime(Microseconds, Some("America/New_York"))', got 'Datetime(Microseconds, None)'; set `return_dtype` to the proper datatype
> pl.select(x=dt).select(pl.col.x.map_elements(lambda x: x, pl.Datetime("ns", time_zone="America/New_York")))
SchemaError: expected output type 'Datetime(Nanoseconds, Some("America/New_York"))', got 'Datetime(Microseconds, None)'; set `return_dtype` to the proper datatype
> pl.select(x=pl.lit(dt, dtype=pl.Datetime("ns", time_zone="America/New_York")))
> pl.select(x=pl.lit(pd.Timestamp.now(), dtype=pl.Datetime("ns", time_zone="America/New_York"))
Log output
No response
Issue description
I think there're two bugs/issues in this example
polars always treats the datetime return of map_elements as a Datetime(Microseconds, None) even if a timezone exists for the return datetime.
polars dtype conversion in map_elements is stricter than pl.lit. This leads to issues where pl.Dateime("ns") can't be used in return_dtype when a datetime is returned. I think this should have the same dtype rule as pl.lit.
Expected behavior
All examples above should return a dataframe with the specified dtype w/o any error.
Installed versions
```
In [17]: pl.show_versions()
--------Version info---------
Polars: 1.9.0
Index type: UInt32
Python: 3.10.13
```
Checks
Reproducible example
Log output
No response
Issue description
I think there're two bugs/issues in this example
Datetime(Microseconds, None)
even if a timezone exists for the return datetime.pl.lit
. This leads to issues wherepl.Dateime("ns")
can't be used inreturn_dtype
when a datetime is returned. I think this should have the same dtype rule aspl.lit
.Expected behavior
All examples above should return a dataframe with the specified dtype w/o any error.
Installed versions