@@ -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
@pytest .mark .parametrize ('in_vals, out_vals' , [
3705
3706
# Basics: strictly increasing (T), strictly decreasing (F),
3706
3707
# abs val increasing (F), non-strictly increasing (T)
@@ -3759,10 +3760,133 @@ def test_is_monotonic_decreasing(self, in_vals, out_vals):
3759
3760
expected .index .name = 'B'
3760
3761
tm .assert_series_equal (result , expected )
3761
3762
3763
+ == == == =
3764
+ def test_is_increasing_is_decreasing (self ):
3765
+ # GH 17015
3766
+
3767
+ # Basics: strictly increasing (T), strictly decreasing (F),
3768
+ # 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
+
3784
+ # 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
+
3801
+ # Test with nan vals; should always be False
3802
+ source_dict = {
3803
+ 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3804
+ '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 ]}
3806
+ df = pd .DataFrame (source_dict )
3807
+ result = df .groupby (['B' ]).C .is_monotonic_increasing ()
3808
+ expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3809
+ data = [False , False , False , False ],
3810
+ name = 'C' )
3811
+ expected .index .name = 'B'
3812
+ 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
+
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
+ # Also check result equal to manually taking x.is_monotonic_increasing.
3831
+ expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_increasing )
3832
+ tm .assert_series_equal (result , expected )
3833
+
3834
+ # As above, for .is_monotonic_decreasing()
3835
+ # Basics: strictly decreasing (T), strictly increasing (F),
3836
+ # 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 )
3762
3848
# Also check result equal to manually taking x.is_monotonic_decreasing.
3763
3849
expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_decreasing )
3764
3850
tm .assert_series_equal (result , expected )
3765
3851
3852
+ # 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
+
3869
+ # Test with nan vals; should always be False
3870
+ source_dict = {
3871
+ 'A' : ['1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' ],
3872
+ '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 ]}
3874
+ df = pd .DataFrame (source_dict )
3875
+ result = df .groupby (['B' ]).C .is_monotonic_decreasing ()
3876
+ expected = pd .Series (index = ['a' , 'b' , 'c' , 'd' ],
3877
+ data = [False , False , False , False ],
3878
+ name = 'C' )
3879
+ expected .index .name = 'B'
3880
+ tm .assert_series_equal (result , expected )
3881
+ >> >> >> > 740 c7c2 ... added tests for gb .is_monotonically_increasing ()/ decreasing
3882
+ # Also check result equal to manually taking x.is_monotonic_decreasing.
3883
+ expected = df .groupby ('B' ).C .apply (lambda x : x .is_monotonic_decreasing )
3884
+ tm .assert_series_equal (result , expected )
3885
+
3886
+ < << << << HEAD
3887
+ == == == =
3888
+
3889
+ >> >> >> > 740 c7c2 ... added tests for gb .is_monotonically_increasing ()/ decreasing
3766
3890
def test_apply_numeric_coercion_when_datetime (self ):
3767
3891
# In the past, group-by/apply operations have been over-eager
3768
3892
# in converting dtypes to numeric, in the presence of datetime
0 commit comments