HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/.local/lib/python3.10/site-packages/numpy/ma/__pycache__/mrecords.cpython-310.pyc
o

���g`j�	@s$dZddlmZmZmZmZmZmZmZm	Z	ddlm
Z
ddlZddlZ
ddlmZmZmZmZmZddlmZmZe
jjjZe
jjZgd�Zgd�Zd dd	�Zd
d�Z Gdd
�d
e�Z!dd�Z"e!Z#			d!dd�Zddddddddef	dd�Zdd�Z$dd�Z%		d"e
j&d�dd�Z'd dd�Z(dS)#a,:mod:`numpy.ma..mrecords`

Defines the equivalent of :class:`numpy.recarrays` for masked arrays,
where fields can be accessed as attributes.
Note that :class:`numpy.ma.MaskedArray` already supports structured datatypes
and the masking of individual fields.

.. moduleauthor:: Pierre Gerard-Marchant

�)�MAError�MaskedArray�masked�nomask�masked_array�getdata�getmaskarray�filledN)�bool_�dtype�ndarray�recarray�array)�
fromarrays�fromrecords)�
MaskedRecords�	mrecarrayrr�fromtextfile�addfield)�_data�_mask�
_fieldmaskrc	Cs�t|�}dd�t|�D�}|dur|}n,t|ttf�r|}nt|t�r)|�d�}ntd|����t|�}||kr@|||d�7}g}t|||j	�D](\}}}|t
vrh|dt
vrb|�||df�qI|�|�qI|�||df�qIt�
|�S)z�
    Checks that field names ``descr`` are not reserved keywords.

    If this is the case, a default 'f%i' is substituted.  If the argument
    `names` is not None, updates the field names to valid names.

    cSsg|]}d|�qS)�f%i���.0�irr�D/home/arjun/.local/lib/python3.10/site-packages/numpy/ma/mrecords.py�
<listcomp>6�z_checknames.<locals>.<listcomp>N�,zillegal input names r�)�len�range�
isinstance�tuple�list�str�split�	NameError�zip�descr�reserved_fields�append�npr)	r+�names�ndescr�
default_names�	new_names�nnames�n�d�trrr�_checknames-s(

r7cCs:dd�|jjD�}tj|j|d�}tdgt|��|_|S)NcSsg|]}|df�qS)z|b1r�rr4rrrrPrz"_get_fieldmask.<locals>.<listcomp>�rF)rr/r.�empty�shaper%r"�flat)�self�mdescr�fdmaskrrr�_get_fieldmaskOsr@c@s�eZdZdZdddddddddeddddfdd�Zdd	�Zed
d��Zedd
��Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd,dd�Zdd�Zd d!�Zd"d#�Zd-d$d%�Zd&d'�Zd(d)�Zd*d+�ZdS).ra�

    Attributes
    ----------
    _data : recarray
        Underlying data, as a record array.
    _mask : boolean array
        Mask of the records. A record is masked when all its fields are
        masked.
    _fieldmask : boolean recarray
        Record array of booleans, setting the mask of each individual field
        of each record.
    _fill_value : record
        Filling values for each field.

    NrFTc
stj||||||||||	|
d�}t�|j��|tust�|�s-|s+tdgt	���|_
|Stj||d�}|j|jkrc|j|j}}|dkrMt�
||j�}n||krYt�||j�}n
d}t|||f��|so|�|�d|_|S|j�krw|}ntj�fdd�|D��d	�}||_
|S)
N)	r�buf�offset�strides�formatsr/�titles�	byteorder�alignedF��copyr!z?Mask and data not compatible: data size is %i, mask size is %i.Tc�g|]}t|gt����qSr�r%r"�r�m��mdtyperrr��z)MaskedRecords.__new__.<locals>.<listcomp>r9)r
�__new__�ma�make_mask_descrrrr.�sizer%r"rrr;�resize�reshaper�__setmask__�_sharedmask)�clsr;rrArBrCrDr/rErFrG�mask�	hard_mask�
fill_value�	keep_maskrI�optionsr=�nd�nm�msgrrrNrrQhs<��

��zMaskedRecords.__new__cs�t|dd�}|dur8t|dt�}t�|d�}|tur#tj|j|d�}nt�|��t�fdd�|D��d��	t
�}|j}|j|d�|�
|�|dtkrPt
|d<dS)Nrrr9crJrrKrL�r>rrr�rPz4MaskedRecords.__array_finalize__.<locals>.<listcomp>�r�
_baseclass)�getattrrr�__getattribute__rR�make_mask_noner;rS�narray�viewr
�__dict__�update�_update_from)r=�objr�objmask�_dtype�_dictrrbr�__array_finalize__�s$
��
z MaskedRecords.__array_finalize__cCst�|t�S)z2
        Returns the data as a recarray.

        )rrir
�r=rrrr�szMaskedRecords._datacCs|jS)z!
        Alias to mask.

        rcrrrrrr�szMaskedRecords._fieldmaskcCs|jrt|j�St|j�S)z%
        Returns the length

        )�ndimr"rrrrrrr�__len__�s

zMaskedRecords.__len__c
Cs�zt�||�WStyYnwt�|d�j}z
||dd�}Wnttfy8}ztd|���|�d}~wwt�|d�}t�||d�}|j|�}|j	j
durVtd��d}|�dd�}	|	dur�z|	|}	Wn	t
yqYnwt|	j	�}
|	�t|
r|
fnd	f���}|js�|r�|�t�}t|_d
|_|	|_|�dd�}|dur�z|||_W|Sty�d|_Y|Sw|S|��}|S)Nr��record array has no attribute rjrdz4MaskedRecords is currently limited tosimple records.FrrT�_fill_value)�objectrf�AttributeErrorr�fields�	TypeError�KeyErrorri�getfieldrr/�NotImplementedError�get�
IndexErrorr"�bool�anyr;rrd�_isfieldrrw�
ValueError�item)r=�attr�	fielddict�res�e�
_localdictrrm�	hasmaskedr�tp_lenrwrrrrf�s`�����
�


