
    wg:j              	          d Z ddlmZmZmZmZmZmZmZm	Z	 ddlm
Z
 ddlZddlZddlmZmZmZ ddlmZmZmZ ej0                  j2                  j4                  Ze
j6                  j8                  Zg dZg dZddZd	 Z  G d
 de      Z!d Z"e!Z#	 	 	 ddZddddddddef	dZd Z$d Z%	 	 dejL                  ddZ'ddZ(y)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)dtypendarrayarray)recarray
fromarraysfromrecords)MaskedRecords	mrecarrayr   r   fromtextfileaddfield)_data_mask
_fieldmaskr   c                 6   t        |       }t        |      D cg c]  }d|z  	 }}||}nat        |t        t        f      r|}n0t        |t
              r|j                  d      }nt        d|      t        |      }||k  r|||d z  }g }t        ||| j                        D ]X  \  }}}	|t        v r4|	d   t        v r|j                  ||	d   f       1|j                  |	       C|j                  ||	d   f       Z t        j                  |      S c c}w )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.

    f%iN,zillegal input names r      )lenrange
isinstancetupleliststrsplit	NameErrorzipdescrreserved_fieldsappendnpr   )
r%   namesndescridefault_names	new_namesnnamesndts
             V/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numpy/ma/mrecords.py_checknamesr3   ,   s    ZF(-f61UQY6M6}!	eeT]+Is#C(I25)<==YF?vw//IFM5;;? %	Aqt&q!A$i(a MM1ad)$% 88F- 7s   Dc                     | j                   j                  D cg c]  }|df }}t        j                  | j                  |      }t        dgt        |      z        |_        |S c c}w )Nz|b1r   F)r   r)   r(   emptyshaper   r   flat)selfr/   mdescrfdmasks       r2   _get_fieldmaskr<   N   sX    "&**"2"23Qq%j3F3XXdjj/F#f+-.FKM 4s   A&c                       e Zd ZdZdddddddddeddddfdZd Zed        Zed	        Z	d
 Z
d Zd Zd Zd Zd Zd ZddZd Zd Zd ZddZd Zd Zd Zy)r   a  

    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.

    Nr   FTc                 6   t        j                  | |||||||||	|
      }t        j                  |j                        }|t
        u st        j                  |      s!|st        dgt        |      z        |_
        |S t        j                  ||      }|j                  |j                  k7  rv|j                  |j                  }}|dk(  r!t        j                  ||j                        }n8||k(  r!t        j                  ||j                        }nd}t        |||fz        |s|j!                  |       d|_        |S |j                  |k(  r|}n;t        j                  |D cg c]  }t        |gt        |      z         c}|      }||_
        |S c c}w )N)	r   bufoffsetstridesformatsr)   titles	byteorderalignedF)copyr   z?Mask and data not compatible: data size is %i, mask size is %i.Tr5   )r   __new__mamake_mask_descrr   r   r(   sizer   r   r   r   r7   resizereshaper   __setmask___sharedmask)clsr7   r   r?   r@   rA   rB   r)   rC   rD   rE   mask	hard_mask
fill_value	keep_maskrF   optionsr9   mdtypendnmmsgr   ms                           r2   rG   zMaskedRecords.__new__g   sk    U%S(/'-(/2
 ##DJJ/6>"E7S[#89
. + 88Dt,DzzTZZ' IItyyR799T4::6D2X::dDJJ7D-C!#R.11  &#'   ::' EHH%M1eQC#f+,=&>%M+13E"
 &Ns   %Fc                    t        |dd       }|t        |dt              }t        j                  | d      }|t        u r"t	        j
                  | j                  |      }nYt	        j                  |      }t        |D cg c]  }t        |gt        |      z         c}|      j                  t              }| j                  }|j                  |       | j                  |       |d   t        k(  r	t        |d<   y c c}w )Nr   r   r5   r   
