polars
                                
                                 polars copied to clipboard
                                
                                    polars copied to clipboard
                            
                            
                            
                        Adding time and datetime gives a nonsense result
Polars version checks
- 
[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. 
Issue description
Adding pl.Time to pl.Datetime produces a result that nobody would want. It gives you an int that's the result of (or equivalent to) calling .to_physical on the values and adding them together. However, calling .to_physical() on a pl.Time gives you nanoseconds, while for pl.Datetime it gives you microseconds.
This means that to add a time to a datetime you need to do:
(datetime_series + time_series.to_physical() // 1000).cast(pl.Datetime)
Reproducible example
>>> from datetime import datetime, time
>>> import polars as pl
>>> pl.Series([datetime(1970, 1, 1, 0, 0, 1)]) + pl.Series([time(0, 0, 2)])
shape: (1,)
Series: '' [i64]
[
	2001000000
]
Expected behavior
Series: '' [datetime[μs]]
[
	1970-01-01 00:00:03
]
OR, it should error and we should require converting the Time to a Duration. Related: #5847
Installed versions
---Version info---
Polars: 0.15.7
Index type: UInt32
Platform: Linux-5.15.57-2-MANJARO-x86_64-with-glibc2.35
Python: 3.11.0 | packaged by conda-forge | (main, Oct 25 2022, 06:24:40) [GCC 10.4.0]
---Optional dependencies---
pyarrow: 10.0.1
pandas: 1.5.2
numpy: 1.23.5
fsspec: <not installed>
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: 3.6.2
I think you want to use datetime.timedeta rather than datetime.time. That works for me at least.
That works because you already have a Duration type, by construction.
There are scenarios where you have a Time type already, and adding a Time to a Datetime should either give the result one would expect or raise an error
"Adding" a time object to a datetime object isn't allowed in Python. You have to use a timedelta instead of time there, or datetime.combine. IMHO, this is a sane decision - you either combine date and time or add/subtract a duration (timedelta; + / - operators). So +1 for raising an exception 🫠
I think we should raise an error here, informing the use to use a Duration/timedelta to offset datetime types.
It seems technically feasible, to add time to dates (or subtract). You'd have to ensure that units used in internal representation match, e.g. both time and date as nanoseconds, microseconds etc. I must admit, I'm not totally sure why it was implemented as it is in Python now. Vanilla Python datetime and timedelta arithmetic certainly have some quirks (example?)...
Most likely, time zones and DST transition hours might get you into trouble. Two hours "wall time" might be three hours in "absolute time" (UTC). Users might have different expected outcomes.
Long story short, after having another thought on this, I still think raising an error for (datetime + time) is a sane thing to do. Handling above mentioned issues in one place, i.e. (datetime + duration), seems enough work to do. But there's room for future features, no? ;-)