
    ٔ jғ                     Z   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
ZmZ ddlmZ g d	Zej        Zd
ddd
ddddd
ddddddZej        Z ed          d             Z ed           G d d                      Z G d dej                  Z ed           G d de                      Zd Z ed          	 	 d!d            Z ed          	 	 d!d            Z ed          	 	 d"d            Zd Z ed          	 	 d"d            Z ed          	 	 d#d             Z dS )$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_parser
fromarraysfromrecords
fromstringfromfilearrayfind_duplicate><=s|)blnBLNSr   r   r   r   r   Iiz	numpy.recc                 X    d t          |                                           D             S )z@Find duplication in a list, return a list of duplicated elementsc                 $    g | ]\  }}|d k    |S r    ).0itemcountss      gC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\numpy/_core/records.py
<listcomp>z"find_duplicate.<locals>.<listcomp>1   s6       D&A:      )r   items)lists    r(   r   r   .   s5     #DMM//11   r*   c                   .    e Zd ZdZddZd	dZd Zd ZdS )
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')])

    FNc                     |                      ||           |                     ||           |                     |           d S N)_parseFormats_setfieldnames_createdtype)selfformatsnamestitlesaligned	byteorders         r(   __init__zformat_parser.__init__u   sH    7G,,,E6***)$$$$$r*   c                    |t          d          t          |t                    r-t          j        d t          |          D             |          }nt          j        ||          }|j        t          j        d|fg|          }|j        |j        }fd|D             | _        fd|D             | _	        t          |          | _        dS )z Parse the field formats NzNeed formats argumentc                 "    g | ]\  }}d | |fS )fr$   )r%   r    format_s      r(   r)   z/format_parser._parseFormats.<locals>.<listcomp>   s7       "7 WWg&  r*   f1c                 ,    g | ]}|         d          S r   r$   r%   keyfieldss     r(   r)   z/format_parser._parseFormats.<locals>.<listcomp>   s!    :::c6#;q>:::r*   c                 ,    g | ]}|         d          S r#   r$   rA   s     r(   r)   z/format_parser._parseFormats.<locals>.<listcomp>   s!    888CQ888r*   )
ValueError
isinstancer,   sbdtype	enumeraterC   r5   
_f_formats_offsetslen_nfields)r3   r4   r7   rH   keysrC   s        @r(   r0   zformat_parser._parseFormatsz   s      	64555gt$$ 		/H &/&8&8    EE HWg..E 	"HtUm_g66E\F{::::T:::88884888D		r*   c                    |rt          |          t          t          fv rnJt          |t                    r|                    d          }nt          dt          |                     d |d| j                 D             | _	        ng | _	        | xj	        d t          t          | j	                  | j                  D             z  c_	        t          | j	                  }|rt          d|           |rd |d| j                 D             | _        n	g | _        g }| j        t          |          k    r+| xj        dg| j        t          |          z
  z  z  c_        dS dS )zQconvert input field names into a list and assign to the _names
        attribute ,zillegal input names c                 6    g | ]}|                                 S r$   stripr%   r   s     r(   r)   z0format_parser._setfieldnames.<locals>.<listcomp>   s     DDD17799DDDr*   Nc                     g | ]}d |z  S )zf%dr$   )r%   r    s     r(   r)   z0format_parser._setfieldnames.<locals>.<listcomp>   s.     A A Aa	 A A Ar*   zDuplicate field names: c                 6    g | ]}|                                 S r$   rR   rT   s     r(   r)   z0format_parser._setfieldnames.<locals>.<listcomp>   s     FFF!AGGIIFFFr*   )typer,   tuplerF   strsplit	NameErrorreprrM   _namesrangerL   r   rE   _titles)r3   r5   r6   _dups       r(   r1   zformat_parser._setfieldnames   s     
	E{{tUm+ FE3'' FC(( DtE{{ D DEEEDDeNT]N.CDDDDKKDK 	 A A5T[1A1A15,@ ,@ A A A 	A dk** 	?=t==>>> 	FFvnt}n/EFFFDLLDLF=3v;;& 	CLLTFdmc&kk&ABBLLLL	C 	Cr*   c                     t          j        | j        | j        | j        | j        d          }|(t          |d                  }|                    |          }|| _        d S )N)r5   r4   offsetsr6   r   )rG   rH   r]   rJ   rK   r_   _byteorderconvnewbyteorder)r3   r8   rH   s      r(   r2   zformat_parser._createdtype   sg    [}l	
 
    	2&y|4I&&y11E


r*   )FN)F)__name__
__module____qualname____doc__r9   r0   r1   r2   r$   r*   r(   r   r   8   si        9 9v% % % %
" " " "0"C "C "CH    r*   r   c                   L     e Zd ZdZd Z dZ fdZ fdZd Zd Zd Zd Z	 xZ
S )	r
   zEA data-type scalar that allows field access as attribute lookup.
    numpyc                     t                      dk    r|                                 S t                                                      S Nq   )r	   __str__super__repr__r3   	__class__s    r(   rp   zrecord.__repr__   s:    !##s* 	"<<>>!ww!!!r*   c                     t                      dk    r!t          |                                           S t                                                      S rl   )r	   rY   r&   ro   rn   rq   s    r(   rn   zrecord.__str__   s@    !##s* 	$tyy{{###ww   r*   c                    |dv r t           j                            | |          S 	 t           j                            | |          S # t          $ r Y nw xY wt           j                            | d          j        }|                    |d           }|rW | j        |d d          }	 |j        }n# t          $ r |cY S w xY w|j        !|	                    | j
        |j        f          S |S t          d| d          )NsetfieldgetfieldrH   rH      "'record' object has no attribute '')ntvoid__getattribute__AttributeErrorrC   getrw   rH   r5   viewrr   )r3   attr	fielddictresobjdts         r(   r}   zrecord.__getattribute__   s)   44 	87++D$777	7++D$777 	 	 	D	G,,T7;;B	mmD$'' 	O$-RaR)CY!   


 x =xx ;<<<J !Md!M!M!MNNNs#   A 
