-
-
Couldn't load subscription status.
- Fork 19.2k
Description
pd.concat has a specific behavior to always sort DatetimeIndex when join="outer" and the non-concatentation axes are not aligned. This was undocumented (prior to 2.2.1) and is inconsistent with all other index types and data types including other temporal types such as pyarrow timestamps/dates/times.
An attempt to treat this as a bug fix highlighted that this has been long-standing behavior that users may be accustomed to. (xref #57006)
Here are two options that come to mind:
-
Deprecate the existing behavior and do not sort by default for
DatetimeIndex. This would simplify things by removing the carve out and treating all index types / data types consistently. This would require users to explicitly passsort=Truewhen concatenating two frames with monotonic indexes if they wanted to ensure a monotonic result. -
Always sort the non-concatenation axis when
join="outer"(for all dtypes). This would be consistent with howpd.mergeandDataFrame.joinhandle outer merges and in practice may be more useful behavior since concatenating two frames with monotonic indexes will return a frame with a monotonic index.