���zMaskedRecords.__getattribute__c
Cs~|dvr|�|�dSt�|d�}||v}z	t�|||�}Wn#tyAt�|d�jp-i}t�|d�p5i}||vs?||vs?�Yn&wt�|d�jpJi}||vrQ|S|rgzt�||�Wntyf|YSwz
||dd�}Wntt	fy�}	zt
d|���|	�d}	~	ww|tur�|d}
|
dur�|d|}n|}d	}nt|�}t
|�}t�|d
�j|g|�R�}
|d�||�|
S)z<
        Sets the attribute attr to the value val.

        )rZ�	fieldmaskNrjr�_optinforurvrwTrr)rWrxrf�__setattr__�	Exceptionrrz�__delattr__r{r|ryrr	r�setfield�__setitem__)r=r��valr��newattr�retr��optinfor�r�rw�dval�mvalrmrrrr��sX
�������zMaskedRecords.__setattr__cCs�|j}t�|d�}t�||d�}t|t�r<||�t�}|||_d|_|d}|dur2|||_	|j
s:|jr:tS|Stj
||dd��t�}tj
||dd��t�|_|S)z�
        Returns all the fields sharing the same fieldname base.

        The fieldname base is either `_data` or `_mask`.

        rrdTrwNFrH)rjrrfrir$r'rrrXrwrsrr.rrr
)r=�indxr�rrrm�fvalrrr�__getitem__&s 


zMaskedRecords.__getitem__cCs0t�|||�t|t�rt�|�|j|<dSdS)z2
        Sets the given record to value.

        N)rr�r$r'rRrr)r=r��valuerrrr�Fs
�zMaskedRecords.__setitem__csv�jdkr dd�t�fdd��jjD��D�}dd�|��d�Sdd�t�fd	d��jjD��D�}d
d�|��d�S)z8
        Calculates the string representation.

        r!cSs(g|]}dd�dd�|D���d��qS)�(r cS�g|]}t|��qSr�r'rrrrrUr�4MaskedRecords.__str__.<locals>.<listcomp>.<listcomp>�)��join�r�srrrrUs �z)MaskedRecords.__str__.<locals>.<listcomp>c�g|]}t�|��qSr�re�r�frrrrrV��[z, �]cSs"g|]
}d�dd�|D����qS)r cSr�rr�rrrrrYrr�r�r�rrrrYs�cr�rr�r�rrrrrZr�r�r�)rTr*rr/r�)r=�mstrrrrr�__str__Os
��zMaskedRecords.__str__csn�jj}dtdd�|D��df���fdd��jjD�}|�dd�|��d�jfd	g�td
�|��S)z6
        Calculates the repr representation.

        z%%%is : %%scSr�r)r"r8rrrrcrz*MaskedRecords.__repr__.<locals>.<listcomp>�csg|]}�|t�|�f�qSrr�r���fmtr=rrrdrPrzmasked_records(z    fill_valuez              )�
)rr/�max�insert�extendr\r'r�)r=�_names�reprstrrr�r�__repr__]s�zMaskedRecords.__repr__cCs|dur|durt�|�}nWt�||�}nP|dur^zt|t�r&t�||�}nt�||�}Wn7ty]t�|�}|jdurR|jjd}|�	��||�}|�
|�nt�||�}d|_Ynwt�|||�}t|dt
�t
ur�t�|j�}|j�|t�|_|j|j_|S)z3
        Returns a view of the mrecarray.

        Nrr)rri�
issubclassr{r.rrz�	__class__�	__bases__�	__array__rlrwrerrRrSrr;)r=r�type�output�basetyperOrrrrijs2
�


