+
    ei  c                   s   R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^RI	H
t ^RI	Ht ^RIHt . R%Ot]P"                  tRRRRRRRRRRRRRRRRRRRRRRRRRRRR/t]P&                  t]! R4      R 4       t]! R4       ! R R
4      4       t ! R R]P.                  4      t]! R4       ! R R	]4      4       tR t]! R4      R&R l4       t]! R4      R&R  l4       t]! R4      R'R! l4       tR" t]! R4      R'R# l4       t]! R4      R(R$ l4       t R# ))z<
This module contains a set of functions for record arrays.
N)Counter)nullcontext)
set_module)numeric)numerictypes)_get_legacy_print_moderecordrecarrayformat_parserZbZ>ZlZ<nZ=ZBZLZNZSZsZ|ZIiz	numpy.recc                sz    \        V 4      P                  4        UUu. uF  w  rV^8  g   K  VNK  	  upp# u uppi )z@Find duplication in a list, return a list of duplicated elements)r    Zitems)listitemZcountss   &  :/usr/lib64/python3.14/site-packages/numpy/_core/records.pyfind_duplicater   /   sA    
 $DM//11LDA: 	1  s   77c                   sD   a  ] tR t^9t o RtRR ltR	R ltR tR tRt	V t
R# )
r   a  
Class to convert formats, names, titles description to a dtype.

After constructing the format_parser object, the dtype attribute is
the converted data-type:
``dtype = format_parser(formats, names, titles).dtype``

Attributes
----------
dtype : dtype
    The converted data-type.

Parameters
----------
formats : str or list of str
    The format description, either specified as a string with
    comma-separated format descriptions in the form ``'f8, i4, S5'``, or
    a list of format description strings  in the form
    ``['f8', 'i4', 'S5']``.
names : str or list/tuple of str
    The field names, either specified as a comma-separated string in the
    form ``'col1, col2, col3'``, or as a list or tuple of strings in the
    form ``['col1', 'col2', 'col3']``.
    An empty list can be used, in that case default field names
    ('f0', 'f1', ...) are used.
titles : sequence
    Sequence of title strings. An empty list can be used to leave titles
    out.
aligned : bool, optional
    If True, align the fields by padding as the C-compiler would.
    Default is False.
byteorder : str, optional
    If specified, all the fields will be changed to the
    provided byte-order.  Otherwise, the default byte-order is
    used. For all available string specifiers, see `dtype.newbyteorder`.

See Also
--------
numpy.dtype, numpy.typename

Examples
--------
>>> import numpy as np
>>> np.rec.format_parser(['<f8', '<i4'], ['col1', 'col2'],
...                      ['T1', 'T2']).dtype
dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4')])

`names` and/or `titles` can be empty lists. If `titles` is an empty list,
titles will simply not appear. If `names` is empty, default field names
will be used.

>>> np.rec.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
...                      []).dtype
dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
>>> np.rec.format_parser(['<f8', '<i4', '<a5'], [], []).dtype
dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])

