o
    e                  	   @   s   d Z dgZddlZddlZddlZddlmZ ddlZddl	m
Z
 ddlmZ zddlZdZW n ey:   dZY nw d	d
ejiiZd	d
ejiiZdd Zdd Ze ejddddejdddddejddddddd ZdS )z8
Magic functions for rendering vega-lite specifications
vegalite    N)magic_arguments)curried)v5TF	vega-lite5c                 C   s`   | du s	t | tr| S t | tjrt| | S t | tr"d| iS tj	d
t| dd | S )z0Convert input data to data for use within schemaNurlzdata of type {} not recognized   )
stacklevel)
isinstancedictpdZ	DataFramer   pipegetstrwarningswarnformattype)datadata_transformers r   N/root/Voice_Assist/myprojectenv/lib/python3.10/site-packages/altair/_magics.py_prepare_data&   s   
r   c                 C   s:   t  }|du rtd| |jvrtd| |j|  S )z+Get a variable from the notebook namespace.Nz[Magic command must be run within an IPython environment, in which get_ipython() is defined.z=argument '{}' does not match the name of any defined variable)IPythonget_ipython
ValueErrorZuser_ns	NameErrorr   )nameipr   r   r   _get_variable3   s   

r    r   ?zBlocal variablename of a pandas DataFrame to be used as the dataset)nargshelpz-vz	--versionversionr   )destdefaultz-jz--jsonjson
store_true)r%   actionc           
   
   C   s   t t| }ddi}||j }|td v sJ td | }td | }|jr,t|}n$tsHzt|}W n tj	yG } zt
d|d}~ww tj|tjd}|jdurat|j}	t|	||d< ||S )aH  Cell magic for displaying vega-lite visualizations in CoLab.

    %%vegalite [dataframe] [--json] [--version='v5']

    Visualize the contents of the cell using Vega-Lite, optionally
    specifying a pandas DataFrame object to be used as the dataset.

    if --json is passed, then input is parsed as json rather than yaml.
    r   r   r   zH%%vegalite: spec is not valid JSON. Install pyyaml to parse spec as yamlN)Loaderr   )r   Zparse_argstringr   r$   	RENDERERSTRANSFORMERSr'   loadsYAML_AVAILABLEJSONDecodeErrorr   yamlloadZ
SafeLoaderr   r    r   )
linecellargsZexisting_versionsr$   VegaLiter   specerrr   r   r   r   r   B   s0   


)__doc____all__r'   r   r   ZIPython.corer   Zpandasr   Ztoolzr   Zaltair.vegaliter   Zvegalite_v5r0   r.   ImportErrorr5   r+   r   r,   r   r    argumentr   r   r   r   r   <module>   sD    