Skip to content

Commit deb24c9

Browse files
committed
Added GroupBy object raises tests
1 parent 8d658c5 commit deb24c9

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pandas/tests/groupby/test_groupby.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ def test_rank_apply(self):
18981898
@pytest.mark.parametrize("grps", [
18991899
['qux'], ['qux', 'quux']])
19001900
@pytest.mark.parametrize("vals", [
1901-
[2, 2, 8, 2, 6], ['bar', 'bar', 'foo', 'bar', 'baz'],
1901+
[2, 2, 8, 2, 6],
19021902
[pd.Timestamp('2018-01-02'), pd.Timestamp('2018-01-02'),
19031903
pd.Timestamp('2018-01-08'), pd.Timestamp('2018-01-02'),
19041904
pd.Timestamp('2018-01-06')]])
@@ -1925,8 +1925,6 @@ def test_rank_apply(self):
19251925
('dense', False, True, [.6, .6, .2, .6, .4]),
19261926
])
19271927
def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
1928-
if ties_method == 'first' and vals[0] == 'bar':
1929-
pytest.xfail("See GH 19482")
19301928
key = np.repeat(grps, len(vals))
19311929
vals = vals * len(grps)
19321930
df = DataFrame({'key': key, 'val': vals})
@@ -1940,7 +1938,6 @@ def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
19401938
['qux'], ['qux', 'quux']])
19411939
@pytest.mark.parametrize("vals", [
19421940
[2, 2, np.nan, 8, 2, 6, np.nan, np.nan], # floats
1943-
['bar', 'bar', np.nan, 'foo', 'bar', 'baz', np.nan, np.nan], # objects
19441941
[pd.Timestamp('2018-01-02'), pd.Timestamp('2018-01-02'), np.nan,
19451942
pd.Timestamp('2018-01-08'), pd.Timestamp('2018-01-02'),
19461943
pd.Timestamp('2018-01-06'), np.nan, np.nan]
@@ -2019,8 +2016,6 @@ def test_rank_args(self, grps, vals, ties_method, ascending, pct, exp):
20192016
])
20202017
def test_rank_args_missing(self, grps, vals, ties_method, ascending,
20212018
na_option, pct, exp):
2022-
if ties_method == 'first' and vals[0] == 'bar':
2023-
pytest.xfail("See GH 19482")
20242019
key = np.repeat(grps, len(vals))
20252020
vals = vals * len(grps)
20262021
df = DataFrame({'key': key, 'val': vals})
@@ -2031,6 +2026,24 @@ def test_rank_args_missing(self, grps, vals, ties_method, ascending,
20312026
exp_df = DataFrame(exp * len(grps), columns=['val'])
20322027
assert_frame_equal(result, exp_df)
20332028

2029+
@pytest.mark.parametrize("ties_method", [
2030+
'average', 'min', 'max', 'first', 'dense'])
2031+
@pytest.mark.parametrize("ascending", [True, False])
2032+
@pytest.mark.parametrize("na_option", ["keep", "top", "bottom"])
2033+
@pytest.mark.parametrize("pct", [True, False])
2034+
@pytest.mark.parametrize("vals", [
2035+
['bar', 'bar', 'foo', 'bar', 'baz'],
2036+
['bar', np.nan, 'foo', np.nan, 'baz']
2037+
])
2038+
def test_rank_object_raises(self, ties_method, ascending, na_option,
2039+
pct, vals):
2040+
df = DataFrame({'key': ['foo'] * 5, 'val': vals})
2041+
with tm.assert_raises_regex(ValueError,
2042+
"rank not supported for object dtypes"):
2043+
df.groupby('key').rank(method=ties_method,
2044+
ascending=ascending,
2045+
na_option=na_option, pct=pct)
2046+
20342047
def test_dont_clobber_name_column(self):
20352048
df = DataFrame({'key': ['a', 'a', 'a', 'b', 'b', 'b'],
20362049
'name': ['foo', 'bar', 'baz'] * 2})

0 commit comments

Comments
 (0)