Nc                sl    V P                  W4       V P                  W#4       V P                  V4       R # N)_parseFormats_setfieldnames_createdtype)selfformatsnamestitlesaligned	byteorders   &&&&&&r   __init__Zformat_parser.__init__v   s,    7,E*)$    c                sD   Vf   \        R4      h\        V\        4      '       d;   \        P                  ! \        V4       UUu. uF  w  r4RV 2V3NK  	  uppV4      pM\        P                  ! W4      pVP                  pVf'   \        P                  ! RV3.V4      pVP                  pVP                  pV Uu. uF  qV,          ^ ,          NK  	  upV n        V Uu. uF  qV,          ^,          NK  	  upV n	        \        V4      V n        R# u uppi u upi u upi )zParse the field formats NzNeed formats argumentZfZf1)
ValueError
isinstancer   sbdtype	enumeratefieldsr   
_f_formats_offsetslen_nfields)	r   r   r   r
   Zformat_r   r    ZkeysZkeys	   &&&      r   r   Zformat_parser._parseFormats{   s     ?455gt$$HH '0&8&8
 Wg&&8 E HHW.E>HHtUm_g6E\\F{{59:Tc#;q>>T:3784CQ48D	 ;8s   D
<D Dc                s   V'       d   \        V4      \        \        39   d   M?\        V\        4      '       d   VP                  R4      pM\        R\        V4       24      hVRV P                    Uu. uF  q3P                  4       NK  	  upV n
        M. V n
        T ;P                  \        \        V P                  4      V P                  4       Uu. uF  pRV,          NK  	  up,          un
        \        V P                  4      pV'       d   \        RV 24      hV'       d3   VRV P                    Uu. uF  q3P                  4       NK  	  upV n        M	. V n        . pV P                  \        V4      8  d>   V ;P                  R.V P                  \        V4      ,
          ,          ,          un        R# R# u upi u upi u upi )zIconvert input field names into a list and assign to the _names
attribute ,zillegal input names Nzf%dzDuplicate field names: )typer   tupler   strZsplitZ	NameErrorreprr$   Zstrip_namesranger#   r   r   _titles)r   r   r   r	   r
   Z_dups   &&&   r   r   Zformat_parser._setfieldnames   sm    E{tUm+E3''C("6tE{m DEE.3NT]].CD.C779.CDDKDK 	5T[[1A15,@ A ,@a		 ,@ A 	A dkk*6tf=>>/5nt}}/EF/E!GGI/EFDLDLF==3v;&LLTFdmmc&k&ABBL '+ EA Gs   4F:F?7Gc           
     s    \         P                  ! R V P                  RV P                  RV P                  RV P
                  /4      pVe&   \        V^ ,          ,          pVP                  V4      pW n        R# )r   r   Zoffsetsr   N)r   r   r*   r!   r"   r,   _byteorderconvZnewbyteorder)r   r   r      && r   r   Zformat_parser._createdtype   sd    T[[tt}}dll	
   &y|4I&&y1E
r   )r!   r*   r$   r"   r,   r   )FN)F)__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r   9   s&     9v%
"0"CH r   c                   sb   a a ] tR t^t oRtR t RtV 3R ltV 3R ltR tR tR t	R t
R	tVtV ;t# )
r   zEA data-type scalar that allows field access as attribute lookup.
    Znumpyc                s^   < \        4       ^q8:  d   V P                  4       # \        SV `  4       # iq   )r   __str__super__repr__r   	__class__   &r   r:   Zrecord.__repr__   s(    !#s*<<>!w!!r   c                sp   < \        4       ^q8:  d   \        V P                  4       4      # \        SV `  4       # r7   )r   r(   r   r9   r8   r;   r=   r   r8   Zrecord.__str__   s,    !#s*tyy{##w  r   c                s4   VR9   d    \         P                  P                  W4      #  \         P                  P                  W4      #   \         d     Mi ; i\         P                  P                  T R4      P                  pTP                  TR4      pT'       dp   T P                  ! TR,          !  p TP                  pM  \         d    Tu # i ; iTP                  e(   TP                  T P                  TP                  34      # T# \        RT R24      h)setfieldr   NNi   N"'record' object has no attribute ''r>   getfieldr   )ntvoid__getattribute__AttributeErrorr    getrC   r   r   viewr<   )r   attr	fielddictresobjZdt   &&    r   rF   Zrecord.__getattribute__   s    4477++D77	77++D77 		GG,,T7;BB	mmD$'--R)CYY! 
 xx#xx ;<<J #EdV1!MNNs#   A AA4C CCc                sn   VR9   d   \        RV R24      h\        P                  P                  V R4      P                  pVP                  VR4      pV'       d   V P                  ! V.VR,          O5!  # \        WR4      '       d!   \        P                  P                  WV4      # \        RV R24      h)	r>   r   zCannot set 'z' attributeNr?   r@   rA   rB   )	rG   rD   rE   rF   r    rH   r>   getattr__setattr__)r   rJ   valrK   rL   s   &&&  r   rP   Zrecord.__setattr__   s    44 <v[!ABBGG,,T7;BB	mmD$'==/s2w//T&&77&&t377 #EdV1!MNNr   c                s   \         P                  P                  W4      p\        V\         P                  4      '       d@   VP                  P
                  e(   VP                  V P                  VP                  34      # V# r   )rD   rE   __getitem__r   r   r   rI   r<   )r   indxrM   r.   r   rR   Zrecord.__getitem__   sY    gg!!$- c277##		(C88T^^SYY788 Jr   c           	     s    V P                   P                  p\        R V 4       4      pRV,          pV Uu. uF  qCV\        W4      3,          NK  	  ppRP	                  V4      # u upi )zPretty-print all fields.c              3   s8   "   T F  p\        V4      x  K  	  R # 5ir   )r#   )Z.0name   & r   Z	<genexpr>Z record.pprint.<locals>.<genexpr>
  s     154SYY5s   z%% %ds: %%s
)r   r   ZmaxrO   Zjoin)r   r   ZmaxlenfmtrT   Zrows   &     r   pprintZrecord.pprint  se     

  1511f$>CDedtWT0111eDyy Es   A% )r/   r0   r1   r2   r3   r:   r8   rF   rP   rR   rY   r4   r5   __classcell__r<   r6      @@r   r   r      s;     
 HJ"
