summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/_ufunc_config.py2
-rw-r--r--numpy/core/code_generators/generate_umath.py6
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py63
-rw-r--r--numpy/core/src/umath/umathmodule.c4
-rw-r--r--numpy/core/tests/test_datetime.py2
-rw-r--r--numpy/lib/tests/test_arraypad.py2
6 files changed, 13 insertions, 66 deletions
diff --git a/numpy/core/_ufunc_config.py b/numpy/core/_ufunc_config.py
index b40e7445e..a731f6bf7 100644
--- a/numpy/core/_ufunc_config.py
+++ b/numpy/core/_ufunc_config.py
@@ -290,7 +290,7 @@ def seterrcall(func):
>>> save_err = np.seterr(all='log')
>>> np.array([1, 2, 3]) / 0.0
- LOG: Warning: divide by zero encountered in true_divide
+ LOG: Warning: divide by zero encountered in divide
array([inf, inf, inf])
>>> np.seterrcall(saved_handler)
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 292d9e0d3..0320dcbb3 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -322,7 +322,7 @@ defdict = {
],
TD(O, f='PyNumber_Multiply'),
),
-#'divide' : aliased to true_divide in umathmodule.c:initumath
+#'true_divide' : aliased to divide in umathmodule.c:initumath
'floor_divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
docstrings.get('numpy.core.umath.floor_divide'),
@@ -336,9 +336,9 @@ defdict = {
],
TD(O, f='PyNumber_FloorDivide'),
),
-'true_divide':
+'divide':
Ufunc(2, 1, None, # One is only a unit to the right, not the left
- docstrings.get('numpy.core.umath.true_divide'),
+ docstrings.get('numpy.core.umath.divide'),
'PyUFunc_TrueDivisionTypeResolver',
TD(flts+cmplx, cfunc_alias='divide', dispatch=[('loops_arithm_fp', 'fd')]),
[TypeDescription('m', FullTypeDescr, 'mq', 'm', cfunc_alias='divide'),
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py
index cd584eea7..9c4a972c6 100644
--- a/numpy/core/code_generators/ufunc_docstrings.py
+++ b/numpy/core/code_generators/ufunc_docstrings.py
@@ -1089,9 +1089,8 @@ add_newdoc('numpy.core.umath', 'divide',
-----
Equivalent to ``x1`` / ``x2`` in terms of array-broadcasting.
- Behavior on division by zero can be changed using ``seterr``.
-
- Behaves like ``true_divide``.
+ The ``true_divide(x1, x2)`` function is an alias for
+ ``divide(x1, x2)``.
Examples
--------
@@ -1100,13 +1099,9 @@ add_newdoc('numpy.core.umath', 'divide',
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.divide(x1, x2)
- array([[ NaN, 1. , 1. ],
- [ Inf, 4. , 2.5],
- [ Inf, 7. , 4. ]])
-
- >>> ignored_states = np.seterr(**old_err_state)
- >>> np.divide(1, 0)
- 0
+ array([[nan, 1. , 1. ],
+ [inf, 4. , 2.5],
+ [inf, 7. , 4. ]])
The ``/`` operator can be used as a shorthand for ``np.divide`` on
ndarrays.
@@ -4052,54 +4047,6 @@ add_newdoc('numpy.core.umath', 'tanh',
""")
-add_newdoc('numpy.core.umath', 'true_divide',
- """
- Returns a true division of the inputs, element-wise.
-
- Unlike 'floor division', true division adjusts the output type
- to present the best answer, regardless of input types.
-
- Parameters
- ----------
- x1 : array_like
- Dividend array.
- x2 : array_like
- Divisor array.
- $BROADCASTABLE_2
- $PARAMS
-
- Returns
- -------
- out : ndarray or scalar
- $OUT_SCALAR_2
-
- Notes
- -----
- In Python, ``//`` is the floor division operator and ``/`` the
- true division operator. The ``true_divide(x1, x2)`` function is
- equivalent to true division in Python.
-
- Examples
- --------
- >>> x = np.arange(5)
- >>> np.true_divide(x, 4)
- array([ 0. , 0.25, 0.5 , 0.75, 1. ])
-
- >>> x/4
- array([ 0. , 0.25, 0.5 , 0.75, 1. ])
-
- >>> x//4
- array([0, 0, 0, 0, 1])
-
- The ``/`` operator can be used as a shorthand for ``np.true_divide`` on
- ndarrays.
-
- >>> x = np.arange(5)
- >>> x / 4
- array([0. , 0.25, 0.5 , 0.75, 1. ])
-
- """)
-
add_newdoc('numpy.core.umath', 'frexp',
"""
Decompose the elements of x into mantissa and twos exponent.
diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c
index 272555704..f8d010ee0 100644
--- a/numpy/core/src/umath/umathmodule.c
+++ b/numpy/core/src/umath/umathmodule.c
@@ -288,8 +288,8 @@ int initumath(PyObject *m)
PyModule_AddObject(m, "NZERO", PyFloat_FromDouble(NPY_NZERO));
PyModule_AddObject(m, "NAN", PyFloat_FromDouble(NPY_NAN));
- s = PyDict_GetItemString(d, "true_divide");
- PyDict_SetItemString(d, "divide", s);
+ s = PyDict_GetItemString(d, "divide");
+ PyDict_SetItemString(d, "true_divide", s);
s = PyDict_GetItemString(d, "conjugate");
s2 = PyDict_GetItemString(d, "remainder");
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 50da7b800..c6a3d4e79 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -1437,7 +1437,7 @@ class TestDateTime:
# NaTs
with suppress_warnings() as sup:
- sup.filter(RuntimeWarning, r".*encountered in true\_divide")
+ sup.filter(RuntimeWarning, r".*encountered in divide")
nat = np.timedelta64('NaT')
for tp in (int, float):
assert_equal(np.timedelta64(1) / tp(0), nat)
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py
index 75db5928b..ca3c35335 100644
--- a/numpy/lib/tests/test_arraypad.py
+++ b/numpy/lib/tests/test_arraypad.py
@@ -474,7 +474,7 @@ class TestStatistic:
@pytest.mark.filterwarnings("ignore:Mean of empty slice:RuntimeWarning")
@pytest.mark.filterwarnings(
- "ignore:invalid value encountered in (true_divide|double_scalars):"
+ "ignore:invalid value encountered in (divide|double_scalars):"
"RuntimeWarning"
)
@pytest.mark.parametrize("mode", ["mean", "median"])