Skip to content

Commit e9bb374

Browse files
topper-123harisbal
authored and
harisbal
committed
add test for numpy ops, esp. nanmin/max bug for np<1.13 (pandas-dev#19753)
1 parent 52be57d commit e9bb374

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pandas/tests/test_nanops.py

+32
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pandas.core.nanops as nanops
1414
import pandas.util.testing as tm
1515
import pandas.util._test_decorators as td
16+
from pandas.compat.numpy import _np_version_under1p13
1617

1718
use_bn = nanops._USE_BOTTLENECK
1819

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

10171018
pd.set_option('use_bottleneck', use_bn)
1019+
1020+
1021+
@pytest.mark.parametrize("numpy_op, expected", [
1022+
(np.sum, 10),
1023+
(np.nansum, 10),
1024+
(np.mean, 2.5),
1025+
(np.nanmean, 2.5),
1026+
(np.median, 2.5),
1027+
(np.nanmedian, 2.5),
1028+
(np.min, 1),
1029+
(np.max, 4),
1030+
])
1031+
def test_numpy_ops(numpy_op, expected):
1032+
# GH8383
1033+
result = numpy_op(pd.Series([1, 2, 3, 4]))
1034+
assert result == expected
1035+
1036+
1037+
@pytest.mark.parametrize("numpy_op, expected", [
1038+
(np.nanmin, 1),
1039+
(np.nanmax, 4),
1040+
])
1041+
def test_numpy_ops_np_version_under1p13(numpy_op, expected):
1042+
# GH8383
1043+
result = numpy_op(pd.Series([1, 2, 3, 4]))
1044+
if _np_version_under1p13:
1045+
# bug for numpy < 1.13, where result is a series, should be a scalar
1046+
with pytest.raises(ValueError):
1047+
assert result == expected
1048+
else:
1049+
assert result == expected

0 commit comments

Comments
 (0)