From 5ae4d915d8a4e002585f29dc562d49c3ceabfbf6 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 28 Feb 2023 01:48:38 +0100 Subject: [PATCH 1/2] BUG: concat sorting when sort=False for all dti --- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/core/indexes/api.py | 2 +- pandas/tests/reshape/concat/test_datetimes.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 45b5c16415f9d..311712db5bd7b 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -191,7 +191,7 @@ Groupby/resample/rolling Reshaping ^^^^^^^^^ -- +- Bug in :func:`concat` sorting :class:`Index` when only :class:`DatetimeIndex` is given (:issue:`51210`) - Sparse diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index fcf529f5be9ac..6b68cc1a5089f 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -276,7 +276,7 @@ def _find_common_index_dtype(inds): raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex") if len(dtis) == len(indexes): - sort = True + sort = sort result = indexes[0] elif len(dtis) > 1: diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index f16358813488e..c888a8ddf34e2 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -77,23 +77,23 @@ def test_concat_datetime_timezone(self): exp_idx = DatetimeIndex( [ - "2010-12-31 15:00:00+00:00", - "2010-12-31 16:00:00+00:00", - "2010-12-31 17:00:00+00:00", "2010-12-31 23:00:00+00:00", "2011-01-01 00:00:00+00:00", "2011-01-01 01:00:00+00:00", + "2010-12-31 15:00:00+00:00", + "2010-12-31 16:00:00+00:00", + "2010-12-31 17:00:00+00:00", ] ) expected = DataFrame( [ - [np.nan, 1], - [np.nan, 2], - [np.nan, 3], [1, np.nan], [2, np.nan], [3, np.nan], + [np.nan, 1], + [np.nan, 2], + [np.nan, 3], ], index=exp_idx, columns=["a", "b"], From cf3b2b780423f33c45ba667ab42a925e4ea0dc84 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 28 Feb 2023 15:56:51 +0100 Subject: [PATCH 2/2] Fix pylint --- pandas/core/indexes/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 6b68cc1a5089f..68df699d58a45 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -276,7 +276,6 @@ def _find_common_index_dtype(inds): raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex") if len(dtis) == len(indexes): - sort = sort result = indexes[0] elif len(dtis) > 1: