HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/numpy/core/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/numpy/core/__pycache__/records.cpython-36.pyc
3

���h��@s8dZddlZddlZddlmZmZddlmZddlm	Z
ddlmZm
Z
mZddlmZdd	lmZd
ddgZejZd
ddd
ddddd
dddddd�Ze
jZGdd�dee�Zdd�Zed�Gdd�d��ZGdd
�d
e
j�ZGdd�de�Zdd�Zd+dd�Zd,d d!�Z d-d"d#�Z!d$d%�Z"d.d&d'�Z#d/d)d*�Z$dS)0a�
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�OrderedDict�)�numeric)�numerictypes)�	isfileobj�	os_fspath�contextlib_nullcontext)�
set_module)�get_printoptions�record�recarray�
format_parser�>�<�=�s�|)�b�l�n�B�L�N�Srrrrr�I�ic@s eZdZdZdd�Zdd�ZdS)�_OrderedCounterz?Counter that remembers the order elements are first encounteredcCsd|jjt|�fS)Nz%s(%r))�	__class__�__name__r)�self�r!�3/tmp/pip-build-5_djhm0z/numpy/numpy/core/records.py�__repr__Qsz_OrderedCounter.__repr__cCs|jt|�ffS)N)rr)r r!r!r"�
__reduce__Tsz_OrderedCounter.__reduce__N)r�
__module__�__qualname__�__doc__r#r$r!r!r!r"rNsrcCsdd�t|�j�D�S)z@Find duplication in a list, return a list of duplicated elementscSsg|]\}}|dkr|�qS)rr!)�.0�item�countsr!r!r"�
<listcomp>[sz"find_duplicate.<locals>.<listcomp>)r�items)�listr!r!r"�find_duplicateXsr.�numpyc@s4eZdZdZddd�Zd
dd�Zdd	�Zd
d�ZdS)ra�
    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')])

    FNcCs&|j||�|j||�|j|�dS)N)�
_parseFormats�_setfieldnames�_createdtype)r �formats�names�titles�aligned�	byteorderr!r!r"�__init__�szformat_parser.__init__cs�|dkrtd��t|t�r6tjdd�t|�D�|�}ntj||�}|j��dkrhtjd|fg|�}|j�|j}�fdd�|D�|_�fdd�|D�|_	t
|�|_dS)z Parse the field formats NzNeed formats argumentcSsg|]\}}dj|�|f�qS)zf{})�format)r(rZformat_r!r!r"r+�sz/format_parser._parseFormats.<locals>.<listcomp>�f1csg|]}�|d�qS)rr!)r(�key)�fieldsr!r"r+�scsg|]}�|d�qS)rr!)r(r;)r<r!r"r+�s)�
ValueError�
isinstancer-�sb�dtype�	enumerater<r4�
_f_formats�_offsets�len�_nfields)r r3r6r@�keysr!)r<r"r0�s
zformat_parser._parseFormatscCs�|rXt|�ttgkrn&t|t�r,|jd�}ntdt|���dd�|d|j�D�|_	ng|_	|j	dd�t
t|j	�|j�D�7_	t|j	�}|r�t
d|��|r�dd�|d|j�D�|_n
g|_g}|jt|�kr�|jdg|jt|�7_dS)	zQconvert input field names into a list and assign to the _names
        attribute �,zillegal input names %scSsg|]}|j��qSr!)�strip)r(rr!r!r"r+�sz0format_parser._setfieldnames.<locals>.<listcomp>NcSsg|]}d|�qS)zf%dr!)r(rr!r!r"r+�szDuplicate field names: %scSsg|]}|j��qSr!)rH)r(rr!r!r"r+�s)�typer-�tupler>�str�split�	NameError�reprrE�_names�rangerDr.r=�_titles)r r4r5Z_dupr!r!r"r1�s&

zformat_parser._setfieldnamescCsDtj|j|j|j|jd��}|dk	r:t|d}|j|�}||_dS)N)r4r3�offsetsr5r)r?r@rOrBrCrQ�_byteorderconvZnewbyteorder)r r7r@r!r!r"r2�s
zformat_parser._createdtype)FN)F)rr%r&r'r8r0r1r2r!r!r!r"ras
:

$csTeZdZdZdZdZ�fdd�Z�fdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)rzEA data-type scalar that allows field access as attribute lookup.
    r/cs$t�ddkr|j�Stt|�j�S)N�legacyz1.13)r�__str__�superrr#)r )rr!r"r#�szrecord.__repr__cs(t�ddkrt|j��Stt|�j�S)NrTz1.13)rrKr)rVrrU)r )rr!r"rU�szrecord.__str__cCs�|dkrtjj||�Sytjj||�Stk
r8YnXtjj|d�j}|j|d�}|r�|j|dd��}y
|j}Wntk
r�|SX|jdk	r�|j	|j
|jf�S|Std|��dS)N�setfield�getfieldr@�z%'record' object has no attribute '%s')rWrXr@)�nt�void�__getattribute__�AttributeErrorr<�getrXr@r4�viewr)r �attr�	fielddict�res�obj�dtr!r!r"r\�s&

