bg`j PdZddlmZmZmZmZmZmZmZm Z ddlm Z ddl Z ddl Z ddl mZmZmZmZmZddlmZmZe jjjZe jjZgdZgdZddZd Z Gd d eZ!d Z"e!Z# ddZdddddd ddef dZdZ$dZ% de j&ddZ'ddZ(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 MaskedArraymaskednomask masked_arraygetdata getmaskarrayfilledN)bool_dtypendarrayrecarrayarray) fromarrays fromrecords) MaskedRecords mrecarrayrr fromtextfileaddfield)_data_mask _fieldmaskr ct|}dt|D}||}n~t|ttfr|}n=t|t r|d}ntd|t|}||kr |||dz }g}t|||j D]o\}}}|tvrC|dtvr| ||df<| |R| ||dfptj |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. cg|]}d|zS)f%i.0is d/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib64/python3.11/site-packages/numpy/ma/mrecords.py z_checknames..6s6661UQY666N,zillegal input names r)lenrange isinstancetupleliststrsplit NameErrorzipdescrreserved_fieldsappendnpr ) r.namesndescr default_names new_namesnnamesndts r _checknamesr:-sUZZF66f 666M }! eeT] + + >II s # # > C((II<5<<== =Y F?? vww/ /I FM5;??%% Aq   t&& q!A$i(((( a    MM1ad) $ $ $ $ 8F  r"cd|jjD}tj|j|}t dgt |z|_|S)Ncg|]}|dfS)z|b1rrr7s r r!z"_get_fieldmask..Ps 3 3 3Qq%j 3 3 3r"r F)r r2r1emptyshaper(r%flat)selfmdescrfdmasks r _get_fieldmaskrEOsQ 3 3$*"2 3 3 3F Xdj / / /F#f++-..FK Mr"ceZdZdZdddddddddeddddfdZdZedZed Z d Z d Z d Z d Z dZdZdZddZdZdZdZddZdZdZdZdS)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 tj|||||||||| |  }tj|j| t ust j| s(|s%tdgtz|_ nt j | |} | j |j krf|j| j}}|dkrt j | |j } n7||krt j| |j } nd}t|||fz|s|| d|_n7| jkr| }n"t j fd| D}||_ |S) N) r bufoffsetstridesformatsr2titles byteorderalignedFcopyr$z?Mask and data not compatible: data size is %i, mask size is %i.TcPg|]"}t|gtz#Srr(r%)rmmdtypes r r!z)MaskedRecords.__new__..s.%M%M%M1eQC#f++,=&>&>%M%M%Mr"r>)r__new__mamake_mask_descrr rr1sizer(r%rrr@resizereshaper __setmask__ _sharedmask)clsr@r rHrIrJrKr2rLrMrNmask hard_mask fill_value keep_maskrPoptionsrBndnmmsgrrTs @r rUzMaskedRecords.__new__hsU%S(/'-(/222 #DJ// 6>>> :"E7S[[#899 8Dt,,,DzTZ'' ItyR779T4:66DD2XX:dDJ77DD-C!#R.111 #  &&&#'  :'' EEH%M%M%M%M%M%M%M+1333E"  r"ct|dd}|t|dt}tj|d}|turt j|j|}nIt j|tfd|D t}|j }| || ||dtkr t|d<dS)Nrr r>cPg|]"}t|gtz#SrrR)rrSrCs r r!z4MaskedRecords.__array_finalize__..s.JJJQqcCKK&7 8 8JJJr"r _baseclass)getattrrr __getattribute__rVmake_mask_noner@rWnarrayviewr__dict__update _update_from)rBobjrobjmask_dtype_dictrCs @r __array_finalize__z MaskedRecords.__array_finalize__sWd++ =c7F33G-dG<? @ @-dJ??  T:l#;<<enc" 9? &%'899 9 w--   d     %%F D+FF99B#HIIMMOOI I  ((;''C$CNCLCI$..==K&+&1$&7COO!+++&*COOO+' ((**C sH **AB*A==B5C>> D  D + F99G  G ct|dvr||dSt|d}||v} t|||}t j|djpi}||vr|S|r/ t||n_#t$r|cYSwxYwnL#t$r?t j|djpi}t j|dpi}||vs||vsYnwxYw ||dd}n,#ttf$r} td|| d} ~ wwxYw|tur|d} | |d|} n|} d } nt|} t|} t j|d j| g|R} |d || | S) z< Sets the attribute attr to the value val. )r^ fieldmaskNror _optinfor~rrTrr)r[rrk __setattr__r r __delattr__ Exceptionrrrrr r setfield __setitem__)rBrvalrnewattrretroptinforrrdvalmvalrrs r rzMaskedRecords.__setattr__s? ( ( (   S ! ! ! F,,T:>> j( $$T455C 0w??FL"I9$$  &&tT2222 JJJ     0w??FL"I.tZ@@FBGI%%  ( @D/"1"%CC8$ @ @ @ 77799>? @ @ &==$]3K&!-06DD#;;D$$D>g&tW55>tJcJJJ7''d333 s<B,=B B('B(,AC54C59D D3D..D3c<|j}tj|d}tj||d}t |t rb||t }|||_d|_|d}| |||_ |j s|jrtS|Stj ||dt}tj ||dt|_|S)z Returns all the fields sharing the same fieldname base. The fieldname base is either `_data` or `_mask`. rriTrNFrO)ror rkrnr'r*rrr\rr{rr1rrr)rBindxrrrrrfvals r __getitem__zMaskedRecords.__getitem__&s] (w77 T:l#;<< dC   +"";//Cd CI"COm,D"&t*8    JhuT{///44Y??HU4[u555::8DD  r"ctj|||t|trt j||j|<dSdS)z2 Sets the given record to value. N)rrr'r*rVr r)rBrvalues r rzMaskedRecords.__setitem__FsQ dE222 dC  6!u55DJt    6 6r"c.jdkrBdtfdjjDD}dd|dSdtfdjjDD}d d|d S) z8 Calculates the string representation. r$cTg|]%}ddd|Dd&S)(r#c,g|]}t|Srr*rs r r!z4MaskedRecords.__str__...Us!4!4!4Q#a&&!4!4!4r")joinrss r r!z)MaskedRecords.__str__..UsTQQQ9!4!4!!4!4!455888QQQr"c0g|]}t|SrrjrfrBs r r!z)MaskedRecords.__str__..Vs#"N"N"N74#3#3"N"N"Nr"[z, ]cNg|]"}dd|D#S)r#c,g|]}t|Srrrs r r!z4MaskedRecords.__str__...Ys 3 3 3AQ 3 3 3r"rrs r r!z)MaskedRecords.__str__..YsLPPPxx 3 3 3 3 3446PPPr"c0g|]}t|Srrrs r r!z)MaskedRecords.__str__..Zs#!M!M!Mq'$"2"2!M!M!Mr"rr)rXr-r r2r)rBmstrs` r __str__zMaskedRecords.__str__Os 9q==QQ "N"N"N"NTZ=M"N"N"NOQQQD)tyy))) )PP !M!M!M!MDJ.cs#;#;#;qCFF#;#;#;r"c:g|]}|t|fzSrr)rrfmtrBs r r!z*MaskedRecords.__repr__..ds-III13!WT1--..IIIr"rzmasked_records(z fill_valuez ) )r r2maxinsertextendr`r*r)rB_namesreprstrrs` @r __repr__zMaskedRecords.__repr__]s !s#;#;F#;#;#;<)r tolistrmrr)rBr`resultr^s r rzMaskedRecords.tolists  !;;z**1133 3 ,,..f===dj''))**t }}r"cd|j|j|jj|j|j|jf}|S)zWReturn the internal state of the masked array. This is for pickling. r$)r@r flagsfncrtobytesrr)rBstates r __getstate__zMaskedRecords.__getstate__sN ##%%##%%!  r"c|\}}}}}}}tj|||||ftd|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. c&g|]\}}|tfSrr )rk_s r r!z.MaskedRecords.__setstate__..s BBBv1E BBBr"rN)r __setstate__r r.ror`) rBrvershptypisfrawmskflvrTs r rzMaskedRecords.__setstate__s/4+c3S#sTCc3#7888BB1ABBBCC g++S&#s,CDDDr"cVt|j|jddf|fS)z? Return a 3-tuple for pickling a MaskedArray. )rb)_mrreconstructrrirrxs r __reduce__zMaskedRecords.__reduce__s0 $=!!##% %r")NNN)__name__ __module__ __qualname____doc__rrUrvpropertyrrr|rkrrrrrrnrrrPrrrrrr"r rrVs"#'DDDu &&&&P(,,X,X   ---^666p@666 * * * ' ' '&&&&P  (%%%%%r"rctj||||}tjt|d}|||||S)zK Build a new MaskedArray from the information stored in a pickle. b1)r^r )r rUrn)subtype baseclass baseshaperrrs r rrsR OIy( ; ; @ @ I IE OGY 5 5E ??7EX? G GGr"Fc d|D} d|D} t| |||||||t} tt | | j_||| _| 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. c,g|]}t|Sr)rrxs r r!zfromarrays..s...q ...r"cPg|]#}tjt|$Sr)r1 atleast_1dr rs r r!zfromarrays..s(BBB1 l1oo..BBBr"r r@rKr2rLrNrM) recfromarraysrnrr)r-rrAr`) arraylistr r@rKr2rLrNrMr`datalistmasklist_arrays r rrs>/.I...HBB BBBH 8!&eW!&vw%.00015Y S(^,,FL& Mr"c t|dd} t|tr^t|tr,|t}||j}|}t||||||||t} ||| _ | turptj | d} t| j} | r | | j_n7| jdkrd| D| j_n| | | | | 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. rNrFrOr~c,g|]}t|Sr)r()rrSs r r!zfromrecords..\s666AuQxx666r")rjr'r rr rnr rrecfromrecordsrr`rr1rr%rrAr{r[) reclistr r@rKr2rLrNrMr`r^rmrecmaskrecordlengths r rr#sJD GWd + +E'7### g{ + + 5nn&&++G44G =ME.."" 'eW %f")Y @ @ @@DY $ 6x5)))tz??  #"DJOO Y!^^66666DJOO   T " " "  111 Kr"cg}tj|}|jdkr |d}n|jdkrtd|D]} t ||tjt@#ttf$r t||tjtn#ttf$rq t||tjtn1#ttf$r||jYnwxYwYnwxYwYwxYw|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. r~rzThe array should be 2D at most!) r1asarrayr{rintr0r rfloatcomplex)arrvartypesrs r _guessvartypesrdsoH *S//C x1}}!f A:;;; ++ + FFF OOBHSMM * * * *I& 1 1 1 1a0000 * 7 7 77AJJJOOBHW$5$56666#I.///OOCI...../ 7 1 OsZ BEC(-EE'D#6-E#+E EE EEEEEcJt|dr|S t|}n&#t$r}td|d|d}~wwxYw|dddkr|dd|S|t d) z1 Opens the file handle of file `fname`. readlinezNo such file: ''Nr~z\xrzWow, binary file)hasattropenFileNotFoundErrorrseekcloser)fnamerrs r openfiler#s uj!! C KK CCC :% : : :;;BCzz||BQB5   q! GGIII 0 1 11s$ AAA#) delimitorc|tjur/tdtjdt d|t |} |}|d| } | } t| dkrnm|| }tfd|D} | j \} } ||t| d }ncd |D}t|| krDd }|d z }tj|t|| fzdt| d }d t!||D}d|D}| j|k}dt!| j|||D}t%||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.r~) stacklevelTr$cg|]H}|dkt|dk!|IS)rr$)r%stripr+)rline commentchar delimiters r r!z fromtextfile..sVLLL"&q'["8"8SYY]] $zz||11)<<=J]]r"rc6g|]}tj|Sr)r1r )rvs r r!z fromtextfile..s 222ABHQKK222r"z&Attempting to %i dtypes for %i fields!z Reverting to default.cg|] \}}||f Srr)rr7rs r r!z fromtextfile..s ; ; ;!Qq!f ; ; ;r"c6g|]}tj|Sr)rVdefault_fill_value)rrs r r!z fromtextfile..s# 9 9 91b#A&& 9 9 9r"c>g|]\}}}}t||||S))r^r r`)r)rarSr9rs r r!z fromtextfile..sGQQQ!aAqaaqQ???QQQr"r>)r1_NoValuerwarningswarnDeprecationWarningr#rfindr*r+r%rr@r!rr-Tr)r"r-r, missingcharvarnamesrr&ftextr+ firstline _varnames _variablesrnfieldsrerCmfillvr _datalists `` r rrsJ4 ##  *++ +  E)Q 8 8 8 8  UOOE~~0$))K00017799 OOI.. y>>A     LLLLLLLLMMJ#LQ KKMMM!*Q-0022222 x==G # #:C + +C M#X 88Q G G G G%jm44H< ;3x#:#: ; ; ;F 9 9 9 9 9F\[ (EQQ%(uh%O%OQQQI iv . . ..r"c |j|j| |tvrdtjz}t j|}tjjj||jfgz}tj |fdjj Dj |jgjj |Rttjd|jD}tj |fdjj Dj t#|gjj |R_S)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. Nrc<g|]}jj|g|RSrrr)rrrnewdatas r r!zaddfield..G+++ Wnena(-1---+++r"c g|] }|tf Srrr=s r r!zaddfield..s===1e*===r"c<g|]}jj|g|RSrrF)rrrnewmasks r r!zaddfield.. rHr")rrr/r%r rVrr1r.rr@rvaluesrrnrr2r ) mrecordnewfield newfieldnamenewdtype newmdtyperrrGrKs @@@@r rrs ME ME|>>s5;/// x!!Hx )lHN-K,LLMMHu{H--G+++++k ''))++++GX^Igm&:<&HIIIIll=))G==hn===>>Iu{I..G+++++k ''))++++G\(++:m*<8::::GM Nr"r)NNNNNFNN)Nr$r%NN))rnumpy.marrrrrrr r rVr6numpyr1r r r rrrmnumpy.core.recordsrrrrcorerecords_byteorderconv_check_fill_value__all__r/r:rErrrrr#r5rrrr"r rZsp  /G-    <;;DN%N%N%N%N%KN%N%N%b HHH  ;?AE((((V $4TUdf>>>>B"""J222(FH)-M/ kM/M/M/M/M/`""""""r"