!
O0
O r   c                   sb   a a ] tR tRt oRtRR ltR tR tR tV 3R lt	R t
RR	 ltR
tVtV ;t# )r   i  a  Construct an ndarray that allows field access using attributes.

Arrays may have a data-types containing fields, analogous
to columns in a spread sheet.  An example is ``[(x, int), (y, float)]``,
where each entry in the array is a pair of ``(int, float)``.  Normally,
these attributes are accessed using dictionary lookups such as ``arr['x']``
and ``arr['y']``.  Record arrays allow the fields to be accessed as members
of the array, using ``arr.x`` and ``arr.y``.

Parameters
----------
shape : tuple
    Shape of output array.
dtype : data-type, optional
    The desired data-type.  By default, the data-type is determined
    from `formats`, `names`, `titles`, `aligned` and `byteorder`.
formats : list of data-types, optional
    A list containing the data-types for the different columns, e.g.
    ``['i4', 'f8', 'i4']``.  `formats` does *not* support the new
    convention of using types directly, i.e. ``(int, float, int)``.
    Note that `formats` must be a list, not a tuple.
    Given that `formats` is somewhat limited, we recommend specifying
    `dtype` instead.
names : tuple of str, optional
    The name of each column, e.g. ``('x', 'y', 'z')``.
buf : buffer, optional
    By default, a new array is created of the given shape and data-type.
    If `buf` is specified and is an object exposing the buffer interface,
    the array will use the memory from the existing buffer.  In this case,
    the `offset` and `strides` keywords are available.

Other Parameters
----------------
titles : tuple of str, optional
    Aliases for column names.  For example, if `names` were
    ``('x', 'y', 'z')`` and `titles` is
    ``('x_coordinate', 'y_coordinate', 'z_coordinate')``, then
    ``arr['x']`` is equivalent to both ``arr.x`` and ``arr.x_coordinate``.
byteorder : {'<', '>', '='}, optional
    Byte-order for all fields.
aligned : bool, optional
    Align the fields in memory as the C-compiler would.
strides : tuple of ints, optional
    Buffer (`buf`) is interpreted according to these strides (strides
    define how many bytes each array element, row, column, etc.
    occupy in memory).
offset : int, optional
    Start reading buffer (`buf`) from this offset onwards.
order : {'C', 'F'}, optional
    Row-major (C-style) or column-major (Fortran-style) order.

Returns
-------
rec : recarray
    Empty array of the given shape and type.

See Also
--------
numpy.rec.fromrecords : Construct a record array from data.
numpy.record : fundamental data-type for `recarray`.
numpy.rec.format_parser : determine data-type from formats, names, titles.

Notes
-----
This constructor can be compared to ``empty``: it creates a new record
array but does not fill it with data.  To create a record array from data,
use one of the following methods:

1. Create a standard ndarray and convert it to a record array,
   using ``arr.view(np.recarray)``
2. Use the `buf` keyword.
3. Use `np.rec.fromrecords`.

Examples
--------
Create an array with two fields, ``x`` and ``y``:

>>> import numpy as np
>>> x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', '<f8'), ('y', '<i8')])
>>> x
array([(1., 2), (3., 4)], dtype=[('x', '<f8'), ('y', '<i8')])

>>> x['x']
array([1., 3.])

View the array as a record array:

>>> x = x.view(np.recarray)

>>> x.x
array([1., 3.])

>>> x.y
array([2, 4])

Create a new, empty record array:

>>> np.recarray((2,),
... dtype=[('x', int), ('y', float), ('z', int)]) #doctest: +SKIP
rec.array([(-1073741821, 1.2249118382103472e-301, 24547520),
       (3471280, 1.2134086255804012e-316, 0)],
      dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])

