@@ -3701,6 +3701,7 @@ def test_cummin_cummax(self):
3701
3701
expected = pd .Series ([1 , 2 , 1 ], name = 'b' )
3702
3702
tm .assert_series_equal (result , expected )
3703
3703
3704
+ < << << << HEAD
3704
3705
< << << << HEAD
3705
3706
@pytest .mark .parametrize ('in_vals, out_vals' , [
3706
3707
# Basics: strictly increasing (T), strictly decreasing (F),
@@ -3764,129 +3765,81 @@ def test_is_monotonic_decreasing(self, in_vals, out_vals):
3764
3765
def test_is_increasing_is_decreasing (self ):
3765
3766
# GH 17015
3766
3767
3768
+ == == == =
3769
+ @pytest .mark .parametrize ('in_vals, out_vals' , [
3770
+ > >> >> >> f8554ee ... parametrized tests for gb .is_monotonic_increasing / decreasing
3767
3771
# Basics: strictly increasing (T), strictly decreasing (F),
3768
3772
# abs val increasing (F), non-strictly increasing (T)
3769
- source_dict = {
3770
- 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3771
- 'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3772
- 'C' : [1 , 2 , 5 , 3 , 2 , 0 , 4 , 5 , - 6 , 1 , 1 ]}
3773
- df = pd .DataFrame (source_dict )
3774
- result = df .groupby (['B' ]).C .is_monotonic_increasing ()
3775
- expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3776
- data = [True , False , False , True ],
3777
- name = 'C' )
3778
- expected .index .name = 'B'
3779
- tm .assert_series_equal (result , expected )
3780
- # Also check result equal to manually taking x.is_monotonic_increasing.
3781
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_increasing )
3782
- tm .assert_series_equal (result , expected )
3783
-
3773
+ ([1 , 2 , 5 , 3 , 2 , 0 , 4 , 5 , - 6 , 1 , 1 ],
3774
+ [True , False , False , True ]),
3784
3775
# Test with inf vals
3785
- source_dict = {
3786
- 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3787
- 'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3788
- 'C' : [1 , 2.1 , np .inf , 3 , 2 , np .inf , - np .inf , 5 , 11 , 1 , - np .inf ]}
3789
- expected .index .name = 'B'
3790
- df = pd .DataFrame (source_dict )
3791
- result = df .groupby (['B' ]).C .is_monotonic_increasing ()
3792
- expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3793
- data = [True , False , True , False ],
3794
- name = 'C' )
3795
- expected .index .name = 'B'
3796
- tm .assert_series_equal (result , expected )
3797
- # Also check result equal to manually taking x.is_monotonic_increasing.
3798
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_increasing )
3799
- tm .assert_series_equal (result , expected )
3800
-
3776
+ ([1 , 2.1 , np .inf , 3 , 2 , np .inf , - np .inf , 5 , 11 , 1 , - np .inf ],
3777
+ [True , False , True , False ]),
3801
3778
# Test with nan vals; should always be False
3779
+ ([1 , 2 , np .nan , 3 , 2 , np .nan , np .nan , 5 , - np .inf , 1 , np .nan ],
3780
+ [False , False , False , False ]),
3781
+ ])
3782
+ def test_is_monotonic_increasing (self , in_vals , out_vals ):
3783
+ # GH 17015
3802
3784
source_dict = {
3803
3785
'A ': ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3804
3786
'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3805
- 'C' : [ 1 , 2 , np . nan , 3 , 2 , np . nan , np . nan , 5 , - np . inf , 1 , np . nan ] }
3787
+ 'C' : in_vals }
3806
3788
df = pd .DataFrame (source_dict )
3807
3789
result = df .groupby (['B' ]).C .is_monotonic_increasing ()
3808
3790
expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3809
- data = [ False , False , False , False ] ,
3791
+ data = out_vals ,
3810
3792
name = 'C' )
3811
3793
expected .index .name = 'B'
3812
3794
tm .assert_series_equal (result , expected )
3813
- # Also check result equal to manually taking x.is_monotonic_increasing.
3814
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_increasing )
3815
- tm .assert_series_equal (result , expected )
3816
3795
3817
- # Test with single member groups; should be True except for np.nan
3818
- source_dict = {
3819
- 'A' : ['1' , '2' , '3' , '4' ],
3820
- 'B' : ['a' , 'b' , 'c' , 'd' ],
3821
- 'C' : [1 , 2 , np .nan , np .inf ]}
3822
- df = pd .DataFrame (source_dict )
3823
- result = df .groupby (['B' ]).C .is_monotonic_increasing ()
3824
- expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3825
- data = [True , True , False , True ],
3826
- name = 'C' )
3827
- expected .index .name = 'B'
3828
- expected .index .name = 'B'
3829
- tm .assert_series_equal (result , expected )
3830
3796
# Also check result equal to manually taking x.is_monotonic_increasing.
3831
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_increasing )
3797
+ expected = (
3798
+ df .groupby (['B' ]).C .apply (lambda x : x .is_monotonic_increasing ))
3832
3799
tm .assert_series_equal (result , expected )
3833
3800
3834
- # As above, for .is_monotonic_decreasing()
3801
+ @ pytest . mark . parametrize ( 'in_vals, out_vals' , [
3835
3802
# Basics: strictly decreasing (T), strictly increasing (F),
3836
3803
# abs val decreasing (F), non-strictly increasing (T)
3837
- source_dict = {
3838
- 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3839
- 'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3840
- 'C' : [10 , 9 , 7 , 3 , 4 , 5 , - 3 , 2 , 0 , 1 , 1 ]}
3841
- df = pd .DataFrame (source_dict )
3842
- result = df .groupby (['B' ]).C .is_monotonic_decreasing ()
3843
- expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3844
- data = [True , False , False , True ],
3845
- name = 'C' )
3846
- expected .index .name = 'B'
3847
- tm .assert_series_equal (result , expected )
3848
- # Also check result equal to manually taking x.is_monotonic_decreasing.
3849
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_decreasing )
3850
- tm .assert_series_equal (result , expected )
3851
-
3804
+ ([10 , 9 , 7 , 3 , 4 , 5 , - 3 , 2 , 0 , 1 , 1 ],
3805
+ [True , False , False , True ]),
3852
3806
# Test with inf vals
3853
- source_dict = {
3854
- 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3855
- 'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3856
- 'C' : [np .inf , 1 , - np .inf , np .inf , 2 , - 3 , - np .inf , 5 , - 3 , - np .inf ,
3857
- - np .inf ]}
3858
- df = pd .DataFrame (source_dict )
3859
- result = df .groupby (['B' ]).C .is_monotonic_decreasing ()
3860
- expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3861
- data = [True , True , False , True ],
3862
- name = 'C' )
3863
- expected .index .name = 'B'
3864
- tm .assert_series_equal (result , expected )
3865
- # Also check result equal to manually taking x.is_monotonic_decreasing.
3866
- expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_decreasing )
3867
- tm .assert_series_equal (result , expected )
3868
-
3807
+ ([np .inf , 1 , - np .inf , np .inf , 2 , - 3 , - np .inf , 5 , - 3 , - np .inf , - np .inf ],
3808
+ [True , True , False , True ]),
3869
3809
# Test with nan vals; should always be False
3810
+ ([1 , 2 , np .nan , 3 , 2 , np .nan , np .nan , 5 , - np .inf , 1 , np .nan ],
3811
+ [False , False , False , False ]),
3812
+ ])
3813
+ def test_is_monotonic_decreasing (self , in_vals , out_vals ):
3814
+ # GH 17015
3870
3815
source_dict = {
3871
3816
'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3872
3817
'B' : ['a' , 'a' , 'a' , 'b' , 'b' , 'b' , 'c' , 'c' , 'c' , 'd' , 'd' ],
3873
- 'C' : [1 , 2 , np .nan , 3 , 2 , np .nan , np .nan , 5 , - np .inf , 1 , np .nan ]}
3818
+ 'C' : in_vals }
3819
+
3874
3820
df = pd .DataFrame (source_dict )
3875
- result = df .groupby ([ 'B' ] ).C .is_monotonic_decreasing ()
3821
+ result = df .groupby ('B' ).C .is_monotonic_decreasing ()
3876
3822
expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3877
- data = [ False , False , False , False ] ,
3823
+ data = out_vals ,
3878
3824
name = 'C' )
3879
3825
expected .index .name = 'B'
3880
3826
tm .assert_series_equal (result , expected )
3827
+ << << < << HEAD
3881
3828
>> > >> >> 740 c7c2 ... added tests for gb .is_monotonically_increasing ()/ decreasing
3829
+ == == == =
3830
+
3831
+ >> > >> > > f8554ee ... parametrized tests for gb .is_monotonic_increasing / decreasing
3882
3832
# Also check result equal to manually taking x.is_monotonic_decreasing.
3883
3833
expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_decreasing )
3884
3834
tm .assert_series_equal (result , expected )
3885
3835
3836
+ << < << << HEAD
3886
3837
<< < << << HEAD
3887
3838
== == == =
3888
3839
3889
3840
>> > >> > > 740 c7c2 ... added tests for gb .is_monotonically_increasing ()/ decreasing
3841
+ == == == =
3842
+ >> > >> > > f8554ee ... parametrized tests for gb .is_monotonic_increasing / decreasing
3890
3843
def test_apply_numeric_coercion_when_datetime (self ):
3891
3844
# In the past, group-by/apply operations have been over-eager
3892
3845
# in converting dtypes to numeric, in the presence of datetime
0 commit comments