_baseclass)getattrr   r   __getattribute__rH   make_mask_noner7   rI   narrayr   r   viewr   __dict__update_update_from)r9   objr   objmask_dtyper:   rY   _dicts           r2   __array_finalize__z MaskedRecords.__array_finalize__   s    Wd+=c7F3G--dG<F& ))$**FC++F3'JQqcCK&7 8J%+--1T(^  5!#')"*E,  Ks   ?C?c                 6    t        j                  | t              S )z2
        Returns the data as a recarray.

        )r   ra   r   r9   s    r2   r   zMaskedRecords._data   s     ||D(++    c                     | j                   S )z!
        Alias to mask.

        r[   rk   s    r2   r   zMaskedRecords._fieldmask   s     zzrl   c                 n    | j                   rt        | j                        S t        | j                        S )z%
        Returns the length

        )ndimr   r   r   rk   s    r2   __len__zMaskedRecords.__len__   s'     99tzz?"4::rl   c                    	 t         j                  | |      S # t        $ r Y nw xY wt        j                  | d      j                  }	 ||   d d }n&# t
        t        f$ r}t        d|       |d }~ww xY wt        j                  | d      }t        j                  | |d         } |j                  | }|j                  j                  t        d      d}|j                  dd       }	|	U	 |	|   }	n# t        $ r Y nw xY wt        |	j                        }
|	j                  t        |
r|
fnd	f      j!                         }|j"                  s|rh|j                  t$              }t        |_        d
|_        |	|_        |j                  dd       }|$	 ||   |_        |S # t.        $ r d |_        Y |S w xY w|S |j1                         }|S )Nr      record array has no attribute rb   r\   z4MaskedRecords is currently limited tosimple records.Fr    T_fill_value)objectr^   AttributeErrorr   fields	TypeErrorKeyErrorra   getfieldr   r)   NotImplementedErrorget
IndexErrorr   boolanyr7   r   r\   _isfieldr   ru   
ValueErroritem)r9   attr	fielddictrese
_localdictr   re   	hasmaskedr   tp_lenru   s               r2   r^   zMaskedRecords.__getattribute__   s   	**466 		 ,,T7;BB		@D/"1%C8$ 	@ 079>?@	@ --dJ?
T:l#;<ennc"99??&% '8 9 9 	w-d  %F

DF9B#HIMMOIII((;'C$CNCLCI$..=K&+&1$&7CO
 
	 " +&*CO 
	+ 
 ((*C
sH    	$$A A4 A//A4-C3 3	C?>C?
F F21F2c                 &   |dv r| j                  |       yt        j                  | d      }||v}	 t        j                  | ||      }t	        j                  | d      j
                  xs i }||vr|S |r	 t        j                  | |       	 ||   dd }|t        u r|d   }
|
	|d   |   }n|}d	}nt        |      }t        |      } t	        j                  | d
      j                  |g| }|d   j                  ||       |S # t        $ r |cY S w xY w# t        $ rJ t	        j                  | d      j
                  xs i }t	        j                  | d      xs i }||v s||v s Y w xY w# t        t        f$ r}	t        d|       |	d}	~	ww xY w)z<
        Sets the attribute attr to the value val.

        )rP   	fieldmaskNrb   r   _optinforr   rs   ru   Tr   r   )rM   rv   r^   __setattr__r   rx   __delattr__	Exceptionry   rz   rw   r   r
   r	   setfield__setitem__)r9   r   valr   newattrretr   optinfor   r   ru   dvalmvalre   s                 r2   r   zMaskedRecords.__setattr__   s    ((S!,,T:>
j(	$$T45C  00w?FFL"I9$
&&tT2	@D/"1%C
 &=$]3K&!-06D#;D$D>g&&tW5>>tJcJ7''d3
+ ! J#  	00w?FFL"I..tZ@FBGI%	, 8$ 	@ 079>?@	@s<   D 6D E- DDAE*)E*-F<FFc                    | j                   }t        j                  | d      }t        j                  | |d         }t	        |t
              rZ||   j                  t              }||   |_        d|_        |d   }|
||   |_	        |j                  s|j                  rt        S |S t        j                  ||         j                  t              }t        j                  ||         j                  t              |_        |S )z
        Returns all the fields sharing the same fieldname base.

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

        r   r\   Tru   )rb   r   r^   ra   r   r!   r   r   rN   ru   ro   r   r(   asarrayr   r   )r9   indxr   r   r   re   fvals          r2   __getitem__zMaskedRecords.__getitem__%  s     ]]
