Skip to content

Commit 2e4bb15

Browse files
No-Streamjreback
authored andcommitted
parametrized tests for gb.is_monotonic_increasing/decreasing
1 parent 5a30ee4 commit 2e4bb15

File tree

1 file changed

+38
-85
lines changed

1 file changed

+38
-85
lines changed

pandas/tests/groupby/test_groupby.py

+38-85
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,7 @@ def test_cummin_cummax(self):
37013701
expected = pd.Series([1, 2, 1], name='b')
37023702
tm.assert_series_equal(result, expected)
37033703

3704+
<<<<<<< HEAD
37043705
<<<<<<< HEAD
37053706
@pytest.mark.parametrize('in_vals, out_vals', [
37063707
# Basics: strictly increasing (T), strictly decreasing (F),
@@ -3764,129 +3765,81 @@ def test_is_monotonic_decreasing(self, in_vals, out_vals):
37643765
def test_is_increasing_is_decreasing(self):
37653766
# GH 17015
37663767

3768+
=======
3769+
@pytest.mark.parametrize('in_vals, out_vals', [
3770+
>>>>>>> f8554ee... parametrized tests for gb.is_monotonic_increasing/decreasing
37673771
# Basics: strictly increasing (T), strictly decreasing (F),
37683772
# 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]),
37843775
# 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]),
38013778
# 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
38023784
source_dict = {
38033785
'A': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
38043786
'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}
38063788
df = pd.DataFrame(source_dict)
38073789
result = df.groupby(['B']).C.is_monotonic_increasing()
38083790
expected = pd.Series(index=['a', 'b', 'c', 'd'],
3809-
data=[False, False, False, False],
3791+
data=out_vals,
38103792
name='C')
38113793
expected.index.name = 'B'
38123794
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)
38163795

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)
38303796
# 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))
38323799
tm.assert_series_equal(result, expected)
38333800

3834-
# As above, for .is_monotonic_decreasing()
3801+
@pytest.mark.parametrize('in_vals, out_vals', [
38353802
# Basics: strictly decreasing (T), strictly increasing (F),
38363803
# 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]),
38523806
# 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]),
38693809
# 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
38703815
source_dict = {
38713816
'A': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'],
38723817
'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+
38743820
df = pd.DataFrame(source_dict)
3875-
result = df.groupby(['B']).C.is_monotonic_decreasing()
3821+
result = df.groupby('B').C.is_monotonic_decreasing()
38763822
expected = pd.Series(index=['a', 'b', 'c', 'd'],
3877-
data=[False, False, False, False],
3823+
data=out_vals,
38783824
name='C')
38793825
expected.index.name = 'B'
38803826
tm.assert_series_equal(result, expected)
3827+
<<<<<<< HEAD
38813828
>>>>>>> 740c7c2... added tests for gb.is_monotonically_increasing()/decreasing
3829+
=======
3830+
3831+
>>>>>>> f8554ee... parametrized tests for gb.is_monotonic_increasing/decreasing
38823832
# Also check result equal to manually taking x.is_monotonic_decreasing.
38833833
expected = df.groupby('B').C.apply(lambda x: x.is_monotonic_decreasing)
38843834
tm.assert_series_equal(result, expected)
38853835

3836+
<<<<<<< HEAD
38863837
<<<<<<< HEAD
38873838
=======
38883839

38893840
>>>>>>> 740c7c2... added tests for gb.is_monotonically_increasing()/decreasing
3841+
=======
3842+
>>>>>>> f8554ee... parametrized tests for gb.is_monotonic_increasing/decreasing
38903843
def test_apply_numeric_coercion_when_datetime(self):
38913844
# In the past, group-by/apply operations have been over-eager
38923845
# in converting dtypes to numeric, in the presence of datetime

0 commit comments

Comments
 (0)