AA&B. .B=<B=c                 `   |dv rt          d| d          t          j                            | d          j        }|                    |d           }|r | j        |g|d d         R  S t          | |d           r!t          j                            | ||          S t          d| d          )Nru   zCannot set 'z' attributerH   rx   ry   rz   )	r~   r{   r|   r}   rC   r   rv   getattr__setattr__)r3   r   valr   r   s        r(   r   zrecord.__setattr__   s    44 	C !A!A!A!ABBBG,,T7;;B	mmD$'' 	O 4=/s2A2w////T4&& 	O7&&tT3777 !Md!M!M!MNNNr*   c                     t           j                            | |          }t          |t           j                  r-|j        j        !|                    | j        |j        f          S |S r/   )r{   r|   __getitem__rF   rH   r5   r   rr   )r3   indxr   s      r(   r   zrecord.__getitem__   s\    g!!$-- c27## 		 	88T^SY7888 Jr*   c                       j         j        }t          d |D                       }d|z   fd|D             }d                    |          S )zPretty-print all fields.c              3   4   K   | ]}t          |          V  d S r/   )rL   )r%   names     r(   	<genexpr>z record.pprint.<locals>.<genexpr>	  s(      114SYY111111r*   z%% %ds: %%sc                 :    g | ]}|t          |          fz  S r$   )r   )r%   r   fmtr3   s     r(   r)   z!record.pprint.<locals>.<listcomp>  s-    DDDdtWT40011DDDr*   
)rH   r5   maxjoin)r3   r5   maxlenrowsr   s   `   @r(   pprintzrecord.pprint  sb     
 11511111f$DDDDDeDDDyyr*   )re   rf   rg   rh   rp   rn   r}   r   r   r   __classcell__rr   s   @r(   r
   r
      s         
 HJ" " " " "
! ! ! ! !
O O O0
O 
O 
O        r*   r
   c                   P     e Zd ZdZ	 	 	 ddZd Zd Zd	 Z fd
Zd Z	ddZ
 xZS )r   aS  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')])

    Nr   FCc           	         |t          j        |          }nt          ||||