((w7T:l#;<dC 
 +"";/CdCI"COm,D"&t*88		J jjt%**95JJuT{+00:	
rl   c                     t        j                  | ||       t        |t              r#t	        j
                  |      | j                  |<   yy)z2
        Sets the given record to value.

        N)r   r   r   r!   rH   r	   r   )r9   r   values      r2   r   zMaskedRecords.__setitem__E  s<    
 	dE2dC !u5DJJt !rl   c                 h   | j                   dkD  rt        | j                  j                  D cg c]  }t	        | |       c} D cg c].  }ddj                  |D cg c]  }t        |       c}       d0 }}}ddj                  |       dS t        | j                  j                  D cg c]  }t	        | |       c}      D cg c]+  }dj                  |D cg c]  }t        |       c}       - }}}ddj                  |       dS c c}w c c}w c c}}w c c}w c c}w c c}}w )z8
        Calculates the string representation.

        r   (r   )[z, ])rJ   r$   r   r)   r]   joinr!   )r9   fsr+   mstrs        r2   __str__zMaskedRecords.__str__N  s%   
 99q= TZZ=M=M"N74#3"NOQ !!4Q#a&!456a8 QD Qtyy'q)) !DJJ<L<L!Mq'$"2!MNP xx 3AQ 3456 PD Ptyy'q)) #O "5 Q
 "N !4 Ps;   DDD.D/D$D. D)2
D.D)D.c           	         | j                   j                  }dt        |D cg c]  }t        |       c}      dz   fz  }| j                   j                  D cg c]  }||t	        | |      fz   }}|j                  dd       |j                  |d| j                  fz  dg       t        dj                  |            S c c}w c c}w )z6
        Calculates the repr representation.

        z%%%is : %%s   r   zmasked_records(z    fill_valuez              )
)
r   r)   maxr   r]   insertextendrR   r!   r   )r9   _namesr/   fmtr   reprstrs         r2   __repr__zMaskedRecords.__repr__\  s    
 !!sF#;qCF#;<q@BB8<

8H8HI13!WT1-..IIq+,/AA)+ 	,499W%&& $<Is   C 
Cc                 6   |/|t        j                  |       }not        j                  | |      }nX|?	 t        |t               rt        j                  | |      }nt        j                  | |      }nt        j                  | ||      }t        |dt              t        ur_t        j                  |j
                        }| j                   j                  |t               |_        |j"                  |j                   _        |S # t        $ r t	        j
                  |      }|j                  K| j                  j                  d   }| j                         j                  ||      }|j                  |        nt        j                  | |      }d|_        Y w xY w)z3
        Returns a view of the mrecarray.

        Nr   r   )r   ra   
issubclassry   r(   r   rx   	__class__	__bases__	__array__rd   ru   r]   r   rH   rI   r   r7   )r9   r   typeoutputbasetyperU   s         r2   ra   zMaskedRecords.viewi  sB    =| d+ dD1\*eW-$\\$6F$\\$6F \\$t4FFGV,F:''5F::??67;FL!'FLL'  * <<'#~~77:H!^^-225(CF''-$\\$6F%)"*s   =D BFFc                     d| _         y)z+
        Forces the mask to hard.

        TN	_hardmaskrk   s    r2   harden_maskzMaskedRecords.harden_mask  s    
 rl   c                     d| _         y)z*
        Forces the mask to soft

        FNr   rk   s    r2   soften_maskzMaskedRecords.soften_mask  s    
 rl   c                     | j                   j                         j                  t        |             }| j                  j                         |_        |S )z7
        Returns a copy of the masked record.

        )r   rF   ra   r   r   )r9   copieds     r2   rF   zMaskedRecords.copy  s:    
 "''T
