
    gf              	      x   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ d	gZd
dej"                  iiZd
dej&                  iiZd ZddZ e
j                          e
j.                  ddd       e
j.                  dddd       e
j.                  dddd      dd                            Zy)z7Magic functions for rendering vega-lite specifications.    )annotationsN)	find_spec)Any)magic_arguments)is_pandas_dataframe)v5vegalite	vega-lite5c                    | t        | t              r| S t        |       r|j                         x}r ||       } | S t        | t              rd| iS t        j                  dt        |        dd       | S )z1Convert input data to data for use within schema.urlzdata of type z not recognized   )
stacklevel)
isinstancedictr   getstrwarningswarntype)datadata_transformersfuncs      C/var/www/openai/venv/lib/python3.12/site-packages/altair/_magics.py_prepare_datar      ss    |z$-	T	"$((**4*:D	D#	t}d4j\AaP    c                    ddl m}  |       x}r.| |j                  vrd|  d}t        |      |j                  |    S d}t	        |      )z+Get a variable from the notebook namespace.r   )get_ipythonz
argument 'z1' does not match the name of any defined variablez[Magic command must be run within an IPython environment, in which get_ipython() is defined.)IPython.core.getipythonr   user_ns	NameError
ValueError)namer   ipmsgs       r   _get_variabler&   .   s\    3]rrzz!tf$UVCC. zz$> 	 o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                2   t        j                  t        |       }ddi}||j                     }|t        d   v sJ t        d   |   }t
        d   |   }|j                  rt        j                  |      }nCt        d      s	 t        j                  |      }n!ddl}
|
j                  ||
j                        }|j                  $t        |j                        }t!        ||      |d	<    ||      S # t        j                  $ r}d}	t        |	      |d}~ww xY w)
aM  
    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
   yamlzH%%vegalite: spec is not valid JSON. Install pyyaml to parse spec as yamlNr   )Loaderr   )r   parse_argstringr	   r*   	RENDERERSTRANSFORMERSr-   loadsr   JSONDecodeErrorr"   r1   load
SafeLoaderr   r&   r   )linecellargsexisting_versionsr*   VegaLiter   specerrr%   r1   r   s               r   r	   r	   ?   s   & **8T:Ds-Gi,,,,%g.H$[1':yyzz$v	+::d#D 	yydooy6yyTYY'$T+<=VD> ## 	+7  S/s*	+s   C0 0DDD)r#   r   returnr   )rA   zvegalite_v5.VegaLite)__doc__
__future__r   r-   r   importlib.utilr   typingr   IPython.corer   narwhals.stable.v1.dependenciesr   altair.vegaliter   vegalite_v5__all__r>   r4   r   r5   r   r&   argumentr	    r   r   <module>rM      s    = "   $  ( ? -, [!!	 [**" !  "

	M
 $)TJ$vlK& L K #&r   