c           
     s    Ve   \         P                  ! V4      pM\        WgWV	4      P                  pVf!   \        P	                  W\
        V3VR7      pV# \        P	                  W\
        V3VWEVR7      pV# )N)order)Zbufferoffsetstridesr^   )r   r   r   ndarray__new__r   )Zsubtypeshaper   bufr_   r`   r   r   r   r   r   r^   descrr   s   &&&&&&&&&&&&  r   rb   Zrecarray.__new__  s     HHUOE!e  ;??u # D 	 ??e # D r   c                s    V P                   P                  \        Jd.   V P                   P                  e   V P                   V n         R # R # R # r   )r   r&   r   r   )r   rM   s   &&r   __array_finalize__Zrecarray.__array_finalize__  s7    ::??&(TZZ-=-=-I DJ .J(r   c                sL    \         P                  W4      #   \         d     Mi ; i\        P                  T R 4      P                  p Y!,          R,          pM(  \
        \        3 d   p\        RT 24      ThRp?ii ; iT P                  ! T!  pTP                  P                  ei   \        TP                  P                  \        P                  4      '       d3   TP                  T P                  P                  TP                  3R7      # T# TP                  \        4      # )r   r?   zrecarray has no attribute Nr   )objectrF   rG   ra   r    	TypeErrorKeyErrorrC   r   r   
issubclassr&   rD   rE   rI   )r   rJ   rK   rL   erM   rN   r   rF   Zrecarray.__getattribute__  s    	**466 		 ,,T7;BB		M/"%C8$ 	M #=dV!DE1L	MmmS! 99??&#)).."''22xxtzz		&BxCCJ88G$$s$    %%	A A>*A99A>c                s   VR 8X  dU   \        VP                  \        P                  4      '       d+   VP                  e   \
        P                  ! \        V34      pWP                  9  p \        P                  WV4      p\        P                  V R 4      P                  ;'       g    / pW9  d   V# V'       d    \        P                  W4       M  WQ,          R,          pT P&                  ! T.TO5!  #   \         d    Tu # i ; i  \         d5    \        P                  T R 4      P                  ;'       g    / pY9  d   h  Lui ; i  \         \"        3 d   p\%        RT 24      ThRp?ii ; i)r   Nr?   zrecord array has no attribute )rk   r&   rD   rE   r   r   r   r   Z__dict__rh   rP   ra   rF   r    Z__delattr__Z	Exceptionri   rj   rG   r>   )r   rJ   rQ   ZnewattrZretrK   rL   rl   s   &&&     r   rP   Zrecarray.__setattr__  sR   
 GOsxx))II!((FC=)Cmm+	$$T5C  00w?FFLL"I$
&&t2	 	/"%C
 }}S'3'' ! J  	00w?FFLL"I$ %	" 8$ 	 07	sB   +D
 <C7 E 7DD
