8000 MAINT: Create rec and char submodules · numpy/numpy@ddf19d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddf19d4

Browse files
committed
MAINT: Create rec and char submodules
1 parent 98f286f commit ddf19d4

17 files changed

+103
-24
lines changed

doc/source/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ Glossary
442442
record array
443443
A :term:`structured array` with allowing access in an attribute style
444444
(``a.field``) in addition to ``a['field']``. For details, see
445-
:doc:`numpy.recarray. <reference/generated/numpy.recarray>`
445+
:doc:`numpy.rec.recarray. <reference/generated/numpy.rec.recarray>`
446446

447447

448448
row-major

doc/source/reference/arrays.classes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ data-type. However, a chararray can also be created using the
501501
:toctree: generated/
502502

503503
char.chararray
504-
core.defchararray.array
504+
char.array
505505

506506
Another difference with the standard ndarray of str data-type is
507507
that the chararray inherits the feature introduced by Numarray that
@@ -526,7 +526,7 @@ scalar data type object :class:`record`.
526526
.. autosummary::
527527
:toctree: generated/
528528

529-
recarray
529+
rec.recarray
530530
record
531531

532532
.. note::

doc/source/user/basics.io.genfromtxt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Validating names
323323
----------------
324324

325325
NumPy arrays with a structured dtype can also be viewed as
326-
:class:`~numpy.recarray`, where a field can be accessed as if it were an
326+
:class:`~numpy.rec.recarray`, where a field can be accessed as if it were an
327327
attribute. For that reason, we may need to make sure that the field name
328328
doesn't contain any space or invalid character, or that it does not
329329
correspond to the name of a standard attribute (like ``size`` or

doc/source/user/basics.rec.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,8 @@ Record Arrays
630630
=============
631631

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

702702
Note that if a field has the same name as an ndarray attribute, the ndarray
703703
attribute takes precedence. Such fields will be inaccessible by attribute but

numpy/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129
atleast_1d, atleast_2d, atleast_3d, base_repr, binary_repr,
130130
bitwise_and, bitwise_not, bitwise_or, bitwise_xor, block, bool_,
131131
broadcast, busday_count, busday_offset, busdaycalendar, byte, bytes_,
132-
can_cast, cbrt, cdouble, ceil, char, character,
133-
choose, clip, clongdouble,
132+
can_cast, cbrt, cdouble, ceil, character, choose, clip, clongdouble,
134133
complexfloating, compress, concatenate, conj, conjugate, convolve,
135134
copysign, copyto, correlate, cos, cosh, count_nonzero, cross, csingle,
136135
cumprod, cumproduct, cumsum, datetime64, datetime_as_string,
@@ -156,7 +155,7 @@
156155
negative, nested_iters, newaxis, nextafter, nonzero, not_equal,
157156
number, object_, ones, ones_like, outer, partition,
158157
pi, positive, power, printoptions, prod, product, promote_types,
159-
ptp, put, putmask, rad2deg, radians, ravel, rec, reciprocal,
158+
ptp, put, putmask, rad2deg, radians, ravel, reciprocal,
160159
record, remainder, repeat, require, reshape, resize, result_type,
161160
right_shift, rint, roll, rollaxis, round,
162161
searchsorted, set_printoptions,
@@ -243,7 +242,7 @@
243242
__numpy_submodules__ = {
244243
"linalg", "fft", "dtypes", "random", "polynomial", "ma",
245244
"exceptions", "lib", "ctypeslib", "testing", "typing",
246-
"f2py", "test"
245+
"f2py", "test", "rec", "char"
247246
}
248247

249248
# We build warning messages for former attributes
@@ -350,6 +349,12 @@ def __getattr__(attr):
350349
elif attr == "typing":
351350
import numpy.typing as typing
352351
return typing
352+
elif attr == "rec":
353+
import numpy.rec as rec
354+
return rec
355+
elif attr == "char":
356+
import numpy.char as char
357+
return char
353358
elif attr == "array_api":
354359
import numpy.array_api as array_api
355360
return array_api

numpy/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ from numpy import (
210210
version as version,
211211
exceptions as exceptions,
212212
dtypes as dtypes,
213+
rec as rec,
214+
char as char,
213215
)
214216

215217
from numpy.core import defchararray, records

numpy/char/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from numpy.core.defchararray import __all__, __doc__
2+
from numpy.core.defchararray import *

numpy/char/__init__.pyi

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from numpy.core.defchararray import (
2+
equal as equal,
3+
not_equal as not_equal,
4+
greater_equal as greater_equal,
5+
less_equal as less_equal,
6+
greater as greater,
7+
less as less,
8+
str_len as str_len,
9+
add as add,
10+
multiply as multiply,
11+
mod as mod,
12+
capitalize as capitalize,
13+
center as center,
14+
count as count,
15+
decode as decode,
16+
encode as encode,
17+
endswith as endswith,
18+
expandtabs as expandtabs,
19+
find as find,
20+
index as index,
21+
isalnum as isalnum,
22+
isalpha as isalpha,
23+
isdigit as isdigit,
24+
islower as islower,
25+
isspace as isspace,
26+
istitle as istitle,
27+
isupper as isupper,
28+
join as join,
29+
ljust as ljust,
30+
lower as lower,
31+
lstrip as lstrip,
32+
partition as partition,
33+
replace as replace,
34+
rfind as rfind,
35+
rindex as rindex,
36+
rjust as rjust,
37+
rpartition as rpartition,
38+
rsplit as rsplit,
39+
rstrip as rstrip,
40+
split as split,
41+
splitlines as splitlines,
42+
startswith as startswith,
43+
strip as strip,
44+
swapcase as swapcase,
45+
title as title,
46+
translate as translate,
47+
upper as upper,
48+
zfill as zfill,
49+
isnumeric as isnumeric,
50+
isdecimal as isdecimal,
51+
array as array,
52+
asarray as asarray,
53+
compare_chararrays as compare_chararrays,
54+
chararray as chararray
55+
)

numpy/core/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@
7676
from .numeric import *
7777
from . import fromnumeric
7878
from .fromnumeric import *
79-
from . import defchararray as char
80-
from . import records
81-
from . import records as rec
82-
from .records import record, recarray, format_parser
79+
from .records import record
8380
# Note: module name memmap is overwritten by a class with same name
8481
from .memmap import *
8582
from . import function_base
@@ -105,7 +102,7 @@
105102
from . import _dtype
106103
from . import _methods
107104

108-
__all__ = ['char', 'rec', 'memmap', 'record', 'abs']
105+
__all__ = ['memmap', 'record', 'abs']
109106
__all__ += numeric.__all__
110107
__all__ += function_base.__all__
111108
__all__ += getlimits.__all__

numpy/core/defchararray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
3636
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
3737
'title', 'translate', 'upper', 'zfill', 'isnumeric', 'isdecimal',
38-
'array', 'asarray', 'compare_chararrays'
38+
'array', 'asarray', 'compare_chararrays', 'chararray'
3939
]
4040

