From b50dcb507bb1c635aff302d700b18f35daefbee9 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 16:17:24 +0200 Subject: [PATCH 01/17] update fix ignored sort in api.py and add test --- pandas/core/indexes/api.py | 7 +++++-- pandas/tests/arrays/integer/test_concat.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 8efc07a2ef148..522fcd40bd13d 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -184,7 +184,10 @@ def union_indexes(indexes, sort: bool = True) -> Index: if len(indexes) == 1: result = indexes[0] if isinstance(result, list): - result = Index(sorted(result)) + if sort: + result = Index(sorted(result)) + else: + result = Index(result) return result indexes, kind = _sanitize_and_check(indexes) @@ -219,7 +222,7 @@ def conv(i): return result.union_many(indexes[1:]) else: for other in indexes[1:]: - result = result.union(other) + result = result.union(other, sort=None if sort else False) return result elif kind == "array": index = indexes[0] diff --git a/pandas/tests/arrays/integer/test_concat.py b/pandas/tests/arrays/integer/test_concat.py index 2e8ef506140af..069c9323d0e8a 100644 --- a/pandas/tests/arrays/integer/test_concat.py +++ b/pandas/tests/arrays/integer/test_concat.py @@ -63,3 +63,11 @@ def test_concat_series_with_numpy(to_concat_dtypes, result_dtype): result = pd.concat([s2, s1], ignore_index=True) expected = pd.Series([0, 1, 0, 1, pd.NA], dtype=object).astype(result_dtype) tm.assert_series_equal(result, expected) + +def test_concat_frame_with_sort_false(): + result = pd.concat([pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False) + expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2,1], columns=[2,1]) + import ipdb; ipdb.set_trace() + + tm.assert_frame_equal(result, expected) + From 623a48d6df7c1a19733736106a7fbc9e0f8211fd Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 16:29:05 +0200 Subject: [PATCH 02/17] update test_concat.py, remove debug statement and improve formatting --- pandas/tests/arrays/integer/test_concat.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/integer/test_concat.py b/pandas/tests/arrays/integer/test_concat.py index 069c9323d0e8a..5786530d3100f 100644 --- a/pandas/tests/arrays/integer/test_concat.py +++ b/pandas/tests/arrays/integer/test_concat.py @@ -64,10 +64,12 @@ def test_concat_series_with_numpy(to_concat_dtypes, result_dtype): expected = pd.Series([0, 1, 0, 1, pd.NA], dtype=object).astype(result_dtype) tm.assert_series_equal(result, expected) + def test_concat_frame_with_sort_false(): - result = pd.concat([pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False) - expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2,1], columns=[2,1]) - import ipdb; ipdb.set_trace() + # GH 43375 + result = pd.concat( + [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False + ) + expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1]) tm.assert_frame_equal(result, expected) - From ef9549da5871c4426e07e04b5d4d197dbccfc34a Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 22:02:10 +0200 Subject: [PATCH 03/17] update api.py, to fix tests --- pandas/core/indexes/api.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 522fcd40bd13d..0a3fc8375207b 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -147,7 +147,7 @@ def _get_combined_index( for other in indexes[1:]: index = index.intersection(other) else: - index = union_indexes(indexes, sort=sort) + index = union_indexes(indexes, sort=None) index = ensure_index(index) if sort: @@ -184,10 +184,7 @@ def union_indexes(indexes, sort: bool = True) -> Index: if len(indexes) == 1: result = indexes[0] if isinstance(result, list): - if sort: - result = Index(sorted(result)) - else: - result = Index(result) + result = Index(sorted(result)) return result indexes, kind = _sanitize_and_check(indexes) @@ -222,7 +219,7 @@ def conv(i): return result.union_many(indexes[1:]) else: for other in indexes[1:]: - result = result.union(other, sort=None if sort else False) + result = result.union(other, sort=None if sort else sort) return result elif kind == "array": index = indexes[0] From 5d769337db038a38545897764e127bde95d7f33c Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 22:32:15 +0200 Subject: [PATCH 04/17] go back to original idea --- pandas/core/indexes/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 0a3fc8375207b..4db068af37023 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -219,7 +219,8 @@ def conv(i): return result.union_many(indexes[1:]) else: for other in indexes[1:]: - result = result.union(other, sort=None if sort else sort) + import pdb; pdb.set_trace() + result = result.union(other, sort=None if sort else False) return result elif kind == "array": index = indexes[0] From f09ee73b09ff60dbbb57bb02567dacd9c9708951 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 22:36:35 +0200 Subject: [PATCH 05/17] move new test from arrays/integer to reshape/concat; remove debug statement --- pandas/core/indexes/api.py | 1 - pandas/tests/arrays/integer/test_concat.py | 8 -------- pandas/tests/reshape/concat/test_sort.py | 12 ++++++++++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 4db068af37023..64ab9df0a88c1 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -219,7 +219,6 @@ def conv(i): return result.union_many(indexes[1:]) else: for other in indexes[1:]: - import pdb; pdb.set_trace() result = result.union(other, sort=None if sort else False) return result elif kind == "array": diff --git a/pandas/tests/arrays/integer/test_concat.py b/pandas/tests/arrays/integer/test_concat.py index 5786530d3100f..fc260a63eafe4 100644 --- a/pandas/tests/arrays/integer/test_concat.py +++ b/pandas/tests/arrays/integer/test_concat.py @@ -65,11 +65,3 @@ def test_concat_series_with_numpy(to_concat_dtypes, result_dtype): tm.assert_series_equal(result, expected) -def test_concat_frame_with_sort_false(): - # GH 43375 - result = pd.concat( - [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False - ) - expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1]) - - tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/concat/test_sort.py b/pandas/tests/reshape/concat/test_sort.py index 865f696b7a73a..305551d04327d 100644 --- a/pandas/tests/reshape/concat/test_sort.py +++ b/pandas/tests/reshape/concat/test_sort.py @@ -1,3 +1,5 @@ +import numpy as np + import pandas as pd from pandas import DataFrame import pandas._testing as tm @@ -81,3 +83,13 @@ def test_concat_aligned_sort_does_not_raise(self): expected = DataFrame({1: [1, 2, 1, 2], "a": [3, 4, 3, 4]}, columns=[1, "a"]) result = pd.concat([df, df], ignore_index=True, sort=True) tm.assert_frame_equal(result, expected) + + def test_concat_frame_with_sort_false(self): + # GH 43375 + result = pd.concat( + [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False + ) + expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1]) + + tm.assert_frame_equal(result, expected) + From 109cd47ec347356db06c0c8d6ea5f9cb8811b33d Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 1 Oct 2021 22:38:38 +0200 Subject: [PATCH 06/17] reformat tests --- pandas/tests/arrays/integer/test_concat.py | 2 -- pandas/tests/reshape/concat/test_sort.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/integer/test_concat.py b/pandas/tests/arrays/integer/test_concat.py index fc260a63eafe4..2e8ef506140af 100644 --- a/pandas/tests/arrays/integer/test_concat.py +++ b/pandas/tests/arrays/integer/test_concat.py @@ -63,5 +63,3 @@ def test_concat_series_with_numpy(to_concat_dtypes, result_dtype): result = pd.concat([s2, s1], ignore_index=True) expected = pd.Series([0, 1, 0, 1, pd.NA], dtype=object).astype(result_dtype) tm.assert_series_equal(result, expected) - - diff --git a/pandas/tests/reshape/concat/test_sort.py b/pandas/tests/reshape/concat/test_sort.py index 305551d04327d..12ee19d7a4ecb 100644 --- a/pandas/tests/reshape/concat/test_sort.py +++ b/pandas/tests/reshape/concat/test_sort.py @@ -89,7 +89,8 @@ def test_concat_frame_with_sort_false(self): result = pd.concat( [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False ) - expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1]) + expected = pd.DataFrame( + [[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1] + ) tm.assert_frame_equal(result, expected) - From c910835a511786b4a3249ac11338256936f954e8 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Sun, 3 Oct 2021 09:40:48 +0200 Subject: [PATCH 07/17] adjust test_constructors to new logic in concat --- pandas/tests/frame/test_constructors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index aa4b734411a58..d9fb97c8ada6f 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2355,9 +2355,10 @@ def test_construct_with_two_categoricalindex_series(self): result = DataFrame([s1, s2]) expected = DataFrame( np.array( - [[np.nan, 39.0, np.nan, 6.0, 4.0], [2.0, 152.0, 2.0, 242.0, 150.0]] + [[39, 6, 4, np.nan, np.nan], [152.0, 242.0, 150.0, 2.0, 2.0]] ), - columns=["f", "female", "m", "male", "unknown"], + # columns=["f", "female", "m", "male", "unknown"], + columns=['female', 'male', 'unknown', 'f', 'm'], ) tm.assert_frame_equal(result, expected) From 3be2b559ba1c06af059ee89ec14c2c3ef42d90c2 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Sun, 3 Oct 2021 09:48:51 +0200 Subject: [PATCH 08/17] update test --- pandas/tests/frame/test_constructors.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index d9fb97c8ada6f..859f5171a6f04 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2354,11 +2354,8 @@ def test_construct_with_two_categoricalindex_series(self): ) result = DataFrame([s1, s2]) expected = DataFrame( - np.array( - [[39, 6, 4, np.nan, np.nan], [152.0, 242.0, 150.0, 2.0, 2.0]] - ), - # columns=["f", "female", "m", "male", "unknown"], - columns=['female', 'male', 'unknown', 'f', 'm'], + np.array([[39, 6, 4, np.nan, np.nan], [152.0, 242.0, 150.0, 2.0, 2.0]]), + columns=["female", "male", "unknown", "f", "m"], ) tm.assert_frame_equal(result, expected) From 809b0c80cd4647b3de6f611b099bbf69f0a0d176 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Sun, 3 Oct 2021 18:43:53 +0200 Subject: [PATCH 09/17] adjust tests --- pandas/tests/reshape/test_melt.py | 26 +++++++++++++------------- pandas/tests/strings/test_cat.py | 6 +++++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pandas/tests/reshape/test_melt.py b/pandas/tests/reshape/test_melt.py index 4972cb34aac69..af9d6dd83bee3 100644 --- a/pandas/tests/reshape/test_melt.py +++ b/pandas/tests/reshape/test_melt.py @@ -746,11 +746,11 @@ def test_unbalanced(self): ) df["id"] = df.index exp_data = { - "X": ["X1", "X1", "X2", "X2"], - "A": [1.0, 3.0, 2.0, 4.0], - "B": [5.0, np.nan, 6.0, np.nan], - "id": [0, 0, 1, 1], - "year": [2010, 2011, 2010, 2011], + "X": ["X1", "X2", "X1", "X2"], + "A": [1.0, 2.0, 3.0, 4.0], + "B": [5.0, 6.0, np.nan, np.nan], + "id": [0, 1, 0, 1], + "year": [2010, 2010, 2011, 2011], } expected = DataFrame(exp_data) expected = expected.set_index(["id", "year"])[["X", "A", "B"]] @@ -993,10 +993,10 @@ def test_nonnumeric_suffix(self): ) expected = DataFrame( { - "A": ["X1", "X1", "X2", "X2"], - "colname": ["placebo", "test", "placebo", "test"], - "result": [5.0, np.nan, 6.0, np.nan], - "treatment": [1.0, 3.0, 2.0, 4.0], + "A": ["X1", "X2", "X1", "X2"], + "colname": ["placebo", "placebo", "test", "test"], + "result": [5.0, 6.0, np.nan, np.nan], + "treatment": [1.0, 2.0, 3.0, 4.0], } ) expected = expected.set_index(["A", "colname"]) @@ -1040,10 +1040,10 @@ def test_float_suffix(self): ) expected = DataFrame( { - "A": ["X1", "X1", "X1", "X1", "X2", "X2", "X2", "X2"], - "colname": [1, 1.1, 1.2, 2.1, 1, 1.1, 1.2, 2.1], - "result": [0.0, np.nan, 5.0, np.nan, 9.0, np.nan, 6.0, np.nan], - "treatment": [np.nan, 1.0, np.nan, 3.0, np.nan, 2.0, np.nan, 4.0], + "A": ["X1", "X2", "X1", "X2", "X1", "X2", "X1", "X2"], + "colname": [1.2, 1.2, 1.0, 1.0, 1.1, 1.1, 2.1, 2.1], + "result": [5.0, 6.0, 0.0, 9.0, np.nan, np.nan, np.nan, np.nan], + "treatment": [np.nan, np.nan, np.nan, np.nan, 1.0, 2.0, 3.0, 4.0], } ) expected = expected.set_index(["A", "colname"]) diff --git a/pandas/tests/strings/test_cat.py b/pandas/tests/strings/test_cat.py index 48f853cfdcb10..8abbc59343e78 100644 --- a/pandas/tests/strings/test_cat.py +++ b/pandas/tests/strings/test_cat.py @@ -278,7 +278,11 @@ def test_str_cat_align_mixed_inputs(join): expected_outer = Series(["aaA", "bbB", "c-C", "ddD", "-e-"]) # joint index of rhs [t, u]; u will be forced have index of s rhs_idx = ( - t.index.intersection(s.index) if join == "inner" else t.index.union(s.index) + t.index.intersection(s.index) + if join == "inner" + else t.index.union(s.index) + if join == "outer" + else t.index.append(s.index.difference(t.index)) ) expected = expected_outer.loc[s.index.join(rhs_idx, how=join)] From 16e9c63b7cd53986ece75577b578b0717d32c1b4 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Tue, 5 Oct 2021 18:55:50 +0200 Subject: [PATCH 10/17] adapt type hints in api.py --- pandas/core/indexes/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 64ab9df0a88c1..49c3a6b9de6c1 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -1,6 +1,7 @@ from __future__ import annotations import textwrap +from typing import Union from pandas._libs import ( NaT, @@ -163,7 +164,7 @@ def _get_combined_index( return index -def union_indexes(indexes, sort: bool = True) -> Index: +def union_indexes(indexes, sort: Union[bool, None] = True) -> Index: """ Return the union of indexes. From 78f699dc650a56284d6c49fcf71d4d3dd9f7331f Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Tue, 5 Oct 2021 19:10:36 +0200 Subject: [PATCH 11/17] update test_sort.py --- pandas/tests/reshape/concat/test_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/reshape/concat/test_sort.py b/pandas/tests/reshape/concat/test_sort.py index 12ee19d7a4ecb..fdbe59ece2771 100644 --- a/pandas/tests/reshape/concat/test_sort.py +++ b/pandas/tests/reshape/concat/test_sort.py @@ -89,7 +89,7 @@ def test_concat_frame_with_sort_false(self): result = pd.concat( [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False ) - expected = pd.DataFrame( + expected = DataFrame( [[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1] ) From bf64737c7140bcdd7a18d4fc951417e7012a48eb Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 12:37:49 +0200 Subject: [PATCH 12/17] add optional type option for sort parameter --- pandas/_libs/lib.pyi | 3 ++- pandas/_libs/lib.pyx | 3 ++- pandas/core/indexes/api.py | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index b88a2e4c28cfb..8aa1a33a05cf2 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -8,6 +8,7 @@ from typing import ( Hashable, Literal, overload, + Optional ) import numpy as np @@ -55,7 +56,7 @@ def is_integer_array(values: np.ndarray, skipna: bool = ...): ... def is_bool_array(values: np.ndarray, skipna: bool = ...): ... def fast_multiget(mapping: dict, keys: np.ndarray, default=...) -> np.ndarray: ... def fast_unique_multiple_list_gen(gen: Generator, sort: bool = ...) -> list: ... -def fast_unique_multiple_list(lists: list, sort: bool = ...) -> list: ... +def fast_unique_multiple_list(lists: list, sort: Optional[bool] = ...) -> list: ... def fast_unique_multiple(arrays: list, sort: bool = ...) -> list: ... def map_infer( arr: np.ndarray, diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 4cc8d1ac2f60e..234251917c05c 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1,6 +1,7 @@ from collections import abc from decimal import Decimal from enum import Enum +from typing import Optional import warnings import cython @@ -350,7 +351,7 @@ def fast_unique_multiple(list arrays, sort: bool = True): @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple_list(lists: list, sort: bool = True) -> list: +def fast_unique_multiple_list(lists: list, sort: Optional[bool] = True) -> list: cdef: list buf Py_ssize_t k = len(lists) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 49c3a6b9de6c1..959c9d6045ba1 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -1,7 +1,7 @@ from __future__ import annotations import textwrap -from typing import Union +from typing import Optional from pandas._libs import ( NaT, @@ -148,7 +148,7 @@ def _get_combined_index( for other in indexes[1:]: index = index.intersection(other) else: - index = union_indexes(indexes, sort=None) + index = union_indexes(indexes, sort=False) index = ensure_index(index) if sort: @@ -164,7 +164,7 @@ def _get_combined_index( return index -def union_indexes(indexes, sort: Union[bool, None] = True) -> Index: +def union_indexes(indexes, sort: Optional[bool] = True) -> Index: """ Return the union of indexes. From 39a5746d4c0e6c93cb57e440197c9264f8046953 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 13:07:22 +0200 Subject: [PATCH 13/17] remove optional type hint in favor of piped types --- pandas/_libs/lib.pyi | 3 +-- pandas/_libs/lib.pyx | 3 +-- pandas/core/indexes/api.py | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index 8aa1a33a05cf2..dd1fa0780520c 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -8,7 +8,6 @@ from typing import ( Hashable, Literal, overload, - Optional ) import numpy as np @@ -56,7 +55,7 @@ def is_integer_array(values: np.ndarray, skipna: bool = ...): ... def is_bool_array(values: np.ndarray, skipna: bool = ...): ... def fast_multiget(mapping: dict, keys: np.ndarray, default=...) -> np.ndarray: ... def fast_unique_multiple_list_gen(gen: Generator, sort: bool = ...) -> list: ... -def fast_unique_multiple_list(lists: list, sort: Optional[bool] = ...) -> list: ... +def fast_unique_multiple_list(lists: list, sort: bool | None = ...) -> list: ... def fast_unique_multiple(arrays: list, sort: bool = ...) -> list: ... def map_infer( arr: np.ndarray, diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 234251917c05c..c9d703718683e 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1,7 +1,6 @@ from collections import abc from decimal import Decimal from enum import Enum -from typing import Optional import warnings import cython @@ -351,7 +350,7 @@ def fast_unique_multiple(list arrays, sort: bool = True): @cython.wraparound(False) @cython.boundscheck(False) -def fast_unique_multiple_list(lists: list, sort: Optional[bool] = True) -> list: +def fast_unique_multiple_list(lists: list, sort: bool | None = True) -> list: cdef: list buf Py_ssize_t k = len(lists) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 959c9d6045ba1..61b151f5e4bbc 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -164,7 +164,7 @@ def _get_combined_index( return index -def union_indexes(indexes, sort: Optional[bool] = True) -> Index: +def union_indexes(indexes, sort: bool | None = True) -> Index: """ Return the union of indexes. From 5bd801cd9d85babc785409c712f2b28630721dda Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 11:25:48 +0000 Subject: [PATCH 14/17] Fixes from pre-commit [automated commit] --- pandas/tests/reshape/concat/test_sort.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/reshape/concat/test_sort.py b/pandas/tests/reshape/concat/test_sort.py index fdbe59ece2771..0b949511cf56e 100644 --- a/pandas/tests/reshape/concat/test_sort.py +++ b/pandas/tests/reshape/concat/test_sort.py @@ -89,8 +89,6 @@ def test_concat_frame_with_sort_false(self): result = pd.concat( [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False ) - expected = DataFrame( - [[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1] - ) + expected = DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1]) tm.assert_frame_equal(result, expected) From 16d8871461021742ca8eda5fda47730a0c163887 Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 15:53:26 +0200 Subject: [PATCH 15/17] update whatsnew --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 722d0dcc10041..e68a71c49e6bb 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -512,6 +512,7 @@ Reshaping - Bug in :func:`concat` of ``bool`` and ``boolean`` dtypes resulting in ``object`` dtype instead of ``boolean`` dtype (:issue:`42800`) - Bug in :func:`crosstab` when inputs are are categorical Series, there are categories that are not present in one or both of the Series, and ``margins=True``. Previously the margin value for missing categories was ``NaN``. It is now correctly reported as 0 (:issue:`43505`) - Bug in :func:`concat` would fail when the ``objs`` argument all had the same index and the ``keys`` argument contained duplicates (:issue:`43595`) +- Bug in :func:`concat` which resulted in ignored the ``sort`` parameter (:issue:`43375`) Sparse ^^^^^^ From 24392f6a712415cfc6d62daf554e95e5926228fb Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 15:55:20 +0200 Subject: [PATCH 16/17] update whatsnew --- doc/source/whatsnew/v1.4.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index e68a71c49e6bb..8c69820a54bce 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -512,7 +512,7 @@ Reshaping - Bug in :func:`concat` of ``bool`` and ``boolean`` dtypes resulting in ``object`` dtype instead of ``boolean`` dtype (:issue:`42800`) - Bug in :func:`crosstab` when inputs are are categorical Series, there are categories that are not present in one or both of the Series, and ``margins=True``. Previously the margin value for missing categories was ``NaN``. It is now correctly reported as 0 (:issue:`43505`) - Bug in :func:`concat` would fail when the ``objs`` argument all had the same index and the ``keys`` argument contained duplicates (:issue:`43595`) -- Bug in :func:`concat` which resulted in ignored the ``sort`` parameter (:issue:`43375`) +- Bug in :func:`concat` which ignored the ``sort`` parameter (:issue:`43375`) Sparse ^^^^^^ From 95580bff53d97efd3898aa37dcda301acc7603cf Mon Sep 17 00:00:00 2001 From: Tobias Pitters Date: Fri, 8 Oct 2021 16:56:14 +0200 Subject: [PATCH 17/17] remove unnecessary import and correct false naming of DataFrame --- pandas/core/indexes/api.py | 1 - pandas/tests/reshape/concat/test_sort.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/indexes/api.py b/pandas/core/indexes/api.py index 61b151f5e4bbc..e497012f23b68 100644 --- a/pandas/core/indexes/api.py +++ b/pandas/core/indexes/api.py @@ -1,7 +1,6 @@ from __future__ import annotations import textwrap -from typing import Optional from pandas._libs import ( NaT, diff --git a/pandas/tests/reshape/concat/test_sort.py b/pandas/tests/reshape/concat/test_sort.py index 0b949511cf56e..3d362ef42d276 100644 --- a/pandas/tests/reshape/concat/test_sort.py +++ b/pandas/tests/reshape/concat/test_sort.py @@ -87,7 +87,7 @@ def test_concat_aligned_sort_does_not_raise(self): def test_concat_frame_with_sort_false(self): # GH 43375 result = pd.concat( - [pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False + [DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False ) expected = DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1])