Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
raguiar2 committed Jul 25, 2018
1 parent 26dfe00 commit 59c98a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pandas/tests/frame/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ def test_rank_na_option(self):
tm.assert_numpy_array_equal(ranks0.values, exp0)
tm.assert_numpy_array_equal(ranks1.values, exp1)

# bad values throw error
msg = "na_option must be one of 'keep', 'top', or 'bottom'"

with tm.assert_raises_regex(ValueError, msg):
self.frame.rank(na_option='bad', ascending=False)

# invalid type
with tm.assert_raises_regex(ValueError, msg):
self.frame.rank(na_option=True, ascending=False)

def test_rank_axis(self):
# check if using axes' names gives the same result
df = DataFrame([[2, 1], [4, 3]])
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/groupby/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ def test_rank_avg_even_vals():
def test_rank_object_raises(ties_method, ascending, na_option,
pct, vals):
df = DataFrame({'key': ['foo'] * 5, 'val': vals})

with tm.assert_raises_regex(TypeError, "not callable"):
df.groupby('key').rank(method=ties_method,
ascending=ascending,
na_option='bad', pct=pct)

with tm.assert_raises_regex(TypeError, "not callable"):
df.groupby('key').rank(method=ties_method,
ascending=ascending,
na_option=True, pct=pct)

with tm.assert_raises_regex(TypeError, "not callable"):
df.groupby('key').rank(method=ties_method,
ascending=ascending,
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/series/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ def test_rank_categorical(self):
exp_keep
)

# Test invalid values for na_option
msg = "na_option must be one of 'keep', 'top', or 'bottom'"

with tm.assert_raises_regex(ValueError, msg):
na_ser.rank(na_option='bad', ascending=False)

# invalid type
with tm.assert_raises_regex(ValueError, msg):
na_ser.rank(na_option=True, ascending=False)

# Test with pct=True
na_ser = Series(['first', 'second', 'third', 'fourth', np.NaN]).astype(
CategoricalDtype(['first', 'second', 'third', 'fourth'], True))
Expand Down

0 comments on commit 59c98a6

Please sign in to comment.