8000 MAINT: Remove any promotion-state switching logic by seberg · Pull Request #27156 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove any promotion-state switching logic #27156

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 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DOC: Mention semi-private removed functions and tweak docs
  • Loading branch information
seberg committed Aug 9, 2024
commit 5a6435cb19a8d0ca5664e30262e47c2c0c010713
7 changes: 4 additions & 3 deletions doc/release/upcoming_changes/27156.change.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NEP 50 promotion state option removed
The NEP 50 promotion state settings are now removed. They were always
meant as temporary means for testing.
A warning will be given if the environment variable is set to anything
but ``NPY_PROMOTION_STATE=weak``.
If for some reason your code sets the promotion state to weak with the
semi-private helper, replace it with ``contextlib.nullcontext``.
but ``NPY_PROMOTION_STATE=weak`` wile ``_set_promotion_state``
and ``_get_promotion_state`` are removed.
In case code used ``_no_nep50_warning``, a ``contextlib.nullcontext``
could be used to replace it when not available.
38 changes: 12 additions & 26 deletions doc/source/reference/c-api/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1089,14 +1089,13 @@ Converting data types
returned when the value will not overflow or be truncated to
an integer when converting to a smaller type.

This is almost the same as the result of
PyArray_CanCastTypeTo(PyArray_MinScalarType(arr), totype, casting),
but it also handles a special case arising because the set
of uint values is not a subset of the int values for types with the
same number of bits.

.. c:function:: PyArray_Descr* PyArray_MinScalarType(PyArrayObject* arr)

.. note::
With the adoption of NEP 50 in NumPy 2, this function is not used
internally. It is currently provided for backwards compatibility,
but expected to be eventually deprecated.

.. versionadded:: 1.6

If *arr* is an array, returns its data type descriptor, but if
Expand Down Expand Up @@ -1134,8 +1133,7 @@ Converting data types

.. c:function:: int PyArray_ObjectType(PyObject* op, int mintype)

This function is superseded by :c:func:`PyArray_MinScalarType` and/or
:c:func:`PyArray_ResultType`.
This function is superseded by :c:func:`PyArray_ResultType`.

This function is useful for determining a common type that two or
more arrays can be converted to. It only works for non-flexible
Expand Down Expand Up @@ -3243,30 +3241,18 @@ Array scalars
.. c:function:: NPY_SCALARKIND PyArray_ScalarKind( \
int typenum, PyArrayObject** arr)

See the function :c:func:`PyArray_MinScalarType` for an alternative
mechanism introduced in NumPy 1.6.0.
Legacy way to query special promotion for scalar values. This is not
used in NumPy itself anymore and is expected to be deprecated eventually.

Return the kind of scalar represented by *typenum* and the array
in *\*arr* (if *arr* is not ``NULL`` ). The array is assumed to be
rank-0 and only used if *typenum* represents a signed integer. If
*arr* is not ``NULL`` and the first element is negative then
:c:data:`NPY_INTNEG_SCALAR` is returned, otherwise
:c:data:`NPY_INTPOS_SCALAR` is returned. The possible return values
are the enumerated values in :c:type:`NPY_SCALARKIND`.
New DTypes can define promotion rules specific to Python scalars.

.. c:function:: int PyArray_CanCoerceScalar( \
char thistype, char neededtype, NPY_SCALARKIND scalar)

See the function :c:func:`PyArray_ResultType` for details of
NumPy type promotion, updated in NumPy 1.6.0.
Legacy way to query special promotion for scalar values. This is not
used in NumPy itself anymore and is expected to be deprecated eventually.

Implements the rules for scalar coercion. Scalars are only
silently coerced from thistype to neededtype if this function
returns nonzero. If scalar is :c:data:`NPY_NOSCALAR`, then this
function is equivalent to :c:func:`PyArray_CanCastSafely`. The rule is
that scalars of the same KIND can be coerced into arrays of the
same KIND. This rule means that high-precision scalars will never
cause low-precision arrays of the same KIND to be upcast.
Use ``PyArray_ResultType`` for similar purposes.


Data-type descriptors
Expand Down
0