3zz(rl   c                    || j                  |      j                         S t        | j                         j                         t              }t        | j                  j                               }d||<   |j                         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``.

        Nr5   )r
   tolistr`   rv   r   )r9   rR   resultrP   s       r2   r   zMaskedRecords.tolist  si     !;;z*1133,,.f=djj'')*t}}rl   c                     d| j                   | j                  | j                  j                  | j                  j                         | j                  j                         | j                  f}|S )zWReturn the internal state of the masked array.

        This is for pickling.

        r   )r7   r   flagsfncr   tobytesr   ru   )r9   states     r2   __getstate__zMaskedRecords.__getstate__  sW     ##%##%!! rl   c                 .   |\  }}}}}}}t        j                  | ||||f       t        | j                  j                  D 	
cg c]  \  }	}
|	t        j
                  f c}
}	      }| j                  d   j                  ||||f       || _        yc c}
}	w )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.

        r   N)r   __setstate__r   r%   r(   r   rb   rR   )r9   r   vershptypisfrawmskflvk_rU   s               r2   r   zMaskedRecords.__setstate__  s     /4+c3S#sTCc3#784::3C3CD!QBGGDEg++S&#s,CD Es   B
c                 `    t         | j                  | j                  ddf| j                         fS )z?
        Return a 3-tuple for pickling a MaskedArray.

        )r   b)_mrreconstructr   r\   r   rk   s    r2   
__reduce__zMaskedRecords.__reduce__  s1    
 $=!!#% 	%rl   )NNN)__name__
__module____qualname____doc__r   rG   ri   propertyr   r   rp   r^   r   r   r   r   r   ra   r   r   rF   r   r   r   r   rt   rl   r2   r   r   U   s    " #'DDDu	&P( , ,  	-^6p@6*'&P  (%rl   r   c                     t        j                  |||      j                  |       }t        j                  t         |d      }| j                  | |||      S )zK
    Build a new MaskedArray from the information stored in a pickle.

    b1)rP   r   )r   rG   ra   )subtype	baseclass	baseshaper   r   r   s         r2   r   r     sJ    
 OOIy(;@@IEOOGY5E??7EX?GGrl   Fc	           
      >   | D 	cg c]  }	t        |	       }
}	| D 	cg c]   }	t        j                  t        |	            " }}	t	        |
|||||||      j                  t              }t        t        |       |j                  _
        |||_        |S c c}	w c c}	w )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.

    r   r7   rB   r)   rC   rE   rD   )r   r(   
atleast_1dr	   recfromarraysra   r   r    r$   r   r8   rR   )	arraylistr   r7   rB   r)   rC   rE   rD   rR   xdatalistmasklist_arrays                r2   r   r     s    > %..q
.H.8AB1l1o.BHB8!&eW!&vw%.0 15Y  S(^,FLL&M /Bs
   B%Bc
           
         t        | dd      }
t        | t              rQt        | t              r#| j	                         j                  t              } || j                  }| j                         } t        | |||||||      j                  t              }|||_
        |	t        urt        j                  |	      }	t        |	j                        }|r|	|j                  _        nI|	j"                  dk(  r)|	D cg c]  }t%        |       c}|j                  _        n|j'                  |	       |
|
|j                  dd |S c c}w )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.

    r   Nr   rr   )r]   r   r   r   r
   ra   r   r   recfromrecordsr   rR   r   r(   r   r   r   r8   ro   r   rM   )reclistr   r7   rB   r)   rC   rE   rD   rR   rP   r   mrecmaskrecordlengthrY   s                 r2   r   r   "  s   D GWd+E'7#g{+nn&++G4G=MME.."'eW %f")Y@@DY 	 $6zz$tzz?"DJJOYY!^156AuQx6DJJOT"

1K 7s   7E c                    g }t        j                  |       } | j                  dk(  r| d   } n| j                  dkD  rt        d      | D ]6  }	 t	        |       |j                  t        j                  t                     8 |S # t        t        f$ r 	 t        |       |j                  t        j                  t                     nz# t        t        f$ rh 	 t        |       |j                  t        j                  t                     n0# t        t        f$ r |j                  | j                         Y nw xY wY nw xY wY w xY w)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.

    rr   r   zThe array should be 2D at most!)
r(   r   ro   r   intr'   r   ry   floatcomplex)arrvartypesr   s      r2   _guessvartypesr   c  s    H
**S/C
xx1}!f	A:;; +	+F OOBHHSM*!+" O I& 	1
1a 0 	* 77AJ OOBHHW$56 #I. /OOCII./7	1sZ   BEC)ED?D#)D?*D9	6D?8D9	9D?<E>D??EEc                    t        | d      r| S 	 t        |       }|j                         dd dk7  r|j	                  dd       |S |j                          t        d      # t        $ r}t        d|  d      |d}~ww xY w)	z1
    Opens the file handle of file `fname`.

    readlinezNo such file: ''Nrr   z\xr   zWow, binary file)hasattropenFileNotFoundErrorr   seekcloser|   )fnamer   r   s      r2   openfiler    s     uj!CK 	zz|BQ5 	q!GGI
