
    h                        S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SS	KJr  SS
KJr  SSKJr  / SQr\
R$                  rSSSSSSSSSSSSSSS.r\R(                  rS r\" S5       " S S5      5       r " S S\R0                  5      r " S S\5      rS r\" S5        S#S j5       r\" S5        S#S j5       r\" S5        S$S j5       rS  r\" S5        S$S! j5       r \" S5        S%S" j5       r!g)&a  
Record Arrays
=============
Record arrays expose the fields of structured arrays as properties.

Most commonly, ndarrays contain elements of a single type, e.g. floats,
integers, bools etc.  However, it is possible for elements to be combinations
of these using structured types, such as::

  >>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', np.int64), ('y', np.float64)])
  >>> a
  array([(1, 2.), (1, 2.)], dtype=[('x', '<i8'), ('y', '<f8')])

Here, each element consists of two fields: x (and int), and y (a float).
This is known as a structured array.  The different fields are analogous
to columns in a spread-sheet.  The different fields can be accessed as
one would a dictionary::

  >>> a['x']
  array([1, 1])

  >>> a['y']
  array([2., 2.])

Record arrays allow us to access fields as properties::

  >>> ar = np.rec.array(a)

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

  >>> ar.y
  array([2., 2.])

    N)Counter)nullcontext   )
set_module   )numeric)numerictypes)	os_fspath)_get_legacy_print_mode)recordrecarrayformat_parser
fromarraysfromrecords
fromstringfromfilearray><=s|)blnBLNSr   r   r   r   r   Iic                 z    [        U 5      R                  5        VVs/ s H  u  pUS:  d  M  UPM     snn$ s  snnf )z@Find duplication in a list, return a list of duplicated elementsr   )r   items)listitemcountss      L/var/www/fran/franai/venv/lib/python3.13/site-packages/numpy/core/records.pyfind_duplicater(   N   s?     $DM//11LDA: 	1  s   77numpyc                   8    \ rS rSrSrS	S jrS
S jrS rS rSr	g)r   W   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, a5'``, or
    a list of format description strings  in the form
    ``['f8', 'i4', 'a5']``.
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
--------
dtype, typename, sctype2char

Examples
--------
>>> np.format_parser(['<f8', '<i4', '<a5'], ['col1', 'col2', 'col3'],
...                  ['T1', 'T2', 'T3']).dtype
dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4'), (('T3', 'col3'), 'S5')])

