BUG: dtype of right merge between datetime and timedelta depends on presence of NaT #56455
Closed
3 tasks done
Labels
Bug
Datetime
Datetime data dtype
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
If both the left and right frames contain
NaT
it looks like the merge considers there to be a match between the left and right keys and therefore promotes the key column to a common "object" type. In contrast if there is noNaT
, the right merge produces atimedelta64[ns]
key column, which feels more correct to me.Note that in contrast a
"left"
merge produces an object dtype key column in both cases.Expected Behavior
I would expect the dtype to be preserved, arguably also for a
"left"
merge, irrespective of the presence ofNaT
.I would also (perhaps preferably) accept raising when attempting to merge between datetime and timedelta, since they have different units. In the same way that attempting to merge between int and datetime or int and timedelta raises.
I was somewhat surprised that the
NaT
matches in this merge (no other datetime matches a timedelta), since my interpretation is that a "datetime"NaT
represents an unknown point in time, and a "timedelta"NaT
represents an unknown duration.Installed Versions
The text was updated successfully, but these errors were encountered: