Skip to content

TST: add test for numpy ops, esp. nanmin/max bug for np<1.13 #19753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pandas/tests/test_nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pandas.core.nanops as nanops
import pandas.util.testing as tm
import pandas.util._test_decorators as td
from pandas.compat.numpy import _np_version_under1p13

use_bn = nanops._USE_BOTTLENECK

Expand Down Expand Up @@ -1015,3 +1016,34 @@ def test_use_bottleneck():
assert not pd.get_option('use_bottleneck')

pd.set_option('use_bottleneck', use_bn)


@pytest.mark.parametrize("numpy_op, expected", [
(np.sum, 10),
(np.nansum, 10),
(np.mean, 2.5),
(np.nanmean, 2.5),
(np.median, 2.5),
(np.nanmedian, 2.5),
(np.min, 1),
(np.max, 4),
])
def test_numpy_ops(numpy_op, expected):
# GH8383
result = numpy_op(pd.Series([1, 2, 3, 4]))
assert result == expected


@pytest.mark.parametrize("numpy_op, expected", [
(np.nanmin, 1),
(np.nanmax, 4),
])
def test_numpy_ops_np_version_under1p13(numpy_op, expected):
# GH8383
result = numpy_op(pd.Series([1, 2, 3, 4]))
if _np_version_under1p13:
# bug for numpy < 1.13, where result is a series, should be a scalar
with pytest.raises(ValueError):
assert result == expected
else:
assert result == expected