zrecord.__getattribute__cCsx|dkrtd|��tjj|d�j}|j|d�}|rL|j|f|dd���St||d�rhtjj|||�Std|��dS)NrWrXr@zCannot set '%s' attributerYz%'record' object has no attribute '%s')rWrXr@)	r]rZr[r\r<r^rW�getattr�__setattr__)r r`�valrarbr!r!r"rfszrecord.__setattr__cCs@tjj||�}t|tj�r8|jjdk	r8|j|j|jf�S|SdS)N)rZr[�__getitem__r>r@r4r_r)r �indxrcr!r!r"rh#szrecord.__getitem__cs@�jj}tdd�|D��}d|���fdd�|D�}dj|�S)zPretty-print all fields.css|]}t|�VqdS)N)rD)r(�namer!r!r"�	<genexpr>1sz record.pprint.<locals>.<genexpr>z%% %ds: %%scsg|]}�|t�|�f�qSr!)re)r(rj)�fmtr r!r"r+3sz!record.pprint.<locals>.<listcomp>�
)r@r4�max�join)r r4�maxlenZrowsr!)rlr r"�pprint-s
z
record.pprint)rr%r&r'r#rUr\rfrhrq�
__classcell__r!r!)rr"r�s
c
s\eZdZdZdZdZddd�Zd	d
�Zdd�Zd
d�Z�fdd�Zdd�Z	ddd�Z
�ZS)r
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
    --------
    rec.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/NrF�Cc	Csf|dk	rtj|�}nt||||
|	�j}|dkrFtj||t|f|d�}
ntj||t|f||||d�}
|
S)N)�order)�buffer�offset�stridesrt)r?r@r�ndarray�__new__r)�subtype�shaper@�bufrvrwr3r4r5r7r6rt�descrr r!r!r"ry�s
zrecarray.__new__cCs$|jjtk	r |jjdk	r |j|_dS)N)r@rIrr4)r rcr!r!r"�__array_finalize__�szrecarray.__array_finalize__cCs�ytj||�Stk
r YnXtj|d�j}y||dd�}Wn$ttfk
rhtd|��YnX|j|�}|jj	dk	r�t
|jjtj
�r�|j|jj|jfd�S|S|jt�SdS)Nr@rYzrecarray has no attribute %s)r@)�objectr\r]rxr<�	TypeError�KeyErrorrXr@r4�
issubclassrIrZr[r_)r r`rarbrcr!r!r"r\�s
zrecarray.__getattribute__cCs|dkr.t|jtj�r.|jdk	r.tjt|f�}||jk}yt	j
|||�}Wn0tk
rztj
|d�jpji}||krv�YnJXtj
|d�jp�i}||kr�|S|r�yt	j||�Wntk
r�|SXy||dd�}Wn&ttfk
�r�td|��YnX|j|f|��S)Nr@rYz record array has no attribute %s)r�rIrZr[r4r?r@r�__dict__rrf�	Exceptionrxr\r<�__delattr__r�r�r]rW)r r`rgZnewattr�retrarbr!r!r"rf�s, 
zrecarray.__setattr__csttt|�j|�}t|t�rl|jjdk	r^|jt|��}t	|jjt
j�rZ|j|jj|jfd�S|S|jtd�Sn|SdS)N)r@)rI)rVr
rhr>rxr@r4r_rIr�rZr[)r rirc)rr!r"rhs
zrecarray.__getitem__cCs�|j}|jjtks$t|jjtj�rH|jtkr>tjtj|f�}d}d}nd}d}|jdksd|jdkrxtj	|d|dd�}nd	t
|j�f}d
dt|�}t�dd
kr�d|}||||fS)Nz
rec.array(zrec.array(%s,%sdtype=%s)zarray(z)array(%s,%sdtype=%s).view(numpy.recarray)rz, rG)�	separator�prefix�suffixz[], shape=%srm� rTz1.13)r)
r@rIrr�rZr[r?�sizer{Zarray2stringrNrDr)r Z
repr_dtyper�rl�lst�lfr!r!r"r#s 
zrecarray.__repr__cCs~t|t�r tj|d�j}||}tj|d�j}||dd�}|dkrj|j|�}|jjdk	r`|S|jt�S|j	|f|��SdS)Nr@rY)
r>�intrxr\r4r<rXr@r_rW)r r`rgr4rarbrcr!r!r"�field6s


zrecarray.field)
NNrNNNNNFrs)N)rr%r&r'ryr~r\rfrhr#r�rrr!r!)rr"r
>sg
"!cCs$|dkrtjdtdd�dS|SdS)Nrz�Passing `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{r!r!r"�_deprecate_shape_0_as_NoneHs
r�FcCsBdd�|D�}t|�}|dkr*|dj}nt|t�r:|f}|dkrX|dkrXdd�|D�}|dk	rltj|�}nt|||||�j}|j}	t|�t|�kr�t	d��|dj}
t|
�}|dkr�|d|�}xFt
|�D]:\}}
||j}|
jd|
j|�}||kr�t	d|��q�Wt||�}x&t
t|��D]}||||	|<�q$W|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.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')])
    cSsg|]}tj|��qSr!)r?Zasarray)r(�xr!r!r"r+�szfromarrays.<locals>.<listcomp>NrcSsg|]
}|j�qSr!)r@)r(rcr!r!r"r+�sz>mismatch between the number of fields and the number of arraysz array-shape mismatch in array %d)r�r{r>r�r?r@rr4rDr=rA�ndimr
rP)Z	arrayListr@r{r3r4r5r6r7r}rOZd0�nn�krcZ	testshape�_arrayrr!r!r"�
fromarraysTs60