|	          j        }|&t                              | |t
          |f|          }n(t                              | |t
          |f||||          }|S )N)order)bufferoffsetstridesr   )rG   rH   r   ndarray__new__r
   )subtypeshaperH   bufr   r   r4   r5   r6   r8   r7   r   descrr3   s                 r(   r   zrecarray.__new__  s      	HUOOEE!    	??u #  DD ??we #  D r*   c                 d    | j         j        t          ur| j         j        | j         | _         d S d S d S r/   )rH   rW   r
   r5   )r3   r   s     r(   __array_finalize__zrecarray.__array_finalize__  sB    :?&( 	$TZ-= 	$ DJJJ	$ 	$ 	$ 	$r*   c                    	 t                               | |          S # t          $ r Y nw xY wt                              | d          j        }	 ||         d d         }n,# t
          t          f$ r}t          d|           |d }~ww xY w | j        | }|j        j	        Mt          |j        j        t          j                  r'|                    | j        j        |j        f          S |S |                    t                    S )NrH   rx   zrecarray has no attribute rH   )objectr}   r~   r   rC   	TypeErrorKeyErrorrw   rH   r5   
issubclassrW   r{   r|   r   )r3   r   r   r   er   s         r(   r}   zrecarray.__getattribute__  s   	**4666 	 	 	D	 ,,T7;;B		MD/"1"%CC8$ 	M 	M 	M !Dd!D!DEE1L	MdmS! 9? 	%#)."'22 Dxxtz	&BxCCCJ88G$$$s$    
**A B0BBc                    |dk    rAt          |j        t          j                  r"|j        t          j        t          |f          }|| j        v}	 t          
                    | ||          }t                              | d          j        pi }||vr|S |r/	 t                              | |           nJ# t          $ r |cY S w xY wn7# t          $ r* t                              | d          j        pi }||vr Y nw xY w	 ||         d d         }n,# t           t"          f$ r}t%          d|           |d }~ww xY w | j        |g|R  S )NrH   rx   zrecord array has no attribute )r   rW   r{   r|   r5   rG   rH   r
   __dict__r   r   r   r}   rC   __delattr__	Exceptionr   r   r~   rv   )r3   r   r   newattrretr   r   r   s           r(   r   zrecarray.__setattr__  s   
 GO	*sx))	* I	*
 (FC=))Cdm+	$$T455C  00w??FL"I9$ 
 &&tT2222    JJJ  	 	 	00w??FL"I9$  		D/"1"%CC8$ 	 	 	 777 	 t}S'3''''s<   C B5 5CC1C<;C< D D:"D55D:c                    t                                          |          }t          |t                    r|j        j        o|                    t          |                     }t          |j        j        t          j
                  r'|                    | j        j        |j        f          S |S |                    t                    S |S )Nr   )rW   )ro   r   rF   r   rH   r5   r   rW   r   r{   r|   )r3   r   r   rr   s      r(   r   zrecarray.__getitem__  s    gg!!$'' c7## 
	y .hhtDzz**cinbg66 H884:?CI*F8GGG
xxWx--- Jr*   c                    | j         }| j         j        t          u s$t          | j         j        t          j                  s3|j        t          u r t          j         t          j        |f          }d}d}nd}d}| j        dk    s| j        dk    rt          j	        | d|d	          }nd
t          | j                   }ddt          |          z  z   }t                      dk    rd|z   }||||fz  S )Nz
rec.array(zrec.array(%s,%sdtype=%s)zarray(z)array(%s,%sdtype=%s).view(numpy.recarray)r   r@   z, rP   )	separatorprefixsuffixz
[], shape=r    rm   )rH   rW   r
   r   r{   r|   rG   sizer   array2stringr\   rL   r	   )r3   
