
    d/              	          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 	 ddlZdZn# e$ r dZY nw xY wd	d
ej        iiZd	d
ej        iiZd Zd Z ej                     ej        ddd           ej        dddd           ej        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                 X   | t          | t                    r| S t          | t          j                  r't	          j        | |                                          S t          | t                    rd| iS t          j	        d
                    t          |                     d           | S )z0Convert input data to data for use within schemaNurlzdata of type {} not recognized   )
stacklevel)
isinstancedictpd	DataFramer   pipegetstrwarningswarnformattype)datadata_transformerss     .lib/python3.11/site-packages/altair/_magics.py_prepare_datar   &   s    |z$--|	D",	'	' |D"3"7"7"9"9:::	D#		 t}6==d4jjIIVWXXXX    c                     t          j                    }|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 environemnt, in which get_ipython() is defined.z=argument '{}' does not match the name of any defined variable)IPythonget_ipython
ValueErroruser_ns	NameErrorr   )nameips     r   _get_variabler%   3   sl    				B	z>
 
 	
 2:++16$<<
 
 	
 :d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                 8   t          j        t          |           }ddi}||j                 }|t          d         v sJ t          d         |         }t
          d         |         }|j        rt          j        |          }ndt          s=	 t          j        |          }nG# t          j	        $ r}t          d          |d}~ww xY wt          j        |t          j                  }|j        't          |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   parse_argstringr   r)   	RENDERERSTRANSFORMERSr,   loadsYAML_AVAILABLEJSONDecodeErrorr    yamlload
SafeLoaderr   r%   r   )
linecellargsexisting_versionsr)   VegaLiter   specerrr   s
             r   r   r   C   s)   $ *8T::Ds-Gi,,,,,%g.H$[1':y 7z$ 	7	:d##DD# 	 	 	7  	 ydo666yTY''$T+<==V8D>>s   B C +B;;C )__doc____all__r,   r   r   IPython.corer   pandasr   toolzr   altair.vegaliter   vegalite_v5r7   r5   ImportErrorr>   r2   r   r3   r   r%   argumentr    r   r   <module>rK      s    ,    ( ( ( ( ( (           - - - - - -KKKNN   NNN
 [!	 [*
 
 
    ! ""

	M  
 $)TJJJ$vlKKK" " LK KJ  #"" " "s   0 ::