BUG: concat(axis=1) sorts by default for DatetimeIndex · Issue #54769 · pandas-dev/pandas (original) (raw)
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
import pandas as pd
a = pd.Series(1, index=pd.to_datetime(['2000-01-01', '2000-01-03'])) b = pd.Series(2, index=pd.to_datetime(['2000-01-02', '2000-01-04']))
pd.concat([a, b], axis=1)
Issue Description
concat
documentation states concat will not sort by default. I believe the default sort behavior was deprecated some time ago. However, there is still a sort=True
behavior for DatetimeIndex
:
0 1
2000-01-01 1.0 NaN
2000-01-02 NaN 2.0
2000-01-03 1.0 NaN
2000-01-04 NaN 2.0
The source of this behavior is a hard-coded special-casing in pandas.core.indexes.api.union_indexes
. Making this not sort by default seems to break at least one test (test_concat_datetime_timezone
) and possibly more.
Expected Behavior
Per the docs, I would expect no sort by default. But that might surprise users if changed. I suppose this either needs to be documented (if intentional) or deprecated (if not intentional).
Installed Versions
.