*L ilB ,ddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z dZdZdZdZd Zd Zd Zd Zd ZdddddddddZdZdZdZdZGddej8ZGddeZdZ d Z!d)d!Z"d"Z#d#Z$d$Z%d*d%Z&d)d&Z'd'Z(d(Z)y)+Nreduce) get_module)ImageUriValidatorcopy_to_readonly_numpy_arrayis_homogeneous_arrayiiiiiili1u1i2u2i4u4f4f8)int8uint8int16uint16int32uint32float32float64ct|}tdd}|r%t||jr|jdk(r|St |j }|dk(r|j}|j}|tkr|tk\r|jd}n|tkr|tk\r|jd}n|tkr|tk\r|jd}n|S|d k(r|j}|j}|t kr|dk\r|jd }nB|t"kr|dk\r|jd }n"|t$kr|dk\r|jd }n|St |j }|t&vrZt&|t)j*|j-d d}|j.dkDrt |j0dd|d<|S|S)zi Convert numpy array to plotly.js typed array spec If not possible return the original value numpyF should_loadrint64rrruint64rrrascii)dtypebdatashape)rr isinstancendarraysizestrr"maxminint8maxint8minastypeint16maxint16minint32maxint32minuint8max uint16max uint32maxplotlyjsShortTypesbase64 b64encodedecodendimr&)vnpr"r+r,arrObjs Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/_plotly_utils/utils.pyto_typed_array_specr@'s %Q'A G /B Z2::.!&&A+ LE eegeeg '>cWn A H_!A H_!AH ( eegeeg (?sax!A I #("A I #("AH LE ""'.%%a(//8  66A:!!''l1R0F7O Hc4gd}tfd|DS)zR Return whether the key is skipped for conversion to the typed array spec )geojsonlayerlayersrangec3(K|] }|k( ywN).0 skipped_keykeys r? z!is_skipped_key..dsBk{c!Bs)any)rL skipped_keyss` r?is_skipped_keyrP_s;L B\B BBrAct|trJ|jD]6\}}t|rt |rt |||<,t |8yt|tst|tr|D] }t |yyrH) r'dictitemsrPrr@convert_to_base64listtuple)objrLvalues r?rTrTgs#t))+ )JCc"%e,.u5C!%(  ) C *S%"8 %E e $ %#9rAc&d}t||g}|S)z0 Custom cumsum to avoid a numpy import. c<t|dk(r|gS||d|zgzSNrr%)len)axs r?_reducerzcumsum.._reducerzs( q6Q;3JAbEAI;rAr)r^r_rets r?cumsumraus  1b !C JrAceZdZdZdZfdZdZedZedZ edZ edZ ed Z ed Z ed Zed Zed ZxZS)PlotlyJSONEncodera9 Meant to be passed as the `cls` kwarg to json.dumps(obj, cls=..) See PlotlyJSONEncoder.default for more implementation information. Additionally, this encoder overrides nan functionality so that 'Inf', 'NaN' and '-Inf' encode to 'null'. Which is stricter JSON than the Python version. c|dvry|S)zU This is used to ultimately *encode* into strict JSON, see `encode` )Infinityz -InfinityNaNNrI)selfconsts r?coerce_to_strictz"PlotlyJSONEncoder.coerce_to_stricts 4 4LrAc8tt| |}d|vsd|vs|S tj||j }tj ||j|j|j|jfS#t$r tdwxYw)z Load and then dump the result using parse_constant kwarg Note that setting invalid separators will cause a failure at this step. rfre)parse_constant) sort_keysindent separatorszSEncoding into strict JSON failed. Did you set the separators valid JSON separators?) superrcencode_jsonloadsridumpsrlrmitem_separator key_separator ValueError)rgo encoded_onew_o __class__s r?rpzPlotlyJSONEncoder.encodes+T9!< "jI&=   KK $:O:OPE;;..{{ //1C1CD   )  s !BBc L|j|j|j|j|j|j |j |j|jf }|D] } ||cStjj||S#t$rY:wxYw)a Accept an object (of unknown type) and try to encode with priority: 1. builtin: user-defined objects 2. sage: sage math cloud 3. pandas: dataframes/series 4. numpy: ndarrays 5. datetime: time/datetime objects Each method throws a NotEncoded exception if it fails. The default method will only get hit if the object is not a type that is naturally encoded by json: Normal objects: dict object list, tuple array str, unicode string int, long, float number True true False false None null Extended objects: float('nan') 'NaN' float('infinity') 'Infinity' float('-infinity') '-Infinity' Therefore, we only anticipate either unknown iterables or values here. ) encode_as_plotlyencode_as_sageencode_as_numpyencode_as_pandasencode_as_datetimeencode_as_dateencode_as_listencode_as_decimal encode_as_pil NotEncodablerq JSONEncoderdefault)rgrWencoding_methodsencoding_methods r?rzPlotlyJSONEncoder.defaultsB  ! !      ! !  # #        " "      0 O &s++    ((s33   s,B B#"B#cJ |jS#t$rtwxYw)z1Attempt to use a builtin `to_plotly_json` method.)to_plotly_jsonAttributeErrorrrWs r?r|z"PlotlyJSONEncoder.encode_as_plotlys+ %%' '   "cFt|dr|jSt)z@Attempt to use `tolist` method to convert to normal Python list.tolist)hasattrrrrs r?rz PlotlyJSONEncoder.encode_as_lists  3 !::<  rActd}|st||jvr t|S||jvr t |St)z@Attempt to convert sage.all.RR to floats and sage.all.ZZ to intszsage.all)rrRRfloatZZint)rWsage_alls r?r}z PlotlyJSONEncoder.encode_as_sagesHj)  (++ :  HKK s8O rActdd}|st||juryt|dr||juryt)z)Attempt to convert pandas.NaT / pandas.NApandasFrNNA)rrNaTrr)rWrs r?rz"PlotlyJSONEncoder.encode_as_pandassHH%8  &**  64 SFII%5rAcXtdd}|st||jjjur t dSt ||jr9|jjdk(r |j|jSt#t$rYtwxYw)z'Attempt to convert numpy.ma.core.maskedrFrnanM) rrmacoremaskedrr'r(r"kinddatetime_as_stringr TypeError)rWrs r?r~z!PlotlyJSONEncoder.encode_as_numpys76  %((--&& &<  U]] + #0E //4;;==  s3B B)(B)cJ |jS#t$rtwxYw)z.Convert datetime objects to iso-format strings) isoformatrrrs r?rz$PlotlyJSONEncoder.encode_as_datetime/s( ==? "   rc` |j}t|S#t$rtwxYw)z=Attempt to convert to utc-iso time string using date methods.)riso_to_plotly_time_stringrr)rW time_strings r?rz PlotlyJSONEncoder.encode_as_date7s6 :--/K-[9 9   s-cXt|tjr t|St)z3Attempt to encode decimal by converting it to float)r'decimalDecimalrrrs r?rz#PlotlyJSONEncoder.encode_as_decimalAs" c7?? +:  rAc~td}|+t||jrtj|St )z5Attempt to convert PIL.Image.Image to base64 data uriz PIL.Image)rr'Imagerpil_image_to_urir)rWimages r?rzPlotlyJSONEncoder.encode_as_pilIs8;'  C!=$55c: : rA)__name__ __module__ __qualname____doc__rirpr staticmethodr|rr}rr~rrrr __classcell__)rzs@r?rcrcs  "H04d     ::rArcc eZdZy)rN)rrrrIrAr?rrSsrArc"|jddddk(s|jdddk(r td|jdd jd d }|jd r|jd d S|jd d S)z=Remove timezone info and replace 'T' delimeter with ' ' (ws).-Nz00:00+rz]Plotly won't accept timestrings with timezone info. All timestrings are assumed to be in UTC.z-00:00z+00:00z T00:00:00T )split Exceptionreplaceendswith) iso_strings r?rrWs bq!W,*2B2B32G2Jg2U 8  ##Hb199(BGJ;'!!+r22!!#s++rAc fd}|S)Nctjdddk(s-|j!|jjdi|_|S)N)rrrI)sys version_inforformat)funcnamess r? _decoratorz template_doc.._decoratorisB#v-||'2t||22;U;  rArI)rrs` r? template_docrhs rAc$d}t|||S)Nctjd|}tt|D]} t ||||<t |S#t $rY-wxYw)Nz(\d+))rerrFr\rrvrV)r<v_partsis r?rLz"_natural_sort_strings..keyss`((8Q's7|$ A  _   W~  sA  AA)rLreversesorted)valsrrLs r?_natural_sort_stringsrrs $C 11rAcZtdd}|rt|jf}|Stf}|S)NrFr)rrinteger)r=int_types r? _get_int_typers4 G /B $ O6 OrAct|dk(r|S|jtdtfd|}t ||S)ar Split all the strings in ss at any of the characters in chars. Example: >>> ss = ["a.string[0].with_separators"] >>> chars = list(".[]_") >>> split_multichar(ss, chars) ['a', 'string', '0', '', 'with', 'separators'] :param (list) ss: A list of strings. :param (list) chars: Is a list of chars (note: not a string). rc ||zSrHrI)r^ys r?z!split_multichar..s QUrAc&|jSrH)r)r^cs r?rz!split_multichar..s!''!*rA)r\poprmapsplit_multichar)sscharsrs @r?rrsB 5zQ  A "C(>> ss = ["a.string[0].with_separators"] >>> chars = list(".[]_") >>> ss_split = split_multichar(ss, chars) >>> ss_split ['a', 'string', '0', '', 'with', 'separators'] >>> split_string_positions(ss_split) [0, 2, 9, 11, 12, 17] :param (list) ss: A list of strings. c|d|dzS)Nrr$rI)ts r?rz(split_string_positions..sadQqTkrArNr%)rUrziprFr\ra)rs r?split_string_positionsrsL"  ! c"gsT#c2cr72C-D'D E F  rAc,tt|dz|z|zDcgc]}d}}d}|%|D]} t|D]} | |z| z}|||<!n t|D]} |||z| z}|||<dj|} |r| d|dz} | Scc}w)a Return a string that is whitespace except at p[i] which is replaced with char. If i is None then all the indices of the string in p are replaced with char. Example: >>> ss = ["a.string[0].with_separators"] >>> chars = list(".[]_") >>> ss_split = split_multichar(ss, chars) >>> ss_split ['a', 'string', '0', '', 'with', 'separators'] >>> ss_pos = split_string_positions(ss_split) >>> ss[0] 'a.string[0].with_separators' >>> display_string_positions(ss_pos,4) ' ^' >>> display_string_positions(ss_pos,4,offset=1,length=3,char="~",trim=False) ' ~~~ ' >>> display_string_positions(ss_pos) '^ ^ ^ ^^ ^' :param (list) p: A list of integers. :param (integer|None) i: Optional index of p to display. :param (integer) offset: Allows adding a number of spaces to the replacement. :param (integer) length: Allows adding a replacement that is the char repeated length times. :param (str) char: allows customizing the replacement character. :param (boolean) trim: trims the remaining whitespace if True. r$rrNr)rFr+join) proffsetlengthchartrim_smaxaddrp_tempr`s r?display_string_positionsrs:CFQJ/&89::A:Gy "Bf  "v+,!'  " " &M DdVmd*GAgJ  ''!*C -GaK  J ;s Bc d}|r|t|||St|s|Sttt|dk(r|t|dz zgSGdd}t t tt |||dgS)a Given a list of strings, some of which are the empty string "", replace the empty strings with c and combine them with the closest non-empty string on the left or "" if it is the first string. Examples: for c="_" ['hey', '', 'why', '', '', 'whoa', '', ''] -> ['hey_', 'why__', 'whoa__'] ['', 'hi', '', "I'm", 'bob', '', ''] -> ['_', 'hi_', "I'm", 'bob__'] ['hi', "i'm", 'a', 'good', 'string'] -> ['hi', "i'm", 'a', 'good', 'string'] Some special cases are: [] -> [] [''] -> [''] ['', ''] -> ['_'] ['', '', '', ''] -> ['___'] If reverse is true, empty strings are combined with closest non-empty string on the right or "" if it is the last string. cD|Dcgc] }|ddd c}dddScc}w)Nr%rI)rrs r?_revz!chomp_empty_strings.._revs'!%&A$B$&tt,,&srr$ceZdZdZdZy)%chomp_empty_strings.._Chomperc||_yrH)r)rgrs r?__init__z.chomp_empty_strings.._Chomper.__init__s DFrAc\t|dk(r|dd|d|jzgzS||gzSr[)r\r)rgr^rs r?__call__z.chomp_empty_strings.._Chomper.__call__s: 1v{"v2 000A3wrAN)rrrrrrIrAr?_Chomperrs   rArr)chomp_empty_stringsr\sumrrUfilterr)stringsrrrrs r?rrs&-'W q9:: w< 3sG "S\A%&''   sF8A;">? @@rAc t|t|kr t||St|dk(r t|Stt|dz}t|D]Z\}}|dzg}t|D]?\}}||dzdz}||dz} ||||k7z} |j t || | A|}\|dS)Nrr$r%)r\ levenshteinrF enumerateappendr,) s1s2 previous_rowrc1 current_rowjc2 insertions deletions substitutionss r?rrs 2wR2r"" 2w!|2wR1%L2 #21ug r] JEAr&a!e,q0J#A*I(OrRx8M   s:y-H I  J#  #  rAc.fd}t||dS)Nc t||fSrH)r)rstrings r?_keyz!find_closest_string.._key(sAv&**rA)rLrr)rrrs` r?find_closest_stringr's+ 't $Q ''rA)F)Nrr$^T)*r8rjsonrqrr functoolsr_plotly_utils.optional_importsr_plotly_utils.basevalidatorsrrrr.r-r1r0r3r2r4r5r6r7r@rPrTrarrcrrrrrrrrrrrrrIrAr?rs  5               5 pC % M))M` 9 ," 2&(2+\+A`&(rA