�

zMaskedRecords.viewcC�
d|_dS)z+
        Forces the mask to hard.

        TN��	_hardmaskrrrrr�harden_mask��
zMaskedRecords.harden_maskcCr�)z*
        Forces the mask to soft

        FNr�rrrrr�soften_mask�r�zMaskedRecords.soften_maskcCs$|j���t|��}|j��|_|S)z7
        Returns a copy of the masked record.

        )rrIrir�r)r=�copiedrrrrI�szMaskedRecords.copycCsH|dur|�|���St|����td�}t|j���}d||<|��S)a
        Return the data portion of the array as a list.

        Data items are converted to the nearest compatible Python type.
        Masked values are converted to fill_value. If fill_value is None,
        the corresponding entries in the output list will be ``None``.

        Nr9)r	�tolistrhrxr)r=r\�resultrZrrrr��s	zMaskedRecords.tolistcCs,d|j|j|jj|j��|j��|jf}|S)zWReturn the internal state of the masked array.

        This is for pickling.

        r!)r;r�flags�fncr�tobytesrrw)r=�staterrr�__getstate__�s�zMaskedRecords.__getstate__c
Cs^|\}}}}}}}t�|||||f�tdd�|jjD��}	|jd�||	||f�||_dS)at
        Restore the internal state of the masked array.

        This is for pickling.  ``state`` is typically the output of the
        ``__getstate__`` output, and is a 5-tuple:

        - class name
        - a tuple giving the shape of the data
        - a typecode for the data
        - a binary string for the data
        - a binary string for the mask.

        cSsg|]\}}|tf�qSr�r
)r�k�_rrrr��z.MaskedRecords.__setstate__.<locals>.<listcomp>rN)r�__setstate__rr+rjr\)
r=r��ver�shp�typ�isf�raw�msk�flvrOrrrr��s

zMaskedRecords.__setstate__cCst|j|jddf|��fS)z?
        Return a 3-tuple for pickling a MaskedArray.

        )r�b)�_mrreconstructr�rdr�rrrrr�
__reduce__�s�zMaskedRecords.__reduce__)NN�N)�__name__�
__module__�__qualname__�__doc__rrQrq�propertyrrrtrfr�r�r�r�r�rir�r�rIr�r�r�r�rrrrrVs8
�(

/8 	

(
	rcCs4t�|||��|�}t�t|d�}|j||||d�S)zK
    Build a new MaskedArray from the information stored in a pickle.

    �b1)rZr)rrQri)�subtype�	baseclass�	baseshaper�rrrrrr��sr�Fc	
Cs\dd�|D�}	dd�|D�}
t|	|||||||d��t�}tt|
��|j_|dur,||_|S)a

    Creates a mrecarray from a (flat) list of masked arrays.

    Parameters
    ----------
    arraylist : sequence
        A list of (masked) arrays. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None, integer}, optional
        Number of records. If None, shape is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.

    cSr�r)r�r�xrrrrrzfromarrays.<locals>.<listcomp>cSsg|]	}t�t|���qSr)r.�
atleast_1drr�rrrrs�rr;rDr/rErGrFN)�
recfromarraysrirr&r*rr<r\)�	arraylistrr;rDr/rErGrFr\�datalist�masklist�_arrayrrrr�s��rc


Cs�t|dd�}
t|t�r"t|t�r|���t�}|dur|j}|��}t||||||||d��t	�}|dur8||_
|	turctj
|	dd�}	t|	j�}|rO|	|j_n|	jdkr^dd�|	D�|j_n|�|	�|
durn|
|jdd�<|S)	aN
    Creates a MaskedRecords from a list of records.

    Parameters
    ----------
    reclist : sequence
        A list of records. Each element of the sequence is first converted
        to a masked array if needed. If a 2D array is passed as argument, it is
        processed line by line
    dtype : {None, dtype}, optional
        Data type descriptor.
    shape : {None,int}, optional
        Number of records. If None, ``shape`` is defined from the shape of the
        first array in the list.
    formats : {None, sequence}, optional
        Sequence of formats for each individual field. If None, the formats will
        be autodetected by inspecting the fields and selecting the highest dtype
        possible.
    names : {None, sequence}, optional
        Sequence of the names of each field.
    fill_value : {None, sequence}, optional
        Sequence of data to be used as filling values.
    mask : {nomask, sequence}, optional.
        External mask to apply on the data.

    Notes
    -----
    Lists of tuples should be preferred over lists of lists for faster processing.

    rNr�FrHrucSr�r)r%rLrrrr\rzfromrecords.<locals>.<listcomp>)rer$rrr	rirr��recfromrecordsrr\rr.rr"rr<rsrW)
�reclistrr;rDr/rErGrFr\rZr�mrec�maskrecordlengthrrrr#s4"