0
11  C/% :;BCs   A   	A>)A99A>)	delimitorc                ~   |t         j                  ur+|t        d      t        j                  dt
        d       |}t        |       }	 |j                         }|d|j                  |       j                         }	|	j                  |      }
t        |
      dkD  rnS||
}t        |D cg c]7  }|d   |k7  r-t        |      dkD  r|j                         j                  |      9 c}      }|j                  \  }}|j                          |t        |d         }nj|D cg c]  }t        j                   |       }}t        |      |k7  r:d}|d	z  }t        j                  |t        |      |fz  d       t        |d         }t#        ||      D cg c]	  \  }}||f }}}|D cg c]  }t%        j&                  |       }}|j(                  |k(  }t#        |j(                  |||      D cg c]  \  }}}}t        ||||
       }}}}}t+        ||      S c c}w c c}w c c}}w c c}w c c}}}}w )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'zThe 'delimitor' keyword argument of numpy.ma.mrecords.fromtextfile() is deprecated since NumPy 1.22.0, use 'delimiter' instead.rr   )
stacklevelr   r   z&Attempting to %i dtypes for %i fields!z Reverting to default.)rP   r   rR   r5   )r(   _NoValuery   warningswarnDeprecationWarningr  r   findstripr"   r   r   r7   r  r   r   r$   rH   default_fill_valueTr   )r  	delimitercommentcharmissingcharvarnamesr   r  ftextline	firstline	_varnames
_variablesr   nfieldsvrX   r/   r   r:   mfillvr   arY   r1   	_datalists                            r2   r   r     sO   4 #  * + + 	 E )Q	8 	 UOE ~~0$))K01779	OOI.	y>A    L"&q'["8SY]  $zz|11)< L MJ##LQ	KKM !*Q-0)12ABHHQK22x=G#:C++CMM#X 88QG%jm4H $'x#:;!Qq!f;F;0891b##A&9F9 \\[(E%(uh%OQ Q!aAq aaqQ? QI Q iv..5L 3 <9
Qs   *<H"!H'H,+H25H7
c                 L   | j                   }| j                  }||t        v rdt        |j                        z  }t        j                  |      }t        j                  |j                  j                  ||j                  fgz         }t        |j                  |      }|j                  j                  j                         D cg c]"  } |j                   |j                  | g| $ c}  |j                  |j                   g|j                  j                  |     |j                  t               }t        j                  |j"                  D cg c]  }|t        j$                  f c}      }	t        |j                  |	      }
|j                  j                  j                         D cg c]"  } |
j                   |j                  | g| $ c}  |
j                  t'        |      g|
j                  j                  |     |
|_        |S c c}w c c}w c c}w )zAdds 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.

    r   )r   r   r&   r   r   rH   r   r(   r%   r   r7   rx   valuesr   r{   ra   r   r)   r   r	   )mrecordnewfieldnewfieldnamer   r   newdtypenewdatar   r/   	newmdtypenewmasks              r2   r   r     s    MMEMME|>s5;;//xx!H xx))lHNN-K,LLMHu{{H-G kk  '')+	
 Wnenna(-1- + GX^^Igmm&:&:<&HIll=)G ?11bgg,?@Iu{{I.G kk  '')+	
 Wnenna(-1- + G\(+ :mm**<8:GMN!+ @+s   'HH1'H!r   )NNNNNFNN)N# NN))r   numpy.mar   r   r   r   r   r   r	   r
   rH   r
  numpyr(   r   r   r   r`   numpy._core.recordsr   r   r   r   r   _corerecords_byteorderconvcore_check_fill_value__all__r&   r3   r<   r   r   r   r   r  r	  r   r   rt   rl   r2   <module>r3     s   	      1 1  !!00 GG-- 
 <DN%K N%bH 	 ;?AE(V  $4TUdf>B"J2( FH)-M/ kkM/`"rl   