r�csL|dkrP|dkrPtj|td���fdd�t�jd�D�}t|||||||d�S|dk	rhtjt|f�}	nt|||||�j}	ytj||	d�}
Wn�t	t
fk
�r t|�}|dkr�t|�}t
|t�r�|f}t|�dkr�t
d��t||	�}x"t|j�D]}t||�||<q�Wtjdtd	d
�|SX|dk	�r>|
j|k�r>||
_|
jt�}
|
S)aCreate 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')])
    N)r@cs"g|]}tj�d|fj���qS).)r?�array�tolist)r(r)rcr!r"r+�szfromrecords.<locals>.<listcomp>r)r3r{r4r5r6r7zCan 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 errorrY)r����)r?r�rrPr{r�r@rrr�r=r�rDr>r�r
r�rJr�r�r�r_)ZrecListr@r{r3r4r5r6r7Zarrlistr}�retvalr�r�rbr!)rcr"�fromrecords�s:+




r�c	Csx|dkr|dkrtd��|dk	r,tj|�}	nt|||||�j}	|	j}
t|�}|dkrdt|�||
}t||	||d�}|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.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'
    Nz2fromstring() needs a 'dtype' or 'formats' argumentr)r|rvr�)Nr�)r�r?r@r�itemsizer�rDr
)Z
datastringr@r{rvr3r4r5r6r7r}r�r�r!r!r"�
fromstrings7r�cCsPy|j�}Wn&tk
r2tjj|j�|j�SXtj|�}|j|j�}|S)N)	�filenor]�os�path�getsizerj�tell�fstat�st_size)�fd�fn�str�r!r!r"�get_remaining_sizeOs
r�c	
CsZ|dkr|dkrtd��t|�}|dkr.d
}nt|t�r>|f}t|�rPt|�}	ntt|�d�}	|	��}|dkrx|j|d�t	|�}
|dk	r�t
j|�}nt|||||�j}|j
}t
j|�jtjd�}
|
|}|dk�r
t|�}|
|||jd�<t|�}t
j|�jtjd�}
|
|}||
k�r$td��t||�}|j|j�}||k�rLtd��WdQRX|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.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' argumentr�rbr)r@z:Not enough bytes left in file for specified shape and typez%Didn't read as many bytes as expectedr�)r�r�)r�r�r>r�rr	�openr�seekr�r?r@rr�r��prodrZZintpr-�indexrJr=r
�readinto�data�IOError)r�r@r{rvr3r4r5r6r7�ctxr�r}r�Z	shapeprodZ	shapesize�nbytesr�Z
nbytesreadr!r!r"�fromfileXsD-





r�TcCs"t|td�tf�st|�r2|dkr2|dkr2td��i}|dk	rJtj|�}n,|dk	rft|||||	�j}n|||||	d�}|dkr�|dkr�td��t|||||d�St|t	�r�t
||f||d�|��St|ttf��rt|dttf��r�t
|f||d�|��St|f||d�|��S�nt|t��rZ|dk	�rD|j|k�rD|j|�}n|}|
�rV|j�}|St|��rtt||||d	�St|t��r�|dk	�r�|j|k�r�|j|�}n|}|
�r�|j�}|jt�St|d
d�}
|
dk�s�t|
t��r�td��tj|�}|dk	�r|j|k�r|j|�}|jt�SdS)z=Construct a record array from a wide-variety of objects.
    NzIMust define formats (or dtype) if object is None, string, or an open file)r3r4r5r6r7z"Must define a shape if obj is None)r|rvrw)r{rvr)r@r{)r@r{rvZ__array_interface__zUnknown input type)r>rIrKrr=r?r@rr
�bytesr�r-rJr�r�r_�copyr�rxre�dictr�)rcr@r{rvrwr3r4r5r6r7r��kwds�newZ	interfacer!r!r"r��s^




r�)NNNNNFN)NNNNNFN)NNrNNNFN)NNrNNNFN)
NNrNNNNFNT)%r'r�r��collectionsrr�rr?rrZZnumpy.compatrrr	Znumpy.core.overridesr
Z
arrayprintr�__all__rxrSZtypeDictZnumfmtrr.rr[rr
r�r�r�r�r�r�r�r!r!r!r"�<module>#sZ

		U
\
S
I	
`