repr_dtyper   r   lstlfs         r(   rp   zrecarray.__repr__  s   Z
JOv%	>4:?BG44	> &( =Xrw
&;<<
!F,CC
 F=C 9q= 	2DJ$. 	2/VCA A ACC 2tDJ//11CC#f++%%!##s* 	rBc2z***r*   c                 `   t          |t                    r(t                              | d          j        }||         }t                              | d          j        }||         d d         }|2 | j        | }|j        j        |S |                    t                    S  | j	        |g|R  S )NrH   rx   )
rF   intr   r}   r5   rC   rw   rH   r   rv   )r3   r   r   r5   r   r   r   s          r(   fieldzrecarray.field  s    dC   	,,T7;;AE;D,,T7;;B	obqb! 	,$-%Cy 
88G$$$ 4=+s++++r*   )
NNr   NNNNNFr   r/   )re   rf   rg   rh   r   r   r}   r   r   rp   r   r   r   s   @r(   r   r     s        g gR IM1558   ,$ $ $% % %D#( #( #(J    ""+ "+ "+H, , , , , , , ,r*   r   c                 N    | dk    rt          j        dt          d           d S | S )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		) 	) 	) 	)
 tr*   Fc                    d | D             } t          |          }|| d         j        }nt          |t                    r|f}||d | D             }|t	          j        |          }nt          |||||          j        }|j        }	t          |          t          |           k    rt          d          |d         j        }
t          |
          }|dk    r|d|          }t          ||          }t          |           D ]R\  }}||         j        }|j        d|j        |z
           }|	|         }||k    rt          d| d| d          |||<   S|S )	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')])
    c                 6    g | ]}t          j        |          S r$   )rG   asarray)r%   xs     r(   r)   zfromarrays.<locals>.<listcomp>i  s     2221A222r*   Nr   c                     g | ]	}|j         
S r$   r   )r%   r   s     r(   r)   zfromarrays.<locals>.<listcomp>v  s    22239222r*   z>mismatch between the number of fields and the number of arrayszarray-shape mismatch in array z ("z"))r   r   rF   r   rG   rH   r   r5   rL   rE   r   rI   ndim)	arrayListrH   r   r4   r5   r6   r7   r8   r   r]   d0nn_arraykr   	testshaper   s                    r(   r   r   8  s   b 32	222I 'u--E !"	E3		  35 3 32	222 PgufgyIIO[F 5zzS^^# , + , , 	, 
qB	RB	Av dsdeU##F I&&  31X]Insx"}n-	ay 	NLaLLDLLLMMMtMr*   c           	      R   |Y|Wt          j        | t                    fdt          j        d                   D             }t          |||||||          S |t          j        t          |f          }	nt          |||||          j        }		 t          j        | |	          }
||
j        |k    r||
_        n# t          t          f$ r t          |          }|t          |           }t          |t                    r|f}t          |          dk    rt          d          t          ||	          }t          |j                  D ]}t#          | |                   ||<   t%          j        dt(          d	
           |cY S w xY w|
                    t                    }|S )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.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')])
    Nr   c                 l    g | ]0}t          j        d |f                                                   1S ).)rG   r   tolist)r%   r    r   s     r(   r)   zfromrecords.<locals>.<listcomp>  sD     
 
 
/0BHSa[''))**
 
 
r*   )r4   r   r5   r6   r7   r8   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 errorrx   r   )rG   r   r   r^   r   r   rH   r
   r   r   rE   r   rL   rF   r   r   r   rX   r   r   r   r   )recListrH   r   r4   r5   r6   r7   r8   arrlistr   retvalr   r   r   r   s                 @r(   r   r     s	   X  O5 Ohwf---
 
 
 
49#)B-4H4H
 
 
 '7%u!'IO O O 	O  &%))UFGY
 

 	!'///*  	!!6 	! FL+ z"   *511 	!LLEeS!! 	HEu::> 	><===%''v{## 	* 	*Agaj))F1II 	Ga	) 	) 	) 	) %. ++h

CJs   B? ?CF
	F
c	                    ||t          d          |t          j        |          }	nt          |||||          j        }	|	j        }
t          |          }|dv rt          |           |z
  |
z  }t          ||	| |          }|S )a  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'
    Nz2fromstring() needs a 'dtype' or 'formats' argument)Nr   )r   r   )r   rG   rH   r   itemsizer   rL   r   )
datastringrH   r   r   r4   r5   r6   r7   r8   r   r   r   s               r(   r   r     s    p  N NLMMM PgufgyIIO~H 'u--E
 7Z6)h6eU
6BBBFMr*   c                     |                                  }	 |                     dd           |                                  |z
  |                     |d           S # |                     |d           w xY w)Nr   rx   )tellseek)fdposs     r(   get_remaining_sizer   ;  s]    
