@@ -37,16 +37,6 @@ def sort(request):
37
37
return request .param
38
38
39
39
40
- @pytest .fixture (params = [True , False , None ])
41
- def sort_with_none (request ):
42
- """Boolean sort keyword for concat and DataFrame.append.
43
-
44
- Includes the default of None
45
- """
46
- # TODO: Replace with sort once keyword changes.
47
- return request .param
48
-
49
-
50
40
class TestConcatAppendCommon :
51
41
"""
52
42
Test common dtype coercion rules between concat and append.
@@ -775,15 +765,13 @@ def test_concat_join_axes_deprecated(self, axis):
775
765
)
776
766
777
767
expected = pd .concat ([one , two ], axis = 1 , sort = False ).reindex (index = two .index )
778
- with tm .assert_produces_warning (expected_warning = FutureWarning ):
779
- result = pd .concat ([one , two ], axis = 1 , sort = False , join_axes = [two .index ])
768
+ result = pd .concat ([one , two ], axis = 1 , sort = False , join_axes = [two .index ])
780
769
tm .assert_frame_equal (result , expected )
781
770
782
771
expected = pd .concat ([one , two ], axis = 0 , sort = False ).reindex (
783
772
columns = two .columns
784
773
)
785
- with tm .assert_produces_warning (expected_warning = FutureWarning ):
786
- result = pd .concat ([one , two ], axis = 0 , sort = False , join_axes = [two .columns ])
774
+ result = pd .concat ([one , two ], axis = 0 , sort = False , join_axes = [two .columns ])
787
775
tm .assert_frame_equal (result , expected )
788
776
789
777
@@ -875,27 +863,19 @@ def test_append_records(self):
875
863
tm .assert_frame_equal (result , expected )
876
864
877
865
# rewrite sort fixture, since we also want to test default of None
878
- def test_append_sorts (self , sort_with_none ):
866
+ def test_append_sorts (self , sort ):
879
867
df1 = pd .DataFrame ({"a" : [1 , 2 ], "b" : [1 , 2 ]}, columns = ["b" , "a" ])
880
868
df2 = pd .DataFrame ({"a" : [1 , 2 ], "c" : [3 , 4 ]}, index = [2 , 3 ])
881
869
882
- if sort_with_none is None :
883
- # only warn if not explicitly specified
884
- # don't check stacklevel since its set for concat, and append
885
- # has an extra stack.
886
- ctx = tm .assert_produces_warning (FutureWarning , check_stacklevel = False )
887
- else :
888
- ctx = tm .assert_produces_warning (None )
889
-
890
- with ctx :
891
- result = df1 .append (df2 , sort = sort_with_none )
870
+ with tm .assert_produces_warning (None ):
871
+ result = df1 .append (df2 , sort = sort )
892
872
893
873
# for None / True
894
874
expected = pd .DataFrame (
895
875
{"b" : [1 , 2 , None , None ], "a" : [1 , 2 , 1 , 2 ], "c" : [None , None , 3 , 4 ]},
896
876
columns = ["a" , "b" , "c" ],
897
877
)
898
- if sort_with_none is False :
878
+ if sort is False :
899
879
expected = expected [["b" , "a" , "c" ]]
900
880
tm .assert_frame_equal (result , expected )
901
881
@@ -2629,7 +2609,7 @@ def test_concat_empty_and_non_empty_series_regression():
2629
2609
tm .assert_series_equal (result , expected )
2630
2610
2631
2611
2632
- def test_concat_sorts_columns (sort_with_none ):
2612
+ def test_concat_sorts_columns (sort ):
2633
2613
# GH-4588
2634
2614
df1 = pd .DataFrame ({"a" : [1 , 2 ], "b" : [1 , 2 ]}, columns = ["b" , "a" ])
2635
2615
df2 = pd .DataFrame ({"a" : [3 , 4 ], "c" : [5 , 6 ]})
@@ -2640,58 +2620,44 @@ def test_concat_sorts_columns(sort_with_none):
2640
2620
columns = ["a" , "b" , "c" ],
2641
2621
)
2642
2622
2643
- if sort_with_none is False :
2623
+ if sort is False :
2644
2624
expected = expected [["b" , "a" , "c" ]]
2645
2625
2646
- if sort_with_none is None :
2647
- # only warn if not explicitly specified
2648
- ctx = tm .assert_produces_warning (FutureWarning )
2649
- else :
2650
- ctx = tm .assert_produces_warning (None )
2651
-
2652
2626
# default
2653
- with ctx :
2654
- result = pd .concat ([df1 , df2 ], ignore_index = True , sort = sort_with_none )
2627
+ with tm . assert_produces_warning ( None ) :
2628
+ result = pd .concat ([df1 , df2 ], ignore_index = True , sort = sort )
2655
2629
tm .assert_frame_equal (result , expected )
2656
2630
2657
2631
2658
- def test_concat_sorts_index (sort_with_none ):
2632
+ def test_concat_sorts_index (sort ):
2659
2633
df1 = pd .DataFrame ({"a" : [1 , 2 , 3 ]}, index = ["c" , "a" , "b" ])
2660
2634
df2 = pd .DataFrame ({"b" : [1 , 2 ]}, index = ["a" , "b" ])
2661
2635
2662
2636
# For True/None
2663
2637
expected = pd .DataFrame (
2664
2638
{"a" : [2 , 3 , 1 ], "b" : [1 , 2 , None ]}, index = ["a" , "b" , "c" ], columns = ["a" , "b" ]
2665
2639
)
2666
- if sort_with_none is False :
2640
+ if sort is False :
2667
2641
expected = expected .loc [["c" , "a" , "b" ]]
2668
2642
2669
- if sort_with_none is None :
2670
- # only warn if not explicitly specified
2671
- ctx = tm .assert_produces_warning (FutureWarning )
2672
- else :
2673
- ctx = tm .assert_produces_warning (None )
2674
-
2675
2643
# Warn and sort by default
2676
- with ctx :
2677
- result = pd .concat ([df1 , df2 ], axis = 1 , sort = sort_with_none )
2644
+ with tm . assert_produces_warning ( None ) :
2645
+ result = pd .concat ([df1 , df2 ], axis = 1 , sort = sort )
2678
2646
tm .assert_frame_equal (result , expected )
2679
2647
2680
2648
2681
- def test_concat_inner_sort (sort_with_none ):
2649
+ def test_concat_inner_sort (sort ):
2682
2650
# https://github.com/pandas-dev/pandas/pull/20613
2683
2651
df1 = pd .DataFrame ({"a" : [1 , 2 ], "b" : [1 , 2 ], "c" : [1 , 2 ]}, columns = ["b" , "a" , "c" ])
2684
2652
df2 = pd .DataFrame ({"a" : [1 , 2 ], "b" : [3 , 4 ]}, index = [3 , 4 ])
2685
2653
2686
2654
with tm .assert_produces_warning (None ):
2687
2655
# unset sort should *not* warn for inner join
2688
2656
# since that never sorted
2689
- result = pd .concat (
2690
- [df1 , df2 ], sort = sort_with_none , join = "inner" , ignore_index = True
2691
- )
2657
+ result = pd .concat ([df1 , df2 ], sort = sort , join = "inner" , ignore_index = True )
2692
2658
2693
2659
expected = pd .DataFrame ({"b" : [1 , 2 , 3 , 4 ], "a" : [1 , 2 , 1 , 2 ]}, columns = ["b" , "a" ])
2694
- if sort_with_none is True :
2660
+ if sort is True :
2695
2661
expected = expected [["a" , "b" ]]
2696
2662
tm .assert_frame_equal (result , expected )
2697
2663
0 commit comments