L idddlZddlZddlZddlZddlZ gdZejdZejdZ ejdZ ejdZ ejdZ ejdZ ejd Zejd Zejd Zejd Zejd ZGddeZGddeZGddZGddeZGddeZGddeZGddeZGddeZdZdZd Zd+d!Zd"Z d#Z!d$Z"d%Z#d&Z$Gd'd(Z%d)Z&d*Z'y),N)MetaDataloadarff ArffErrorParseArffErrorz^\s*@z^%z^\s+$z^\s*@\S*z^@[Dd][Aa][Tt][Aa]z*^@[Rr][Ee][Ll][Aa][Tt][Ii][Oo][Nn]\s*(\S*)z2^\s*@[Aa][Tt][Tt][Rr][Ii][Bb][Uu][Tt][Ee]\s*(..*$)z{(.+)}z%[Dd][Aa][Tt][Ee]\s+[\"']?(.+?)[\"']?$z'(..+)'\s+(..+$)z(\S+)\s+(..+$)c eZdZy)rN__name__ __module__ __qualname__]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/io/arff/_arffread.pyrr6r rc eZdZy)rNrr r rrr:rr rc2eZdZdZdZedZdZdZy) AttributeNcJ||_d|_tj|_yN)namerangenpobject_dtype)selfrs r__init__zAttribute.__init__Es  ZZ r cy)zj Parse the attribute line if it knows how. Returns the parsed attribute, or None. Nr clsr attr_strings rparse_attributezAttribute.parse_attributeJs r cy)- Parse a value of this type. Nr rdata_strs r parse_datazAttribute.parse_dataRsr c:|jdz|jzS)r",)r type_namers r__str__zAttribute.__str__Xsyy3//r ) r r r r(r classmethodr r%r*r r rrrAs*I  0r rcNeZdZdZfdZedZedZdZ dZ xZ S)NominalAttributenominalct||||_||_tj t d|Df|_y)Nc32K|]}t|ywr)len).0is r z,NominalAttribute.__init__..gs$<SV$<)superrvaluesrrbytes_maxr)rrr7 __class__s rrzNominalAttribute.__init__cs9   ii$>> from scipy.io.arff._arffread import NominalAttribute >>> NominalAttribute._get_nom_val("{floup, bouga, fl, ratata}") ('floup', 'bouga', 'fl', 'ratata') z(This does not look like a nominal string) r_nominalmatchsplit_data_linegrouptuple ValueError)atrvmattrs_s r _get_nom_valzNominalAttribute._get_nom_valisA. OOD ! &qwwqz2HE1< GH Hr cH|ddk(r|j|}|||Sy)z Parse the attribute line if it knows how. Returns the parsed attribute, or None. For nominal attributes, the attribute string would be like '{, , }'. r{N)rG)rrrr7s rr z NominalAttribute.parse_attributes0 q>S %%k2FtV$ $r c||jvr|S|dk(r|Stt|dt|j)r"?z value not in )r7rBstrr#s rr%zNominalAttribute.parse_datasE t{{ "O _OH nS=MC' 'C ( t{{2 s  r ) r r r r(r staticmethodrGr+r r%r* __classcell__r:s@rr-r-_sBI> II:   Qr r-c:eZdZfdZedZdZdZxZS)NumericAttributec\t||d|_tj|_y)Nnumeric)r6rr(rfloat64rrrr:s rrzNumericAttribute.__init__s" "ZZ r c|jj}|dtddk(s"|dtddk(s|dtddk(r||Sy)z Parse the attribute line if it knows how. Returns the parsed attribute, or None. For numeric attributes, the attribute string would be like 'numeric' or 'int' or 'real'. NrXintreallowerstripr1rs rr z NumericAttribute.parse_attributesa"'')//1 Y (I 5 {E #u , |F $ .t9 r c@d|vrtjSt|S)a Parse a value of this type. Parameters ---------- data_str : str string to convert Returns ------- f : float where float can be nan Examples -------- >>> from scipy.io.arff._arffread import NumericAttribute >>> atr = NumericAttribute('atr') >>> atr.parse_data('1') 1.0 >>> atr.parse_data('1\n') 1.0 >>> atr.parse_data('?\n') nan rK)rnanfloatr#s rr%zNumericAttribute.parse_datas2 (?66M? "r c|jdz|jdz z }tj|tj|tj|tj ||zfS)Ng?r<)sizernanminnanmaxmeanstd)rdatanbfacs r _basic_statszNumericAttribute._basic_statssU B$))a-0 $4 rvvd|e35 5r ) r r r rr+r r%rlrSrTs@rrVrVs& $#<5r rVc.eZdZfdZedZxZS)StringAttributec2t||d|_y)Nstring)r6rr(rZs rrzStringAttribute.__init__s !r cr|jj}|dtddk(r||Sy)z Parse the attribute line if it knows how. Returns the parsed attribute, or None. For string attributes, the attribute string would be like 'string'. Nrpr^rs rr zStringAttribute.parse_attributes;"'')//1 ~H &( 2t9 r )r r r rr+r rSrTs@rrnrns"r rncNeZdZfdZedZedZdZfdZ xZ S) DateAttributect||||_||_d|_||_t jd|j|_y)Ndater) r6r date_format datetime_unitr(rr datetime64r)rrrvrwr:s rrzDateAttribute.__init__sF &*  ]]1d&8&89 r ctj|}|r|jdj}d}d|vr|j dd}d}n |j dd}d}d|vr|j dd}d }d |vr|j d d }d }d |vr|j d d}d}d|vr|j dd}d}d|vr|j dd}d}d|vsd|vr t d| t d||fSt d)Nr<yyyyz%YYyyz%yMMz%mMddz%dDHHz%Hhmmz%MrDssz%SszZz6Date type attributes with time zone not supported, yetz"Invalid or unsupported date formatzInvalid or no date format)r_dater>r@r`replacerB)rCrDpatternrws r_get_date_formatzDateAttribute._get_date_format s9 LL  ggaj&&(G M !//&$7 # !//$5 # w!//$5 # w!//$5 # w!//$5 # w!//$5 # w!//$5 # g~ "233$ !EFFM) )89 9r c|jj}|dtddk(r|j|\}}||||Sy) Parse the attribute line if it knows how. Returns the parsed attribute, or None. For date attributes, the attribute string would be like 'date '. Nru)r_r`r1r)rrrattr_string_lowerrvrws rr zDateAttribute.parse_attribute1sV(--/557 \c&k *f 4),)=)=k)J &Kt[-8 8r c`|jjdjd}|dk(r tjd|jStjj ||j }tj|jd|jdS)r"'"rKNaTz datetime64[])r`rrxrwdatetimestrptimervastype)rr$date_strdts rr%zDateAttribute.parse_dataCs>>#))#.44S9 s?==(:(:; ;""++Hd6F6FGB==$++d00135 5r c@t|dz|jzS)Nr')r6r*rvrr:s rr*zDateAttribute.__str__Os w 3&)9)999r ) r r r rrRrr+r r%r*rSrTs@rrsrss@:$:$:L" 5::r rsc>eZdZfdZedZdZfdZxZS)RelationalAttributecxt||d|_tj|_g|_d|_y)N relational)r6rr(rrr attributesdialectrZs rrzRelationalAttribute.__init__Us0 %ZZ  r cr|jj}|dtddk(r||Sy)rNrr^)rrrrs rr z#RelationalAttribute.parse_attribute\s>(--/557 /c,/ 0L @t9 r c $ttt|j}|j j d}g}|j dD]g}t||j\}|_|jt|Dcgc]#}|j|j||%c}itj||jDcgc]}|j|jfc}Scc}wcc}w)Nzunicode-escape )listrr1rencodedecodesplitr?rappendrAr%rarrayrr) rr$elemsescaped_string row_tuplesrawrowr3as rr%zRelationalAttribute.parse_datamsU3t/01!*112BC !''- IC /T\\ B C   e@EF1#..s1v6FH I I xx 48OODq!&&!''*DF FGEs (D"D clt|dzdjd|jDzS)Nz c32K|]}t|ywr)rL)r2rs rr4z.RelationalAttribute.__str__..sr ) r r r rr+r r%r*rSrTs@rrrSs, F">>r rctttttf}|D]}|j ||}||cSt d|)Nzunknown attribute )r-rVrsrnrr r)rr attr_classesrattrs r to_attributersZ$&6 #%8:L""45  K -k]; <[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)zI(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)zG(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)z-(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)Nr<rquotedelimspacez((z)|^)\W*z[^z\n]*z\W*((z)|$))rrecompileDOTALL MULTILINEfindall groupindexr1boolescapesearchr delimiter doublequoteskipinitialspace) sniff_liner delimiters right_regexrestrregexpmatchesrrDnrrr dq_regexprs r%workaround_csv_sniffer_bug_last_fieldrs&'` b`!FH EZZryy2<<'?@FnnZ0G  K  && 7|q   AJ w ! #! w ! #! w ! #QqT JJ"))E"#75'BIIe4D3ET%PRSUS\S\]bScRddhinhootuwu~u~@EvFuGGK LNPNZNZ 9++J78 ! J  %G )#( W(r cd}tjttjdj dzddk(rddj }tfd|Ds|dz }|3tjj||}t|||ttjg|}||fS) Nz, rNrc3&K|]}|v ywrr )r2dlines rr4z"split_data_line..s-QqDy-sr')r)rrr) rfield_size_limitr\ctypesc_ulongvaluer`anyrrrnextreader)rrrrrs` rr?r?sJV^^B/55:;< Bx4CRy ::>> from scipy.io.arff._arffread import tokenize_attribute >>> iterable = iter([0] * 10) # dummy iterator >>> tokenize_attribute(iterable, r"@attribute floupi real") ('floupi', 'real', 0) If attribute is r"'floupi 2' real", will return 'floupi 2' as name, and real as value. >>> tokenize_attribute(iterable, r" @attribute 'floupi 2' real ") ('floupi 2', 'real', 0) r<zmulti line not supported yetzFirst line unparsable: r) r` r_attributer>r@ r_comattrvaltokenize_single_commar r_wcomattrvaltokenize_single_wcommarBrr_read_relational_attribute)iterable attributesattrmattrrCrtype next_items rtokenize_attributersT OO E   e $E {{1~   d #.t4JD$XI   &/5JD$XI;< <25':;;T4(I zz||#-h 9M  i r c tj|}|rC |jdj}|jdj}||fSt d|#t$r}t d|d}~wwxYwNr<rz Error while tokenizing attributezError while tokenizing single )rr>r@r` IndexErrorrBvalrDrres rrr<s 3A H771:##%D771:##%D :9#?@@ H?@a G H>A)) B2 A>>Bc tj|}|rC |jdj}|jdj}||fSt d|#t$r}t d|d}~wwxYwr)rr>r@r`rrBrs rrrKs C A H771:##%D771:##%D :9#?@@ H?@a G Hrctjd|jzdz}|j|stj|}|rPt j|}|r+t ||\}}|jj|ntd|t|}|j|st|}|S)z4Read the nested attributes of a relational attributez^@[Ee][Nn][Dd]\s*z\s*$Error parsing line ) rrrr> r_headerlinerrrrrBr)ofilerelational_attributer3r_end_relationalrDisattrrs rrrZszz"6"6";";#<>E#FG$$Q'   q !  &&q)F,UA6a$//66t< #6qc!:;;U A$$Q' U A Hr c$t|}tj|r!t|}tj|r!d}g}tj|stj|}|r{t j|}|r!t ||\}}|j|nNtj|}|r|jd}ntd|t|}n t|}tj|s||fS)z&Read the header of the iterable ofile.Nr<r) r r_commentr> r_datametarrrr r_relationr@rB)rr3relationrrDrrisrels r read_headerrps U A //!  K //! HJq!   q !  &&q)F,UA6a!!$'"((+${{1~H$':1#%>??KU Aq!" Z r c4eZdZdZdZdZdZdZdZdZ y) raSmall container to keep useful information on a ARFF dataset. Knows about attributes names and types. Examples -------- :: data, meta = loadarff('iris.arff') # This will print the attributes names of the iris.arff dataset for i in meta: print(i) # This works too meta.names() # Getting attribute type types = meta.types() Methods ------- names types Notes ----- Also maintains the list of attributes in order, i.e., doing for i in meta, where meta is an instance of MetaData, will return the different attribute names in the order they were defined. c\||_|Dcic]}|j|c}|_ycc}wr)r _attributes)rrelrrs rrzMetaData.__init__s' /34!AFFAI44s)c"d}|d|jdz }|jD]j}|d|d|j|jz }|j|jr(|dt |j|jz }|dz }l|S)Nz Dataset: r z 's type is z , range is )rr r(rrLrPs r__repr__zMetaData.__repr__s 499+R((!! A Rs+d&6&6q&9&C&C%DE EC"((S)9)9!)<)B)B%C$DEE 4KC    r c,t|jSr)iterr r)s r__iter__zMetaData.__iter__sD$$%%r cP|j|}|j|jfSr)r r(r)rkeyrs r __getitem__zMetaData.__getitem__s%$ ++r c,t|jS)zReturn the list of attribute names. Returns ------- attrnames : list of str The attribute names. )rr r)s rnameszMetaData.namessD$$%%r cp|jDcgc]}|j|j}}|Scc}w)zReturn the list of attribute types. Returns ------- attr_types : list of str The attribute types. )r r()rr attr_typess rtypeszMetaData.typessC#'"2"24&&t,664 44s 3N) r r r __doc__rrrrrrr r rrrs%85&, & r rct|dr|}n t|} t|||ur|jSS#||ur|jwwxYw)a Read an arff file. The data is returned as a record array, which can be accessed much like a dictionary of NumPy arrays. For example, if one of the attributes is called 'pressure', then its first 10 data points can be accessed from the ``data`` record array like so: ``data['pressure'][0:10]`` Parameters ---------- f : file-like or str File-like object to read from, or filename to open. Returns ------- data : record array The data of the arff file, accessible by attribute names. meta : `MetaData` Contains information about the arff file such as name and type of attributes, the relation (name of the dataset), etc. Raises ------ ParseArffError This is raised if the given file is not ARFF-formatted. NotImplementedError The ARFF file has an attribute which is not supported yet. Notes ----- This function should be able to read most arff files. Not implemented functionality include: * date type attributes * string type attributes It can read files with numeric and nominal attributes. It cannot read files with sparse data ({} in the file). However, this function can read files with missing data (? in the file), representing the data points as NaNs. Examples -------- >>> from scipy.io import arff >>> from io import StringIO >>> content = """ ... @relation foo ... @attribute width numeric ... @attribute height numeric ... @attribute color {red,green,blue,yellow,black} ... @data ... 5.0,3.25,blue ... 4.5,3.75,green ... 3.0,4.00,red ... """ >>> f = StringIO(content) >>> data, meta = arff.loadarff(f) >>> data array([(5.0, 3.25, 'blue'), (4.5, 3.75, 'green'), (3.0, 4.0, 'red')], dtype=[('width', '>> meta Dataset: foo width's type is numeric height's type is numeric color's type is nominal, range is ('red', 'green', 'blue', 'yellow', 'black') read)hasattropen _loadarffclose)frs rrrsULq&Q > KKM 5> KKM s <Ac t|\} d} D]}t |t sd}t | }|r tdt  d fd }t||}tj| Dcgc]}|j|jfc}}||fS#t$r}dt|z}t||d}~wwxYwcc}w)Nz'Error while parsing header, error was: FTz*String attributes not supported yet, sorryc 3&Ktt}d}|D]l}tj|stj|r.t ||\}}t |Dcgc]}|j||c}nycc}wwr)rrrr>r_emptyr?rAr%) row_iterrrrrrr3rnis r generatorz_loadarff..generatorIsU2Y ECs#w}}S'9*38LCUCa++CF3CD D EDsAB"B B)r')rrBrLr isinstancernrNotImplementedErrorr1rrrrr) rr rrQhasstrrmetar(rjrr's @@rr r *s)& T F  a )F C D""NOO TBE8 Yu A 88A48a)8 9D :u )7#a&@S!q()r9sB(>C ( C1C  Cr)(rrnumpyrrr__all__rr_metarr%rrrrr=rrrOSErrorrrrr-rVrnrsrrrrr?rrrrrrrr r r rr1s  " A$ H  BJJu  "**X rzz+& RZZ- . RZZE F bjjNO BJJy ! < =rzz-.  ,-    Y 00)->f =  /)dFB J   , >GGTNb>r