''))C
1wwyy3
QQs   ,A A1c	                    ||t          d          t          |          }|d}nt          |t                    r|f}t	          | d          rt          |           }	n"t          t          j        |           d          }	|	5 } |dk    r| 	                    |d           t          |           }
|t          j        |          }nt          |||||          j        }|j        }t          j        |                              t"          j                  }||z  }|dk     rlt'          |          }|
| z  ||                    d	          <   t+          |          }t          j        |                              t"          j                  }||z  }||
k    rt-          d
          t/          ||          }|                     |j                  }||k    rt5          d          	 ddd           n# 1 swxY w Y   |S )a   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)r   readintorbr   r   r   r   z;Not enough bytes left in file for specified shape and type.z%Didn't read as many bytes as expected)r   r   rF   r   hasattrr   openosfspathr   r   rG   rH   r   r   r   prodr{   intpr,   indexrX   rE   r   r   dataOSError)r   rH   r   r   r4   r5   r6   r7   r8   ctxr   r   r   	shapeprod	shapesizenbytesr   
nbytesreads                     r(   r   r   D  so   \  L LJKKK 'u--E 	E3		 r: ( "oo 29R==$''	 "CA: 	GGFA!"%% 	HUOOEE!   >HUOO((rw(77	(	q= 	<KKE%)iZ%7E%++b//"%LLE,,27,;;IX%D= 	&   %''[[--
 	CABBB	CC"C "C "C "C "C "C "C "C "C "C "C "C "C "C "CH Ms   E$G55G9<G9Tc                 *   t          | t          d          t          f          st          | d          r||t	          d          i }|t          j        |          }n#|t          |||||	          j        }n|||||	d}| %|t	          d          t          ||| ||          S t          | t                    rt          | |f||d|S t          | t          t          f          rBt          | d         t          t          f          rt          | f||d	|S t          | f||d	|S t          | t                    r=|!| j        |k    r|                     |          }n| }|
r|                                }|S t          | d          rt#          | |||
          S t          | t$                    rU|!| j        |k    r|                     |          }n| }|
r|                                }|                    t                    S t'          | dd          }|t          |t(                    st	          d          t          j        |           } | | j        |k    r|                     |          } |                     t                    S )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]])
    >>> 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 file)r4   r5   r6   r7   r8   z"Must define a shape if obj is None)r   r   r   )r   r   r   )rH   r   )rH   r   r   __array_interface__zUnknown input type)rF   rW   rY   r   rE   rG   rH   r   r   bytesr   r,   rX   r   r   r   copyr   r   r   dictr   )r   rH   r   r   r   r4   r5   r6   r7   r8   r   kwdsnew	interfaces                 r(   r   r     s   l 
C$t**c*	+	+ :wsJ/G/G ::$: 9 : : 	: D 	 	guf%y2 227 	 # "&	   *" 	CABBBu#fgNNNN	C		 %"#uIE&IIDIII	C$	'	' ""c!fudm,, 	EsE%uEEEEEcDeDDtDDD	C	"	" " 	#)u"4 	((5//CCC 	((**C
	j	!	! "5fEEEE	C	!	! " 	#)u"4 	((5//CCC 	((**Cxx!!! C!6==	 	3Jy$$?$? 	31222hsmm 	"#)u"4 	"((5//Cxx!!!r*   )NNNNNFN)NNr   NNNFN)
NNr   NNNNFNT)!rh   r   r   collectionsr   
contextlibr   numpy._utilsr    r   rG   r   r{   
arrayprintr	   __all__r   rc   
sctypeDictnumfmtr   r   r|   r
   r   r   r   r   r   r   r   r   r$   r*   r(   <module>r
     s     
			        " " " " " " # # # # # # / / / / / / / / . . . . . .   * ( 
 K   KH H H H H H H HVH H H H HRW H H Hf KQ, Q, Q, Q, Q,w Q, Q, Q,h	 	 	 K:>AE[ [ [ [| KEI6:U U U Up KEIAEH H H HT   K;??Ce e e eP KGKGKR" R" R" R" R" R"r*   