8000 API: Cleaning `numpy/__init__.py` and main namespace - Part 5 [NEP 52] by mtsokol · Pull Request #24587 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Cleaning numpy/__init__.py and main namespace - Part 5 [NEP 52] #24587

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 11 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions doc/release/upcoming_changes/24587.python_removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* ``np.compare_chararrays`` has been removed from the main namespace.
Use ``np.char.compare_chararrays`` instead.

* The ``charrarray`` in the main namespace has been deprecated. It can be imported
without a deprecation warning from ``np.char.chararray`` for now,
but we are planning to fully deprecate and remove ``chararray`` in the future.

* ``np.format_parser`` has been removed from the main namespace.
Use ``np.rec.format_parser`` instead.
6 changes: 3 additions & 3 deletions doc/source/reference/arrays.classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,14 @@ executing them on an element-by-element basis. Perhaps the easiest
way to create a chararray is to use :meth:`self.view(chararray)
<ndarray.view>` where *self* is an ndarray of str or unicode
data-type. However, a chararray can also be created using the
:meth:`numpy.chararray` constructor, or via the
:meth:`numpy.char.chararray` constructor, or via the
:func:`numpy.char.array <core.defchararray.array>` function:

.. autosummary::
:toctree: generated/

chararray
core.defchararray.array
char.chararray
char.array

Another difference with the standard ndarray of str data-type is
that the chararray inherits the feature introduced by Numarray that
Expand Down
2 changes: 1 addition & 1 deletion doc/source/reference/routines.dtype.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Creating data types
:toctree: generated/

dtype
format_parser
rec.format_parser

Data type information
---------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/source/user/basics.rec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ Record Arrays
=============

As an optional convenience numpy provides an ndarray subclass,
:class:`numpy.recarray` that allows access to fields of structured arrays by
attribute instead of only by index.
:class:`numpy.recarray` that allows access to fields of structured arrays
by attribute instead of only by index.
Record arrays use a special datatype, :class:`numpy.record`, that allows
field access by attribute on the structured scalars obtained from the array.
The ``numpy.rec`` module provides functions for creating recarrays from
Expand Down Expand Up @@ -697,7 +697,7 @@ array if the field has a structured type but as a plain ndarray otherwise. ::
>>> type(recordarr.foo)
<class 'numpy.ndarray'>
>>> type(recordarr.bar)
<class 'numpy.recarray'>
<class 'numpy.rec.recarray'>

Note that if a field has the same name as an ndarray attribute, the ndarray
attribute takes precedence. Such fields will be inaccessible by attribute but
Expand Down
25 changes: 19 additions & 6 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

from . import core
from .core import (
_no_nep50_warning, memmap, iinfo, finfo,
_no_nep50_warning, memmap, iinfo, finfo, recarray,
False_, ScalarType, True_, abs, absolute, add, all, allclose, alltrue,
amax, amin, any, arange, arccos, arccosh, arcsin, arcsinh, arctan,
arctan2, arctanh, argmax, argmin, argpartition, argsort, argwhere,
Expand All @@ -129,8 +129,7 @@
atleast_1d, atleast_2d, atleast_3d, base_repr, binary_repr,
bitwise_and, bitwise_not, bitwise_or, bitwise_xor, block, bool_,
broadcast, busday_count, busday_offset, busdaycalendar, byte, bytes_,
can_cast, cbrt, cdouble, ceil, char, character, chararray,
choose, clip, clongdouble, compare_chararrays,
can_cast, cbrt, cdouble, ceil, character, choose, clip, clongdouble,
complexfloating, compress, concatenate, conj, conjugate, convolve,
copysign, copyto, correlate, cos, cosh, count_nonzero, cross, csingle,
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
Expand All @@ -139,7 +138,7 @@
errstate, euler_gamma, exp, exp2, expm1, fabs,
flatiter, flatnonzero, flexible, sctypeDict,
float_power, floating, floor, floor_divide, fmax, fmin, fmod,
format_float_positional, format_float_scientific, format_parser,
format_float_positional, format_float_scientific,
frexp, from_dlpack, frombuffer, fromfile, fromfunction, fromiter,
frompyfunc, fromstring, full, full_like, gcd, generic, geomspace,
get_printoptions, getbufsize, geterr, geterrcall, greater,
Expand All @@ -156,7 +155,7 @@
negative, nested_iters, newaxis, nextafter, nonzero, not_equal,
number, object_, ones, ones_like, outer, partition,
pi, positive, power, printoptions, prod, product, promote_types,
ptp, put, putmask, rad2deg, radians, ravel, rec, recarray, reciprocal,
ptp, put, putmask, rad2deg, radians, ravel, reciprocal,
record, remainder, repeat, require, reshape, resize, result_type,
right_shift, rint, roll, rollaxis, round,
searchsorted, set_printoptions,
Expand Down Expand Up @@ -248,7 +247,7 @@
__numpy_submodules__ = {
"linalg", "fft", "dtypes", "random", "polynomial", "ma",
"exceptions", "lib", "ctypeslib", "testing", "typing",
"f2py", "test"
"f2py", "test", "rec", "char"
}

# We build warning messages for former attributes
Expand Down Expand Up @@ -358,6 +357,12 @@ def __getattr__(attr):
elif attr == "typing":
import numpy.typing as typing
return typing
elif attr == "rec":
import numpy.rec as rec
return rec
elif attr == "char":
import numpy.char as char
return char
elif attr == "array_api":
import numpy.array_api as array_api
return array_api
Expand Down Expand Up @@ -385,6 +390,14 @@ def __getattr__(attr):
f"{__expired_attributes__[attr]}"
)

if attr == "chararray":
warnings.warn(
"`np.chararray` is deprecated and will be removed from "
"the main namespace in the future. Use an array with a string "
"or bytes dtype instead.", DeprecationWarning, stacklevel=2)
import numpy.char as char
return char.chararray

raise AttributeError("module {!r} has no attribute "
"{!r}".format(__name__, attr))

Expand Down
Loading
0