Skip to content

Commit

Permalink
add test for numpy ops, esp. nanmin/max bug for np<1.13 (pandas-dev#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 authored and harisbal committed Feb 28, 2018
1 parent 52be57d commit e9bb374
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit e9bb374

Please sign in to comment.