4141

@@ -1919,6 +1919,7 @@ def isdecimal(a):
19191919
return _vec_string(a, bool_, 'isdecimal')
19201920

19211921

1922+
@set_module("numpy.char")
19221923
class chararray(ndarray):
19231924
"""
19241925
chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0,

numpy/core/records.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# All of the functions allow formats to be a dtype
4747
__all__ = [
4848
'record', 'recarray', 'format_parser', 'fromarrays', 'fromrecords',
49-
'fromstring', 'fromfile', 'array',
49+
'fromstring', 'fromfile', 'array', 'find_duplicate',
5050
]
5151

5252

@@ -75,6 +75,7 @@
7575
numfmt = nt.sctypeDict
7676

7777

78+
@set_module('numpy.rec')
7879
def find_duplicate(list):
7980
"""Find duplication in a list, return a list of duplicated elements"""
8081
return [
@@ -305,6 +306,8 @@ def pprint(self):
305306
# If byteorder is given it forces a particular byteorder on all
306307
# the fields (and any subfields)
307308

309+
310+
@set_module("numpy.rec")
308311
class recarray(ndarray):
309312
"""Construct an ndarray that allows field access using attributes.
310313
@@ -535,7 +538,7 @@ def __repr__(self):
535538
# This should only happen if the user is playing
536539
# strange games with dtypes.
537540
prefix = "array("
538-
fmt = 'array(%s,%sdtype=%s).view(numpy.recarray)'
541+
fmt = 'array(%s,%sdtype=%s).view(numpy.rec.recarray)'
539542

540543
# get data/shape string. logic taken from numeric.array_repr
541544
if self.size > 0 or self.shape == (0,):

numpy/lib/recfunctions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def _rec_drop_fields_dispatcher(base, drop_names):
596596
@array_function_dispatch(_rec_drop_fields_dispatcher)
597597
def rec_drop_fields(base, drop_names):
598598
"""
599-
Returns a new numpy.recarray with fields in `drop_names` dropped.
599+
Returns a new numpy.rec.recarray with fields in `drop_names` dropped.
600600
"""
601601
return drop_fields(base, drop_names, usemask=False, asrecarray=True)
602602

@@ -958,7 +958,7 @@ def structured_to_unstructured(arr, dtype=None, copy=False, casting='unsafe'):
958958
If true, always return a copy. If false, a view is returned if
959959
possible, such as when the `dtype` and strides of the fields are
960960
suitable and the array subtype is one of `numpy.ndarray`,
961-
`numpy.recarray` or `numpy.memmap`.
961+
`numpy.rec.recarray` or `numpy.memmap`.
962962
963963
.. versionchanged:: 1.25.0
964964
A view can now be returned if the fields are separated by a

numpy/ma/mrecords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
""":mod:`numpy.ma..mrecords`
22
3-
Defines the equivalent of :class:`numpy.recarrays` for masked arrays,
3+
Defines the equivalent of :class:`numpy.rec.recarrays` for masked arrays,
44
where fields can be accessed as attributes.
55
Note that :class:`numpy.ma.MaskedArray` already supports structured datatypes
66
and the masking of individual fields.

numpy/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ pure_subdirs = [
293293
'polynomial',
294294
'testing',
295295
'tests',
296-
'typing'
296+
'typing',
297+
'rec',
298+
'char'
297299
]
298300
if py.version().version_compare('<3.12')
299301
pure_subdirs += 'distutils'

numpy/rec/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from numpy.core.records import __all__, __doc__
2+
from numpy.core.records import *

numpy/rec/__init__.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from numpy.core.records import (
2+
record as record,
3+
recarray as recarray,
4+
format_parser as format_parser,
5+
fromarrays as fromarrays,
6+
fromrecords as fromrecords,
7+
fromstring as fromstring,
8+
fromfile as fromfile,
9+
array as array
10+
)

numpy/typing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
Record array dtypes
136136
~~~~~~~~~~~~~~~~~~~
137137
138-
The dtype of `numpy.recarray`, and the `numpy.rec` functions in general,
138+
The dtype of `numpy.rec.recarray`, and the `numpy.rec` functions in general,
139139
can be specified in one of two ways:
140140
141141
* Directly via the ``dtype`` argument.

0 commit comments

Comments
 (0)
0