1E	<
E	E	E1E,,E1c                s  < \         SV `  V4      p\        V\        4      '       d   VP                  P
                  e   VP                  \        V 4      4      p\        VP                  P                  \        P                  4      '       d3   VP                  V P                  P                  VP                  3R7      # V# VP                  \        R7      # V# )Nrg   )r&   )r9   rR   r   ra   r   r   rI   r&   rk   rD   rE   )r   rS   rM   r<   s   && r   rR   Zrecarray.__getitem__  s    g!$' c7##yy*hhtDz*ciinnbgg66884::??CII*F8GG
xxWx-- Jr   c                sd   V P                   pV P                   P                  \        J g5   \        V P                   P                  \        P
                  4      '       g@   VP                  \        J d'   \        P                   ! \        P
                  V34      pR pRpMRpRpV P                  ^ 8  g   V P                  R
8X  d   \        P                  ! V RVRR7      pMR\        V P                  4       2pRR	\        V4      ,          ,           p\        4       ^q8:  d
   R	V,           pW4WQ3,          # )z
rec.array(zrec.array(%s,%sdtype=%s)zarray(z)array(%s,%sdtype=%s).view(numpy.recarray)z, r%   )Z	separatorprefixZsuffixz
[], shape=rV   Z     )r   r&   r   rk   rD   rE   r   sizerc   Zarray2stringr)   r#   r   )r   Z
repr_dtyperm   rW   ZlstZlfrX   r   r:   Zrecarray.__repr__  s    ZZ
JJOOv%4::??BGG44 &(XXrww
&;<
!F,C
 F=C 99q=DJJ$.//VCAC tDJJ/01CC#f+%%!#s*rB2***r   c                s   \        V\        4      '       d)   \        P                  V R 4      P                  pW1,          p\        P                  V R 4      P
                  pWA,          R,          pVf@   V P                  ! V!  pVP                  P                  e   V# VP                  \        4      # V P                  ! V.VO5!  # )r   r?   )
r   intra   rF   r   r    rC   r   rI   r>   )r   rJ   rQ   r   rK   rL   rM   s   &&&    r   fieldZrecarray.field  s    dC  ,,T7;AAE;D,,T7;BB	ob!;--%Cyy*
88G$$==+s++r   rg   )
NNro   NNNNNFZCr   )r/   r0   r1   r2   r3   rb   rf   rF   rP   rR   r:   rr   r4   r5   r[   r\   r]   r   r   r     s7     gR,$%D#(J""+H, ,r   c                 sR    V ^ 8X  d    \         P                  ! R\        ^R7       R# V # )ro   zPassing `shape=0` to have the shape be inferred is deprecated, and in future will be equivalent to `shape=(0,)`. To infer the shape and suppress this warning, pass `shape=None` instead.Z
stacklevelN)warningswarnFutureWarning)rc   s   &r   _deprecate_shape_0_as_Nonerw   -  s,    zN a		)
 r   c                s&   V  Uu. uF  p\         P                  ! V4      NK  	  p p\        V4      pVf   V ^ ,          P                  pM\	        V\
        4      '       d   V3pVf   Vf   V  U	u. uF  qP                  NK  	  pp	Ve   \         P                  ! V4      p
M\        W4WVV4      P                  p
V
P                  p\        V
4      \        V 4      8w  d   \        R4      hV
^ ,          P                  p\        V4      pV^ 8  d   VRV)  p\        W*4      p\        V 4       F\  w  rW,          P                  pV	P                  RV	P                  V,
           pW,          pVV8w  d   \        RV RV R24      hWV&   K^  	  V# u upi u up	i )a  Create a record array from a (flat) list of arrays

Parameters
----------
arrayList : list or tuple
    List of array-like objects (such as lists, tuples,
    and ndarrays).
dtype : data-type, optional
    valid dtype for all arrays
shape : int or tuple of ints, optional
    Shape of the resulting array. If not provided, inferred from
    ``arrayList[0]``.
formats, names, titles, aligned, byteorder :
    If `dtype` is ``None``, these arguments are passed to
    `numpy.rec.format_parser` to construct a dtype. See that function for
    detailed documentation.

Returns
-------
np.recarray
    Record array consisting of given arrayList columns.

Examples
--------
>>> x1=np.array([1,2,3,4])
>>> x2=np.array(['a','dd','xyz','12'])
>>> x3=np.array([1.1,2,3,4])
>>> r = np.rec.fromarrays([x1,x2,x3],names='a,b,c')
>>> print(r[1])
(2, 'dd', 2.0) # may vary
>>> x1[1]=34
>>> r.a
array([1, 2, 3, 4])

>>> x1 = np.array([1, 2, 3, 4])
>>> x2 = np.array(['a', 'dd', 'xyz', '12'])
>>> x3 = np.array([1.1, 2, 3,4])
>>> r = np.rec.fromarrays(
...     [x1, x2, x3],
...     dtype=np.dtype([('a', np.int32), ('b', 'S3'), ('c', np.float32)]))
>>> r
rec.array([(1, b'a', 1.1), (2, b'dd', 2. ), (3, b'xyz', 3. ),
           (4, b'12', 4. )],
          dtype=[('a', '<i4'), ('b', 'S3'), ('c', '<f4')])
Nz>mismatch between the number of fields and the number of arrayszarray-shape mismatch in array z ("z"))r   Zasarrayrw   rc   r   rq   r   r   r   r#   r   r   r   Zndim)Z	arrayListr   rc   r   r   r   r   r   ZxrM   re   r*   Zd0Znn_arraykZ	testshaperT   s   &&&&&&&&          r   
fromarraysrz   9  sy   b )22	1A	I2 'u-E}!""	E3		5= )22	99	2gfyIOO[[F 5zS^# + , 	, 
qB	RB	Avdse#F I&X]]IInsxx"}-	y=aSD6LMMt ' MW 3 3s   F	.Fc           
     s   Vf   Vf   \         P                  ! V \        R7      p\        VP                  R,          4       U	u. uF0  p	\         P                  ! VRV	3,          P                  4       4      NK2  	  p
p	\        WW$WVVR7      # Ve   \         P                  ! \        V34      pM\        W4WVV4      P                  p \         P                  ! WR7      pVe   VP                  V8w  d   W,n        TP-                  \         4      pT# u up	i   \        \        3 d    \        T4      pTf   \        T 4      p\        T\        4      '       d   T3p\        T4      ^8  d   \        R4      h\!        Y+4      p\        TP"                  4       F  p\%        Y,          4      Y&   K  	  \&        P(                  ! R\*        ^R7       Tu # i ; i)av  Create a recarray from a list of records in text form.

Parameters
----------
recList : sequence
    data in the same field may be heterogeneous - they will be promoted
    to the highest data type.
dtype : data-type, optional
    valid dtype for all arrays
shape : int or tuple of ints, optional
    shape of each array.
formats, names, titles, aligned, byteorder :
    If `dtype` is ``None``, these arguments are passed to
    `numpy.format_parser` to construct a dtype. See that function for
    detailed documentation.

    If both `formats` and `dtype` are None, then this will auto-detect
    formats. Use list of tuples rather than list of lists for faster
    processing.

Returns
-------
np.recarray
    record array consisting of given recList rows.

Examples
--------
>>> r=np.rec.fromrecords([(456,'dbe',1.2),(2,'de',1.3)],
... names='col1,col2,col3')
>>> print(r[0])
(456, 'dbe', 1.2)
>>> r.col1
array([456,   2])
>>> r.col2
array(['dbe', 'de'], dtype='<U3')
>>> import pickle
>>> pickle.loads(pickle.dumps(r))
rec.array([(456, 'dbe', 1.2), (  2, 'de', 1.3)],
          dtype=[('col1', '<i8'), ('col2', '<U3'), ('col3', '<f8')])
rg   .)r   rc   r   r   r   r   zCan only deal with 1-d array.zxfromrecords expected a list of tuples, may have received a list of lists instead. In the future that will raise an errorrs   )r   arrayrh   r+   rc   Ztolistrz   r   r   r   ri   r   rw   r#   r   rq   r   rp   r'   rt   ru   rv   rI   )ZrecListr   rc   r   r   r   r   r   rM   r
   Zarrlistre   Zretvalrx   ry   rL   s   &&&&&&&&        r   fromrecordsr}     s   X 5=hhwf-49#))B-4H
4HqBHHSa['')*4H 	 
 '%!'IO 	O &%)FY

% 	!'/* !6 L
++h
CJQ
 z" *51=LEeS!!HEu:><==%'v{{#Agj)FI $ 	Ga	) %s   6DD B8GGc	                s   Vf   Vf   \        R4      hVe   \        P                  ! V4      p	M\        WEWgV4      P                  p	V	P                  p
\        V4      pVR9   d   \        V 4      V,
          V
,          p\        W)WR7      pV# )a0  Create a record array from binary data

Note that despite the name of this function it does not accept `str`
instances.

Parameters
----------
datastring : bytes-like
    Buffer of binary data
dtype : data-type, optional
    Valid dtype for all arrays
shape : int or tuple of ints, optional
    Shape of each array.
offset : int, optional
    Position in the buffer to start reading from.
formats, names, titles, aligned, byteorder :
    If `dtype` is ``None``, these arguments are passed to
    `numpy.format_parser` to construct a dtype. See that function for
    detailed documentation.


Returns
-------
np.recarray
    Record array view into the data in datastring. This will be readonly
    if `datastring` is readonly.

See Also
--------
numpy.frombuffer

Examples
--------
>>> a = b'\x01\x02\x03abc'
>>> np.rec.fromstring(a, dtype='u1,u1,u1,S3')
rec.array([(1, 2, 3, b'abc')],
        dtype=[('f0', 'u1'), ('f1', 'u1'), ('f2', 'u1'), ('f3', 'S3')])

>>> grades_dtype = [('Name', (np.str_, 10)), ('Marks', np.float64),
...                 ('GradeLevel', np.int32)]
>>> grades_array = np.array([('Sam', 33.3, 3), ('Mike', 44.4, 5),
...                         ('Aadi', 66.6, 6)], dtype=grades_dtype)
>>> np.rec.fromstring(grades_array.tobytes(), dtype=grades_dtype)
rec.array([('Sam', 33.3, 3), ('Mike', 44.4, 5), ('Aadi', 66.6, 6)],
        dtype=[('Name', '<U10'), ('Marks', '<f8'), ('GradeLevel', '<i4')])

>>> s = '\x01\x02\x03abc'
>>> np.rec.fromstring(s, dtype='u1,u1,u1,S3')
Traceback (most recent call last):
   ...
TypeError: a bytes-like object is required, not 'str'
z2fromstring() needs a 'dtype' or 'formats' argument)rd   r_   )Nr{   )ri   r   r   r   itemsizerw   r#   r   )Z
datastringr   rc   r_   r   r   r   r   r   re   r~   rx   s   &&&&&&&&&   r   
fromstringr     s    p }LMMgfyIOO~~H 'u-E
Z6)h6e
BFMr   c                 s    V P                  4       p V P                  ^ ^4       V P                  4       V,
          V P                  V^ 4       #   T P                  T^ 4       i ; irn   )Ztellseek)fdZposrU   r   get_remaining_sizer   <  sG    
'')C
1wwy3
QQs   (A A!c	           	     s   Vf   Vf   \        R4      h\        V4      pVf   R	pM\        V\        4      '       d   V3p\	        V R4      '       d   \        V 4      p	M \        \        P                  ! V 4      R4      p	T	;_uu_ 4       p V^ 8  d   V P                  V^4       \        V 4      p
Ve   \        P                  ! V4      pM\        WEWgV4      P                  pVP                  p\        P                  ! V4      P!                  \"        P$                  R7      pW,          pV^ 8  de   \'        V4      pW) ,          W"P)                  R4      &   \+        V4      p\        P                  ! V4      P!                  \"        P$                  R7      pW,          pW8  d   \-        R4      h\/        W+4      pV P1                  VP2                  4      pVV8w  d   \5        R4      h RRR4       V#   + '       g   i     X# ; i)
ah  Create an array from binary file data

Parameters
----------
fd : str or file type
    If file is a string or a path-like object then that file is opened,
    else it is assumed to be a file object. The file object must
    support random access (i.e. it must have tell and seek methods).
dtype : data-type, optional
    valid dtype for all arrays
shape : int or tuple of ints, optional
    shape of each array.
offset : int, optional
    Position in the file to start reading from.
formats, names, titles, aligned, byteorder :
    If `dtype` is ``None``, these arguments are passed to
    `numpy.format_parser` to construct a dtype. See that function for
    detailed documentation

Returns
-------
np.recarray
    record array consisting of data enclosed in file.

Examples
--------
>>> from tempfile import TemporaryFile
>>> a = np.empty(10,dtype='f8,i4,a5')
>>> a[5] = (0.5,10,'abcde')
>>>
>>> fd=TemporaryFile()
>>> a = a.view(a.dtype.newbyteorder('<'))
>>> a.tofile(fd)
>>>
>>> _ = fd.seek(0)
>>> r=np.rec.fromfile(fd, formats='f8,i4,a5', shape=10,
... byteorder='<')
>>> print(r[5])
(0.5, 10, b'abcde')
>>> r.shape
(10,)
Nz0fromfile() needs a 'dtype' or 'formats' argumentreadintoZrbrg   z;Not enough bytes left in file for specified shape and type.z%Didn't read as many bytes as expectedr{   )r{   )ri   rw   r   rq   hasattrr   ZopenosZfspathr   r   r   r   r   r~   r|   ZprodrD   Zintpr   Zindexr'   r   r   r   ZdataZOSError)r   r   rc   r_   r   r   r   r   r   Zctxrp   re   r~   Z	shapeprodZ	shapesizeZnbytesrx   Z
nbytesreads   &&&&&&&&&         r   fromfiler   E  s   \ }JKK 'u-E}	E3		r: "o 299R=$'	A:GGFA!"%HHUOE!e  >>HHUO((rww(7	(	q=KE%)Z%7E++b/"%LE,,277,;I%=&  %'[[-
ABB  C 
H MI 
H Ms   EG--G>	c           
     s2   \        V \        R4      \        34      '       g   \        V R4      '       d   Vf   Vf   \	        R4      h/ pVe   \
        P                  ! V4      pM(Ve   \        WVVW4      P                  pMRVRVRVRVRV	/pV f   Vf   \	        R	4      h\        W!WVR
7      # \        V \        4      '       d   \        W3RVRV/VB # \        V \        \        34      '       dD   \        V ^ ,          \        \        34      '       d   \        V 3RVRV/VB # \        V 3RVRV/VB # \        V \        4      '       dD   Ve$   V P                  V8w  d   V P                  V4      pMT pV
'       d   VP!                  4       pV# \        V R4      '       d   \#        WW#R7      # \        V \$        4      '       dW   Ve$   V P                  V8w  d   V P                  V4      pMT pV
'       d   VP!                  4       pVP                  \        4      # \'        V RR4      pVe   \        V\(        4      '       g   \	        R4      h\
        P*                  ! V 4      p Ve#   V P                  V8w  d   V P                  V4      p V P                  \        4      # )az	  
Construct a record array from a wide-variety of objects.

A general-purpose record array constructor that dispatches to the
appropriate `recarray` creation function based on the inputs (see Notes).

Parameters
----------
obj : any
    Input object. See Notes for details on how various input types are
    treated.
dtype : data-type, optional
    Valid dtype for array.
shape : int or tuple of ints, optional
    Shape of each array.
offset : int, optional
    Position in the file or buffer to start reading from.
strides : tuple of ints, optional
    Buffer (`buf`) is interpreted according to these strides (strides
    define how many bytes each array element, row, column, etc.
    occupy in memory).
formats, names, titles, aligned, byteorder :
    If `dtype` is ``None``, these arguments are passed to
    `numpy.format_parser` to construct a dtype. See that function for
    detailed documentation.
copy : bool, optional
    Whether to copy the input object (True), or to use a reference instead.
    This option only applies when the input is an ndarray or recarray.
    Defaults to True.

Returns
-------
np.recarray
    Record array created from the specified object.

Notes
-----
If `obj` is ``None``, then call the `~numpy.recarray` constructor. If
`obj` is a string, then call the `fromstring` constructor. If `obj` is a
list or a tuple, then if the first object is an `~numpy.ndarray`, call
`fromarrays`, otherwise call `fromrecords`. If `obj` is a
`~numpy.recarray`, then make a copy of the data in the recarray
(if ``copy=True``) and use the new formats, names, and titles. If `obj`
is a file, then call `fromfile`. Finally, if obj is an `ndarray`, then
return ``obj.view(recarray)``, making a copy of the data if ``copy=True``.

Examples
--------
>>> a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> a
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

>>> np.rec.array(a)
rec.array([[1, 2, 3],
           [4, 5, 6],
           [7, 8, 9]],
          dtype=int64)

>>> b = [(1, 1), (2, 4), (3, 9)]
>>> c = np.rec.array(b, formats = ['i2', 'f2'], names = ('x', 'y'))
>>> c
rec.array([(1, 1.), (2, 4.), (3, 9.)],
          dtype=[('x', '<i2'), ('y', '<f2')])

>>> c.x
array([1, 2, 3], dtype=int16)

>>> c.y
array([1.,  4.,  9.], dtype=float16)

>>> r = np.rec.array(['abc','def'], names=['col1','col2'])
>>> print(r.col1)
abc

>>> r.col1
array('abc', dtype='<U3')

>>> r.col2
array('def', dtype='<U3')
Nr   zIMust define formats (or dtype) if object is None, string, or an open filer   r   r   r   r   z"Must define a shape if obj is None)rd   r_   r`   rc   r_   r   )r   rc   r_   Z__array_interface__zUnknown input type)r   r&   r(   r   r   r   r   r   r   Zbytesr   r   r'   r}   rz   rI   copyr   ra   rO   Zdictr|   )rM   r   rc   r_   r`   r   r   r   r   r   r   ZkwdsZnewZ	interfaces   &&&&&&&&&&&   r   r|   r|     sX   l 
C$t*c*	+	+wsJ/G/G?u} 9 : 	: D		gf%227% 	 7&7Y	 {=ABB#gNN	C		#IEI&IDII	C$	'	'c!fudm,,sE%EuEEEcDDeDtDD	C	"	"#))u"4((5/CC((*C
	j	!	!EE	C	!	!#))u"4((5/CC((*Cxx!! C!6=	Jy$$?$?122hhsm#))u"4((5/Cxx!!r   )	r   r   r   rz   r}   r   r   r|   r   )NNNNNFN)NNro   NNNFN)
NNro   NNNNFNT)!r3   r   rt   Zcollectionsr    Z
contextlibr   Znumpy._utilsr   Z r   r   r   rD   Z
arrayprintr   Z__all__ra   r-   Z
sctypeDictZnumfmtr   r   rE   r   r   rw   rz   r}   r   r   r   r|   rZ   r   r   <module>r      s   
   " #    . **ssssssssssssss( 
 K  KH H HVHRWW Hf KQ,w Q, Q,h	 K[ [| KU Up KH HT Ke eP KR" R"r   