L i%|UddlmZddlZddlmZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZmZmZmZdd lmZer2ddlZdd l m!Z!dd l"m#Z#ddl$m%Z%ejLdk\rddlm'Z'nddl(m'Z'eZ)de*d<dZ+de*d< eedZ,de*d<e,rede,krd(dZ.nd(dZ.Gdde Z/e e/efZ0e d) d*dZ1e d+ d,dZ1e d+ d-d Z1 d. d/d!Z1d0d"Z2d1d#Z3 d2d$Z4d3d%Z5d4d&Z6d5d'Z7y#e-$rdZ,YwxYw)6) annotationsN)version) TYPE_CHECKINGAnyCallableFinal TypedDictUnionoverload)WeakValueDictionary)is_into_dataframe)Version)import_vegafusion) DataFrameLike)DataType MaxRowsErrorSupportsGeoInterfaceToValuesReturnType)default_data_transformer)MutableMapping) IntoDataFrame) ChartState) )TypeIsz"MutableMapping[str, DataFrameLike]extracted_inline_tableszvegafusion+dataset://rVEGAFUSION_PREFIX vegafusionzVersion | NoneVEGAFUSION_VERSIONz2.0.0a0c<t|txs t|SN) isinstancerr datas c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/altair/utils/_vegafusion_data.pyis_supported_by_vfr&6s$ .I2CD2IIc"t|tSr!)r"rr#s r%r&r&=s$ ..r'ceZdZUded<y)_ToVegaFusionReturnUrlDictstrurlN)__name__ __module__ __qualname____annotations__r'r%r*r*As Hr'r*cyr!r1r$max_rowss r%vegafusion_data_transformerr5Hr'cyr!r1r3s r%r5r5Nr6r'cyr!r1r3s r%r5r5Ts r'c|tSt|rKt|ts;dt j j dd}|t|<dt|ziSt|S)zVegaFusion Data Transformer.table_-_r,) r5r&r"ruuiduuid4replacerrr)r$r4 table_names r%r5r5Zsi |**$ 49M(Ndjjl^,44S#> .2 +(:566 (--r'c@t}|jdgD]M}|jdd}|jts+|t td}|j |O|jdgD]}|j t||S)a Get a set of the inline datasets names in the provided Vega spec. Inline datasets are encoded as URLs that start with the table:// prefix. Parameters ---------- vega_spec: dict A Vega specification dict Returns ------- set of str Set of the names of the inline datasets that are referenced in the specification. Examples -------- >>> spec = { ... "data": [ ... {"name": "foo", "url": "https://path/to/file.csv"}, ... {"name": "bar", "url": "vegafusion+dataset://inline_dataset_123"}, ... ] ... } >>> get_inline_table_names(spec) {'inline_dataset_123'} r$r,Nmarks)setget startswithrlenaddupdateget_inline_table_names) vega_spec table_namesr$r,namemarks r%rJrJls:%K fb)"hhub! >>+ ,s,-/0D OOD ! " gr*91$789 r'ct|}|jt}|Dcic]}|tj|c}Scc}w)a& Get the inline tables referenced by a Vega specification. Note: This function should only be called on a Vega spec that corresponds to a chart that was processed by the vegafusion_data_transformer. Furthermore, this function may only be called once per spec because the returned dataframes are deleted from internal storage. Parameters ---------- vega_spec: dict A Vega specification dict Returns ------- dict from str to dataframe dict from inline dataset name to dataframe object )rJ intersectionrpop)rK inline_namesrLks r%get_inline_tablesrTsF&*)4L++,CDK7B C!A&**1- - CC CsAc8ddlm}m}t}|j }| d}t |||}t |}|jj dd} |jj|||| } t| | j| S)ax Compile a Vega-Lite spec to a VegaFusion ChartState. Note: This function should only be called on a Vega-Lite spec that was generated with the "vegafusion" data transformer enabled. In particular, this spec may contain references to extract datasets using table:// prefixed URLs. Parameters ---------- vegalite_spec: dict A Vega-Lite spec that was generated from an Altair chart with the "vegafusion" data transformer enabled local_tz: str Local timezone name (e.g. 'America/New_York') Returns ------- ChartState A VegaFusion ChartState object rdata_transformersvegalite_compilersN)No active vega-lite compiler plugin foundr4)local_tzinline_datasets row_limit) altairrWrXrrE ValueErrorrToptionsruntimenew_chart_statehandle_row_limit_exceeded get_warnings) vegalite_specrZrWrXvfcompilermsgrK inline_tablesr\ chart_states r%!compile_to_vegafusion_chart_staterjs2=  B"%%'H9o'I&i0M"))--j$?I**,,% -Ki)A)A)CD r'c>ddlm}m}t}|j }| d}t |||}t |}|jj dd}|jj||j||\} } t|| | S)aR Compile a Vega-Lite spec to Vega and pre-transform with VegaFusion. Note: This function should only be called on a Vega-Lite spec that was generated with the "vegafusion" data transformer enabled. In particular, this spec may contain references to extract datasets using table:// prefixed URLs. Parameters ---------- vegalite_spec: dict A Vega-Lite spec that was generated from an Altair chart with the "vegafusion" data transformer enabled Returns ------- dict A Vega spec that has been pre-transformed by VegaFusion rrVNrYr4)r[r\) r]rWrXrrEr^rTr_r`pre_transform_spec get_local_tzrb) rdrWrXrerfrgrKrhr\transformed_vega_specwarningss r%compile_with_vegafusionrps*=  B"%%'H9o'I&i0M"))--j$?I&(jj&C&C % 'D'#8i2  r'c\|D]'}|jddk(sd|d}t|y)NtypeRowLimitExceededzXThe number of dataset rows after filtering and aggregation exceeds the current limit of z. Try adding an aggregation to reduce the size of the dataset that must be loaded into the browser. Or, disable the limit by calling alt.data_transformers.disable_max_rows(). Note that disabling this limit may cause the browser to freeze or crash.)rEr)r\rowarningrgs r%rbrbsK $ ;;v "4 4((1{3QQ s# # $r'c,ddlm}|jdk(S)z9Check whether the vegafusion data transformer is enabled.rrWr)r]rWactivervs r%using_vegafusionrx+s)  # #| 33r')r$rreturnzTypeIs[DataFrameLike])..)r$Noner4intryzCallable[..., Any]).)r$rr4r{ryr)r$z+dict | IntoDataFrame | SupportsGeoInterfacer4r{ry_VegaFusionReturnType)Ni)r$zDataType | Noner4r{ryz*Callable[..., Any] | _VegaFusionReturnType)rKdict[str, Any]ryzset[str])rKr}ryzdict[str, DataFrameLike])rdr}rZr+ryr)rdr}ryr})r\r{rolist)rybool)8 __future__rr=importlib.metadatarimportlib_versiontypingrrrrr r r weakrefr narwhals.stable.v1.dependenciesr packaging.versionraltair.utils._importersraltair.utils.coreraltair.utils.datarrrraltair.vegalite.datarsyscollections.abcrnarwhals.stable.v1.typingrvegafusion.runtimer version_infortyping_extensionsrr0rr ImportErrorr&r*r|r5rJrTrjrprbrxr1r'r%rs" ;RRR'=%5+ :.7- 7"!, ?R>S;S 352)01B<1P)QQ '),0BBJ/  8:LLM &)  #   ), #&   GJ 5 AD    39. .,/./.$*ZD45!5-055p0!f $4wsD11D;:D;