|
13 | 13 | import pandas.core.nanops as nanops
|
14 | 14 | import pandas.util.testing as tm
|
15 | 15 | import pandas.util._test_decorators as td
|
| 16 | +from pandas.compat.numpy import _np_version_under1p13 |
16 | 17 |
|
17 | 18 | use_bn = nanops._USE_BOTTLENECK
|
18 | 19 |
|
@@ -1015,3 +1016,34 @@ def test_use_bottleneck():
|
1015 | 1016 | assert not pd.get_option('use_bottleneck')
|
1016 | 1017 |
|
1017 | 1018 | 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