`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.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'],
...                  []).dtype
dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
>>> np.format_parser(['<f8', '<i4', '<a5'], [], []).dtype
dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])

Nc                 j    U R                  X5        U R                  X#5        U R                  U5        g N)_parseFormats_setfieldnames_createdtype)selfformatsnamestitlesaligned	byteorders         r'   __init__format_parser.__init__   s,    7,E*)$    c           	      :   Uc  [        S5      e[        U[        5      (       aG  [        R                  " [        U5       VVs/ s H  u  p4SR                  U5      U4PM     snnU5      nO[        R                  " X5      nUR                  nUc&  [        R                  " SU4/U5      nUR                  nUR                  nU Vs/ s H
  oU   S   PM     snU l	        U Vs/ s H
  oU   S   PM     snU l
        [        U5      U l        gs  snnf s  snf s  snf )zParse the field formats NzNeed formats argumentzf{}f1r   r   )
ValueError
isinstancer$   sbdtype	enumerateformatfieldsr3   
_f_formats_offsetslen_nfields)	r1   r2   r5   r!   format_r?   rB   keyskeys	            r'   r.   format_parser._parseFormats   s     ?455gt$$HH>G>PQ>P
%,,q/7+>PQE
 HHW.E>HHtUm_g6E\\F{{59:Tc#;q>T:3784CQ48D	 R ;8s   D
D#Dc                 `   U(       a  [        U5      [        [        4;   a  O>[        U[        5      (       a  UR                  S5      nO[        S[        U5      -  5      eUSU R                    Vs/ s H  o3R                  5       PM     snU l
        O/ U l
        U =R                  [        [        U R                  5      U R                  5       Vs/ s H  nSU-  PM
     sn-  sl
        [        U R                  5      nU(       a  [        SU-  5      eU(       a3  USU R                    Vs/ s H  o3R                  5       PM     snU l        O	/ U l        / nU R                  [        U5      :  a0  U =R                  S/U R                  [        U5      -
  -  -  sl        ggs  snf s  snf s  snf )zIconvert input field names into a list and assign to the _names
attribute ,zillegal input names %sNzf%dzDuplicate field names: %s)typer$   tupler=   strsplit	NameErrorreprrF   strip_namesrangerE   r(   r<   _titles)r1   r3   r4   r   r!   _dups         r'   r/   format_parser._setfieldnames   sg    E{tUm+E3''C( 84; FGG.3NT]].CD.C779.CDDKDK 	5T[[1A15,@ A ,@a	 ,@ A 	A dkk*84?@@/5nt}}/EF/E!GGI/EFDLDLF==3v;&LLTFdmmc&k&ABBL '+ EA Gs   1F!F&,F+c                     [         R                  " U R                  U R                  U R                  U R
                  S.5      nUb  [        US      nUR                  U5      nX l        g )N)r3   r2   offsetsr4   r   )r>   r?   rT   rC   rD   rV   _byteorderconvnewbyteorder)r1   r6   r?   s      r'   r0   format_parser._createdtype   s\    [[}}ll	
   &y|4I&&y1E
r9   )rC   rT   rF   rD   rV   r?   )FN)F)
__name__
__module____qualname____firstlineno____doc__r7   r.   r/   r0   __static_attributes__ r9   r'   r   r   W   s    8t%
"*"CHr9   r   c                   X   ^  \ rS rSrSrS r SrU 4S jrU 4S jrS rS rS r	S	 r
S
rU =r$ )r      zEA data-type scalar that allows field access as attribute lookup.
    r)   c                 \   > [        5       S::  a  U R                  5       $ [        TU ]  5       $ Nq   )r   __str__super__repr__r1   	__class__s    r'   rl   record.__repr__   s(    !#s*<<>!w!!r9   c                 n   > [        5       S::  a  [        U R                  5       5      $ [        TU ]  5       $ rh   )r   rO   r%   rk   rj   rm   s    r'   rj   record.__str__   s,    !#s*tyy{##w  r9   c                    US;   a  [         R                  R                  X5      $  [         R                  R                  X5      $ ! [         a     Of = f[         R                  R                  U S5      R                  nUR                  US 5      nU(       ah  U R                  " US S 6 n UR                  nO! [         a    Us $ f = fUR                  b'  UR                  U R                  UR                  45      $ U$ [        SU-  5      e)Nsetfieldgetfieldr?   r?   r   %'record' object has no attribute '%s')ntvoid__getattribute__AttributeErrorrB   getru   r?   r3   viewrn   )r1   attr	fielddictresobjdts         r'   ry   record.__getattribute__   s    4477++D77	77++D77 		GG,,T7;BB	mmD$'--Ra)CYY! 
 xx#xx ;<<J  "%'+", - -s#   A 
AA,B9 9CCc                 Z   US;   a  [        SU-  5      e[        R                  R                  U S5      R                  nUR                  US 5      nU(       a  U R                  " U/US S Q76 $ [        XS 5      (       a   [        R                  R                  XU5      $ [        SU-  5      e)Nrs   zCannot set '%s' attributer?   r   rv   )	rz   rw   rx   ry   rB   r{   rt   getattr__setattr__)r1   r}   valr~   r   s        r'   r   record.__setattr__  s    44 !<t!CDDGG,,T7;BB	mmD$'==/s2Aw//t4((ww**4s;;$ &)+/&0 1 1r9   c                     [         R                  R                  X5      n[        U[         R                  5      (       a>  UR                  R
                  b'  UR                  U R                  UR                  45      $ U$ r-   )rw   rx   __getitem__r=   r?   r3   r|   rn   )r1   indxr   s      r'   r   record.__getitem__  sY    gg!!$- c277##		(C88T^^SYY788 Jr9   c           	          U R                   R                  n[        S U 5       5      nSU-  nU Vs/ s H  oCU[        X5      4-  PM     nnSR	                  U5      $ s  snf )zPretty-print all fields.c              3   8   #    U  H  n[        U5      v   M     g 7fr-   )rE   ).0names     r'   	<genexpr> record.pprint.<locals>.<genexpr>'  s     154SYY5s   z%% %ds: %%s
)r?   r3   maxr   join)r1   r3   maxlenfmtr   rowss         r'   pprintrecord.pprint#  sb     

  1511f$>CDedtWT011eDyy Es   Ard   )r^   r_   r`   ra   rb   rl   rj   ry   r   r   r   rc   __classcell__rn   s   @r'   r   r      s7    
 HJ"
!
-21 r9   r   c                   f   ^  \ rS rSrSrS r Sr   SS jrS rS rS rU 4S jr	S	 r
SS
 jrSrU =r$ )r   i4  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
--------
core.records.fromrecords : Construct a record array from data.
record : fundamental data-type for `recarray`.
format_parser : determine a 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``:

>>> 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')])

r)   c           
          Ub  [         R                  " U5      nO[        XgXU	5      R                  nUc  [        R	                  X[
        U4US9nU$ [        R	                  X[
        U4X4X[S9nU$ )N)order)bufferoffsetstridesr   )r>   r?   r   ndarray__new__r   )subtypeshaper?   bufr   r   r2   r3   r4   r6   r5   r   descrr1   s                 r'   r   recarray.__new__  sz     HHUOE!'&9MSSE;??7FE?%?PD
  ??7FE?-0.5 # DD r9   c                     U R                   R                  [        La*  U R                   R                  b  U R                   U l         g g g r-   )r?   rM   r   r3   )r1   r   s     r'   __array_finalize__recarray.__array_finalize__  s7    ::??&(TZZ-=-=-I DJ .J(r9   c                 ,    [         R                  X5      $ ! [         a     Of = f[        R                  U S5      R                  n X!   S S nO'! [
        [        4 a  n[        SU-  5      UeS nAff = fU R                  " U6 nUR                  R                  bd  [        UR                  R                  [        R                  5      (       a/  UR                  U R                  R                  UR                  4S9$ U$ UR                  [        5      $ )Nr?   r   zrecarray has no attribute %sr?   )objectry   rz   r   rB   	TypeErrorKeyErrorru   r?   r3   
issubclassrM   rw   rx   r|   )r1   r}   r~   r   er   s         r'   ry   recarray.__getattribute__  s    	**466 		 ,,T7;BB		O/"1%C8$ 	O !?$!FGQN	OmmS! 99??&#)).."''22xxtzz		&BxCCJ88G$$s$    
$$A A4 A//A4c                    US:X  aR  [        UR                  [        R                  5      (       a)  UR                  b  [
        R                  " [        U45      nXR                  ;  n [        R                  XU5      n[        R                  U S5      R                  =(       d    0 nX;  a  U$ U(       a   [        R                  X5        O  XQ   S S nU R&                  " U/UQ76 $ ! [         a    Us $ f = f! [         a2    [        R                  U S5      R                  =(       d    0 nX;  a  e  Nhf = f! [         ["        4 a  n[%        SU-  5      UeS nAff = f)Nr?   r   z record array has no attribute %s)r   rM   rw   rx   r3   r>   r?   r   __dict__r   r   r   ry   rB   __delattr__	Exceptionr   r   rz   rt   )r1   r}   r   newattrretr~   r   r   s           r'   r   recarray.__setattr__  sJ    7?z#((BGG<<AV((FC=)Cmm+	$$T5C  00w?FFL"I$
&&t2	 	/"1%C
 }}S'3'' ! J  	00w?FFL"I$ %	" 8$ 	 2T9	s<   (C: 6C( D9 (C76C7:9D65D69E	EEc                   > [         TU ]  U5      n[        U[        5      (       a  UR                  R
                  b~  UR                  [        U 5      5      n[        UR                  R                  [        R                  5      (       a/  UR                  U R                  R                  UR                  4S9$ U$ UR                  [        S9$ U$ )Nr   )rM   )rk   r   r=   r   r?   r3   r|   rM   r   rw   rx   )r1   r   r   rn   s      r'   r   recarray.__getitem__  s    g!$' c7##yy*hhtDz*ciinnbgg66884::??CII*F8GG
xxWx-- Jr9   c                 4   U R                   nU R                   R                  [        L d3  [        U R                   R                  [        R
                  5      (       d>  UR                  [        L a&  [        R                   " [        R
                  U45      nSnSnOSnSnU R                  S:  d  U R                  S:X  a  [        R                  " U SUSS	9nOS
[        U R                  5      < 3nSS[        U5      -  -   n[        5       S::  a  SU-   nX4XQ4-  $ )Nz
rec.array(zrec.array(%s,%sdtype=%s)zarray(z)array(%s,%sdtype=%s).view(numpy.recarray)r   )r   z, rL   )	separatorprefixsuffixz
[], shape=r    ri   )r?   rM   r   r   rw   rx   r>   sizer   array2stringrR   rE   r   )r1   
repr_dtyper   r   lstlfs         r'   rl   recarray.__repr__  s    ZZ
::??f$Jtzz,P,P &(XXrww
&;<
!F,C
 F=C 99q=DJJ$.//VCAC /
 %)$46C#c&k/!!#s*rB2***r9   c                 h   [        U[        5      (       a$  [        R                  U S5      R                  nX1   n[        R                  U S5      R
                  nXA   S S nUc=  U R                  " U6 nUR                  R                  b  U$ UR                  [        5      $ U R                  " U/UQ76 $ )Nr?   r   )
r=   intr   ry   r3   rB   ru   r?   r|   rt   )r1   r}   r   r3   r~   r   r   s          r'   fieldrecarray.field.  s    dC  ,,T7;AAE;D,,T7;BB	obq!;--%Cyy*
88G$$==+s++r9   r   )
NNr   NNNNNFCr-   )r^   r_   r`   ra   rb   r   r   ry   r   r   rl   r   rc   r   r   s   @r'   r   r   4  sJ    fT HJHL1558"$%D(B"+B, ,r9   r   c                 H    U S:X  a  [         R                  " S[        SS9  g U $ )Nr   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.   
stacklevel)warningswarnFutureWarning)r   s    r'   _deprecate_shape_0_as_Noner   @  s,    zN a		)
 r9   z	numpy.recc                    U  Vs/ s H  n[         R                  " U5      PM     n n[        U5      nUc  U S   R                  nO[	        U[
        5      (       a  U4nUc  Uc  U  V	s/ s H  oR                  PM     nn	Ub  [         R                  " U5      n
O[        X4XVU5      R                  n
U
R                  n[        U
5      [        U 5      :w  a  [        S5      eU
S   R                  n[        U5      nUS:  a  USU*  n[        X*5      n[        U 5       HO  u  pX   R                  nU	R                  SU	R                  U-
   nX   nUU:w  a  [        SU SU S35      eXU'   MQ     U$ s  snf s  sn	f )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.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.core.records.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.core.records.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')])
Nr   z>mismatch between the number of fields and the number of arrayszarray-shape mismatch in array z ("z"))r>   asarrayr   r   r=   r   r?   r   r3   rE   r<   r   r@   ndim)	arrayListr?   r   r2   r3   r4   r5   r6   xr   r   rT   d0nn_arrayk	testshaper   s                     r'   r   r   L  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    E/'E4c           
      ^   Ucw  Uct  [         R                  " U [        S9n[        UR                  S   5       V	s/ s H,  n	[         R                  " USU	4   R                  5       5      PM.     n
n	[        XX$XVUS9$ Ub  [         R                  " [        U45      nO[        X4XVU5      R                  n [         R                  " XS9nUb  UR                  U:w  a  X,l        UR-                  [         5      nU$ s  sn	f ! [        [        4 a    [        U5      nUc  [        U 5      n[        U[        5      (       a  U4n[        U5      S:  a  [        S5      e[!        X+5      n[        UR"                  5       H  n[%        X   5      X'   M     [&        R(                  " S[*        SS	9  Us $ f = f)
a  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.core.records.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')])
r   .)r2   r   r3   r4   r5   r6   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 errorr   r   )r>   r   r   rU   r   tolistr   r?   r   r   r   r<   r   rE   r=   r   r   r   rN   r   r   r   r|   )recListr?   r   r2   r3   r4   r5   r6   r   r!   arrlistr   retvalr   r   r   s                   r'   r   r     s   X 5=hhwf-;@2;OP;Oa288CQK..01;OP'%!'IO 	O &%)gfyIOO!'/* !6 L
++h
CJI Q z" *51=LEeS!!HEu:><==%'v{{#Agj)FI $ 	Ga	) %s   3C73C< <B-F,+F,c	                     Uc  Uc  [        S5      eUb  [        R                  " U5      n	O[        XEXgU5      R                  n	U	R                  n
[        U5      nUS;   a  [        U 5      U-
  U
-  n[        X)XS9nU$ )aJ  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.core.records.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.core.records.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.core.records.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)Nr   )r   r   )r   r>   r?   r   itemsizer   rE   r   )
datastringr?   r   r   r2   r3   r4   r5   r6   r   r   r   s               r'   r   r      s    p }LMMgfyIOO~~H 'u-E
Z6)h6e
BFMr9   c                     U R                  5       n U R                  SS5        U R                  5       U-
  U R                  US5        $ ! U R                  US5        f = f)Nr   r   )tellseek)fdposs     r'   get_remaining_sizer   K  sG    
'')C
1wwy3
QQs   $A	 	Ac	                    Uc  Uc  [        S5      e[        U5      nUc  SnO[        U[        5      (       a  U4n[	        U S5      (       a  [        U 5      n	O[        [        U 5      S5      n	U	 n US:  a  U R                  US5        [        U 5      n
Ub  [        R                  " U5      nO[        XEXgU5      R                  nUR                  n[        R                  " U5      R                  [         R"                  S9nX-  nUS:  a]  [%        U5      nX* -  X"R'                  S	5      '   [)        U5      n[        R                  " U5      R                  [         R"                  S9nX-  nX:  a  [+        S
5      e[-        X+5      nU R/                  UR0                  5      nUU:w  a  [3        S5      e SSS5        U$ ! , (       d  f       W$ = f)ab  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.newbyteorder('<')
>>> a.tofile(fd)
>>>
>>> _ = fd.seek(0)
>>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
... byteorder='<')
>>> print(r[5])
(0.5, 10, 'abcde')
>>> r.shape
(10,)
Nz0fromfile() needs a 'dtype' or 'formats' argument)r   readintorbr   r   r   r   z:Not enough bytes left in file for specified shape and typez%Didn't read as many bytes as expected)r   r   r=   r   hasattrr   openr
   r   r   r>   r?   r   r   r   prodrw   intpr$   indexrN   r<   r   r   dataOSError)r   r?   r   r   r2   r3   r4   r5   r6   ctxr   r   r   	shapeprod	shapesizenbytesr   
nbytesreads                     r'   r   r   T  s   \ }JKK 'u-E}	E3		r: "o 9R=$'	A:GGFA!"%HHUOE!'&9MSSE>>HHUO((rww(7	(	q=KE%)Z%7E++b/"%LE,,277,;I%=PR R %'[[-
ABB  ; 
@ MA 
@ Ms   /EF>>
Gc                    [        U [        S5      [        45      (       d  [        U S5      (       a  Uc  Uc  [	        S5      e0 nUb  [
        R                  " U5      nO#Ub  [        XVUX5      R                  nOUUUUU	S.nU c  Uc  [	        S5      e[        X!XUS9$ [        U [        5      (       a  [        X4X#S.UD6$ [        U [        [        45      (       a:  [        U S   [        [        45      (       a  [        U 4XS	.UD6$ [        U 4XS	.UD6$ [        U [        5      (       a@  Ub"  U R                  U:w  a  U R                  U5      nOU nU
(       a  UR!                  5       nU$ [        U S5      (       a
  [#        XX#S
9$ [        U [$        5      (       aS  Ub"  U R                  U:w  a  U R                  U5      nOU nU
(       a  UR!                  5       nUR                  [        5      $ ['        U SS5      nUb  [        U[(        5      (       d  [	        S5      e[
        R*                  " U 5      n Ub!  U R                  U:w  a  U R                  U5      n U R                  [        5      $ )a	  
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]])
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

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

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

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

>>> c.y
rec.array([ 1.0,  4.0,  9.0], 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 file)r2   r3   r4   r5   r6   z"Must define a shape if obj is None)r   r   r   )r   r   r   )r?   r   )r?   r   r   __array_interface__zUnknown input type)r=   rM   rO   r   r<   r>   r?   r   r   bytesr   r$   rN   r   r   r|   copyr   r   r   dictr   )r   r?   r   r   r   r2   r3   r4   r5   r6   r   kwdsnew	interfaces                 r'   r   r     s?   j 
C$t*c*	+	+wsJ/G/G?u} 9 : 	: D		gf%227% 	 # "&	 {=ABB#gNN	C		#IEIDII	C$	'	'c!fudm,,sE%EEEcD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!!r9   )NNNNNFN)NNr   NNNFN)
NNr   NNNNFNT)"rb   r   collectionsr   
contextlibr   _utilsr    r   r>   r	   rw   numpy.compatr
   
arrayprintr   __all__r   r[   
sctypeDictnumfmtr(   r   rx   r   r   r   r   r   r   r   r   r   rd   r9   r'   <module>r     so  "F   "     " . **( 
 GD D DNKRWW KjI,w I,X	 K:>AE[ [| KEI6:Q Qh KEIAEH HT K;??Ca aH KGKGKQ" Q"r9   