��



rcCs�g}t�|�}|jdkr|d}n	|jdkrtd��|D]V}zt|�WnEttfyizt|�Wn+ttfy^zt|�WnttfyS|�|j	�Yn	w|�t�	t��Yn	w|�t�	t��Yqw|�t�	t��q|S)a.
    Tries to guess the dtypes of the str_ ndarray `arr`.

    Guesses by testing element-wise conversion. Returns a list of dtypes.
    The array is first converted to ndarray. If the array is 2D, the test
    is performed on the first line. An exception is raised if the file is
    3D or more.

    rurzThe array should be 2D at most!)
r.�asarrayrsr��intr{�float�complexr-r)�arr�vartypesr�rrr�_guessvartypesds4




�����
r�c
Cszt|d�r|Szt|�}Wnty"}z	td|�d��|�d}~ww|��dd�dkr5|�dd�|S|��td��)	z1
    Opens the file handle of file `fname`.

    �readlinezNo such file: '�'Nruz\xrzWow, binary file)�hasattr�open�FileNotFoundErrorr��seek�closer~)�fnamer�r�rrr�openfile�s
��r�#�)�	delimitorcsZ|tjur�dur
td��tjdtdd�|�t|�}	|��}|d|�����	�}	|	�
��}
t|
�dkr7nq|dur>|
}t��fdd	�|D��}|j
\}}
|��|dur^t|d
�}n&dd	�|D�}t|�|
kr�d}|d
7}tj|t|�|
fdd�t|d
�}dd	�t||�D�}dd	�|D�}|j|k}dd	�t|j|||�D�}t||d�S)a�
    Creates a mrecarray from data stored in the file `filename`.

    Parameters
    ----------
    fname : {file name/handle}
        Handle of an opened file.
    delimiter : {None, string}, optional
        Alphanumeric character used to separate columns in the file.
        If None, any (group of) white spacestring(s) will be used.
    commentchar : {'#', string}, optional
        Alphanumeric character used to mark the start of a comment.
    missingchar : {'', string}, optional
        String indicating missing data, and used to create the masks.
    varnames : {None, sequence}, optional
        Sequence of the variable names. If None, a list will be created from
        the first non empty line of the file.
    vartypes : {None, sequence}, optional
        Sequence of the variables dtypes. If None, it will be estimated from
        the first non-commented line.


    Ultra simple: the varnames are in the header, one lineNz;fromtextfile() got multiple values for argument 'delimiter'zThe 'delimitor' keyword argument of numpy.ma.mrecords.fromtextfile() is deprecated since NumPy 1.22.0, use 'delimiter' instead.ru)�
stacklevelTr!cs2g|]}|d�krt|�dkr|������qS)rr!)r"�stripr()r�line��commentchar�	delimiterrrr�s�z fromtextfile.<locals>.<listcomp>rcS�g|]}t�|��qSr)r.r)r�vrrrr�r�z&Attempting to %i dtypes for %i fields!z Reverting to default.cSsg|]\}}||f�qSrr)rr4r�rrrr�r�cSrr)rR�default_fill_valuer�rrrr�r�cSs$g|]\}}}}t||||d��qS))rZrr\)r)r�arMr6r�rrrr�s
�r9)r.�_NoValuer{�warnings�warn�DeprecationWarningrr��findr	r(r"rr;rr�r*�Tr)rr
r�missingchar�varnamesr�r�ftextr
�	firstline�	_varnames�
_variablesr��nfieldsrar>�mfillvr�	_datalistrrrr�sF
�
�

�rcs|j�|j�|dus|tvrdt�j�}t�|�}t��jj||jfg�}t	�j
|����fdd��jj��D��j
|jg�jj|�R���t��t�dd�|jD��}t	�j
|����fdd��jj��D��j
t|�g�jj|�R���_�S)z�Adds a new field to the masked record array

    Uses `newfield` as data and `newfieldname` as name. If `newfieldname`
    is None, the new field name is set to 'fi', where `i` is the number of
    existing fields.

    Nrc�$g|]}�j�j|�g|�R��qSr�r�r}r�)r�newdatarrr���zaddfield.<locals>.<listcomp>cSsg|]}|tf�qSrr�r8rrrrrcr!rr"r�)r�newmaskrrr	r$)rrr,r"rrRrr.r+r
r;rz�valuesr�rirr/r)�mrecord�newfield�newfieldname�newdtype�	newmdtyper)rrr#r%rr�s,

�

�
�rr�)NNNNNFNN)NrrNN))r��numpy.marrrrrrrr	rRr�numpyr.r
rrr
rrh�numpy.core.recordsrr�rr��core�records�_byteorderconv�_check_fill_value�__all__r,r7r@rr�rr�rrrrrrrr�<module>sF(

"	
�+
�A%��P