a
    d/                  	   @   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yt   dZY n0 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   sd   | du st | tr| S t | tjr2t| | S t | trDd| iS tj	d
t| dd | S 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   W/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/altair/_magics.py_prepare_data&   s    
r   c                 C   s:   t  }|du rtd| |jvr0td| |j|  S )z+Get a variable from the notebook namespace.Nz[Magic command must be run within an IPython environemnt, in which get_ipython() is defined.z=argument '{}' does not match the name of any defined variable)IPythonZ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rXt|}nVtszt|}W q tj	y } zt
d|W Y d}~qd}~0 0 ntj|tjd}|jdurt|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   C   s,    


)__doc____all__r&   r   r   ZIPython.corer   Zpandasr   Ztoolzr   Zaltair.vegaliter   Zvegalite_v5r/   r-   ImportErrorr4   r*   r   r+   r   r   argumentr   r   r   r   r   <module>   s@   
