
    #Yh\9              	         U d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZmZmZmZmZmZ d dlmc mZ d dlmZ d dlmZ d	d
lmZ d	dl m!Z!m"Z"m#Z#m$Z$m%Z% d	dl&m'Z' ej(        dk    r	d dlm)Z)m*Z* nd dl+m)Z)m*Z* ej(        dk    r	d dlm,Z,m-Z- nd dl+m,Z,m-Z- er8ej(        dk    rd dlm.Z. nd dl+m.Z. ej(        dk    rd dlm/Z/ nd dl+m/Z/ d dl0Z1d dl2Z3e* G d de)                      Z4ee5eef         ee4e!f         Z6de7d<    ede6          Z8 ede          Z9e5e:ee:e5eef         e;e5eef                  f         f         Z<de7d<   e5e:ee5eef         e;e5eef                  f         f         Z=de7d<   eee5e:ef         df         Z>ded Z? e-d!          Z@ ed"e<e          ZAee,e6e@f         eAf         ZB G d# d$e'eBeAf                   ZC G d% d&eD          ZEedfdgd-            ZFedhdid.            ZF	 djdkd2ZFe	 dldmd6            ZGe	 dfdnd7            ZGe	 dfdod9            ZG	 	 	 dpdqd;ZGed<         ZH G d= d>e          ZI G d? d@e          ZJe	 	 	 	 	 drdsdF            ZKe	 	 	 	 dtdudG            ZK	 	 	 	 	 dvdwdMZKe	 	 	 	 	 drdsdN            ZLe	 	 	 	 dtdxdP            ZL	 	 	 	 	 dydzdSZLd{dUZMd|dWZNd}dXZOd~dYZPdd[ZQdd^ZRdd_ZSdd`ZTdddZUdS )    )annotationsN)MutableMappingSequence)partial)Path)TYPE_CHECKINGAnyCallableLiteral	TypedDictTypeVarUnionoverload)is_pandas_dataframe)IntoDataFrame   )import_pyarrow_interchange)DataFrameLikesanitize_geo_interfacesanitize_narwhals_dataframesanitize_pandas_dataframeto_eager_narwhals_dataframe)PluginRegistry)      )Protocolruntime_checkable)r   
   )Concatenate	ParamSpec)TypeIs)	TypeAliasc                      e Zd ZU ded<   dS )SupportsGeoInterfacer   __geo_interface__N__name__
__module____qualname____annotations__     YD:\DownLoads\facial_attendance_system-main\venv311\Lib\site-packages\altair/utils/data.pyr$   r$   :   s         %%%%%%r,   r$   r"   DataType	TDataType)boundTIntoDataFrameVegaLiteDataDictToValuesReturnTypeobjr	   returnTypeIs[DataType]c                    t          | t          t          f          p.t          t          j        | dd          t          j                  S )NT)eager_or_interchange_onlypass_through)
isinstancedictr$   nwfrom_native	DataFrame)r4   s    r-   is_data_typer?   M   sD    cD"6788 J
sdNNN
= = r,   PRc                  P    e Zd ZddiZed
d            Zej        dd            Zd	S )DataTransformerRegistryconsolidate_datasetsTr5   boolc                    | j         d         S NrD   _global_settings)selfs    r-   rD   z,DataTransformerRegistry.consolidate_datasetsi   s    $%;<<r,   valueNonec                    || j         d<   d S rG   rH   )rJ   rK   s     r-   rD   z,DataTransformerRegistry.consolidate_datasetsm   s    8=4555r,   N)r5   rE   )rK   rE   r5   rL   )r'   r(   r)   rI   propertyrD   setterr+   r,   r-   rC   rC   f   sa        .5= = = X=  > > > ! > > >r,   rC   c                      e Zd ZdZdS )MaxRowsErrorz+Raised when a data model has too many rows.N)r'   r(   r)   __doc__r+   r,   r-   rQ   rQ   s   s        5555r,   rQ   .datarL   max_rows
int | Noner   c                    d S Nr+   rS   rT   s     r-   
limit_rowsrY   w   s    ILr,   c                    d S rW   r+   rX   s     r-   rY   rY   y   s    HKr,     DataType | Nonepartial | DataTypec                   | t          t                    S t          |            fd}t          | t                    r'| j        d         dk    r| j        d         }n=| j        }n5t          | t                    rd| v r	| d         }n| S t          |           } | }t          |          k    r
 |             | S )z
    Raise MaxRowsError if the data model has more than max_rows.

    If max_rows is None, then do not perform any check.
    N)rT   c                 .    d d} t          |           )NzHThe number of rows in your dataset is greater than the maximum allowed (aG  ).

Try enabling the VegaFusion data transformer which raises this limit by pre-evaluating data
transformations in Python.
    >> import altair as alt
    >> alt.data_transformers.enable("vegafusion")

Or, see https://altair-viz.github.io/user_guide/large_datasets.html for additional information
on how to plot large datasets.)rQ   )msgrT   s    r-   raise_max_rows_errorz(limit_rows.<locals>.raise_max_rows_error   s/    	-)1	- 	- 	- 	 3r,   typeFeatureCollectionfeaturesvalues)	r   rY   check_data_typer:   r$   r%   r;   r   len)rS   rT   ra   re   s    `  r-   rY   rY   {   s     |zH5555D          $,-- !&)-@@@+J7FF+FF	D$		 t(^FFK*400Fh 6 6Kr,   nfracfloat | Nonec                    d S rW   r+   rS   rh   ri   s      r-   samplerm      s	     cr,   c                    d S rW   r+   rl   s      r-   rm   rm      s	     Sr,   SampleReturnTypec                    d S rW   r+   rl   s      r-   rm   rm      s	     sr,   partial | SampleReturnTypec                   | t          t          ||          S t          |            t          |           r|                     ||          S t	          | t
                    r[d| v rU| d         }|s2|d}t          |          t          |t          |          z            }t          j        ||          }d|iS dS t          j        | d          } |s2|d}t          |          t          |t          |           z            }t          j        t          t          |                     |          }| |                                         S )zBReduce the size of the data model by sampling without replacement.N)rh   ri   re   z9frac cannot be None if n is None and data is a dictionaryT
eager_onlyz:frac cannot be None if n is None with this data input type)r   rm   rf   r   r:   r;   
ValueErrorintrg   randomr<   r=   range	to_native)rS   rh   ri   re   r`   indicess         r-   rm   rm      sP    |v....D4   {{QT{***	D$		 t(^F ,<UC$S//)s6{{*++]61--Ff%% 4>$4000D "<NCS//!s4yy !!mE#d)),,a00G=""$$$r,   )csvjsonc                      e Zd ZU ded<   dS )_FormatDict_FormatTyperb   Nr&   r+   r,   r-   r~   r~      s         r,   r~   c                  $    e Zd ZU ded<   ded<   dS )_ToFormatReturnUrlDictstrurlr~   formatNr&   r+   r,   r-   r   r      s'         HHHr,   r   prefixr   	extensionfilenameurlpathc                    d S rW   r+   rS   r   r   r   r   s        r-   to_jsonr      	     cr,   c                    d S rW   r+   r   s        r-   r   r      	     !Sr,   altair-datar|   {prefix}-{hash}.{extension}  partial | _ToFormatReturnUrlDictc                    t          ||||          }| t          t          fi |S t          |           }t	          |fi |dt          d          iS )zGWrite the data model to a .json file and return a url based data model.Nr   r|   rb   )_to_text_kwdsr   r   _data_to_json_string_to_textr~   rS   r   r   r   r   kwdsdata_strs          r-   r   r      sk     Hg>>D|w''$''''--JJDJJ&1I1I1IJJJJr,   c                    d S rW   r+   r   s        r-   to_csvr     r   r,   #dict | pd.DataFrame | DataFrameLikec                    d S rW   r+   r   s        r-   r   r     r   r,   r{   *dict | pd.DataFrame | DataFrameLike | Nonec                    t          ||||          }| t          t          fi |S t          |           }t	          |fi |dt          d          iS )zFWrite the data model to a .csv file and return a url based data model.Nr   r{   r   )r   r   r   _data_to_csv_stringr   r~   r   s          r-   r   r     sk     Hg>>D|v&&&&&&t,,IIDII%1H1H1HIIIIr,   r   c                    t          |           }|                    |||          }t          |                              | d           t	          t          ||                    }t          ||d          S )N)r   hashr   zutf-8)encoding)r   r   )_compute_data_hashr   r   
write_textr   r   )rS   r   r   r   r   r   	data_hashr   s           r-   r   r   ,  st     #4((If9	RRHNNdW555
d7H%%
&
&C!#"@"@AAAr,   dict[str, str]c                   | |||dS )Nr   r   r   r   r+   r   s       r-   r   r   ;  s    9(W^___r,   c                    t          |            t          j        | d          }t          |t                    rdt          |          iS t          |          r't          |          }d|                    d          iS t          |t                    rd|vrd}t          |          |S t          | t          j                  r't          |           } d|                     d          iS dt          |            }t          |          )	z0Replace a DataFrame by a data model with values.T)r9   re   records)orient.values expected in data dict, but not present.namedzUnrecognized data type: )rf   r<   ry   r:   r$   _from_geo_interfacer   r   to_dictr;   KeyErrorr>   r   rowsrb   ru   )rS   data_nativer`   s      r-   	to_valuesr   ?  s   D,t$777K+344 -k::;;	[	)	) /<<+--Y-??@@	K	&	& ;&&BC3--	D",	'	' *400$))$)//00 6d55oor,   c                f    t          |           s!dt          |            }t          |          d S )Nz@Expected dict, DataFrame or a __geo_interface__ attribute, got: )r?   rb   	TypeError)rS   r`   s     r-   rf   rf   W  s?     ]QUVZQ[Q[]]nn r,   r   c                    t          j        |                                                                           d d         S )N    )hashlibsha256encode	hexdigest)r   s    r-   r   r   `  s1    >(//++,,6688"==r,   SupportsGeoInterface | Anydict[str, Any]c                f    t          |           rt          |           } t          | j                  S )z
    Santize a ``__geo_interface__`` w/ pre-santize step for ``pandas`` if needed.

    Notes
    -----
    Split out to resolve typing issues related to:
    - Intersection types
    - ``typing.TypeGuard``
    - ``pd.DataFrame.__getattr__``
    )r   r   r   r%   )rS   s    r-   r   r   d  s2     4   /(..!$"8999r,   c                h   t          |            t          | t                    r!t          j        t          |                     S t          |           r&t          |           } |                     dd          S t          | t                    r1d| vrd}t          |          t          j        | d         d          S 	 t          j        | d          }n$# t          $ r}d	}t          |          |d
}~ww xY wt          |          }t          j        |                    d                    S )z6Return a JSON string representation of the input data.r      )r   double_precisionre   r   T)	sort_keysrs   zBto_json only works with data expressed as a DataFrame or as a dictNr   )rf   r:   r$   r|   dumpsr   r   r   r   r;   r   r<   r=   r   NotImplementedErrorr   r   )rS   r`   data_nwexcs       r-   r   r   t  s2   D$,-- 	:z-d33444	T	"	" :(..||9r|BBB	D$		 :4BC3--z$x.D99990.$777 0 0 0R!#&&C/0 *'22G:glll..///s   C 
C:#C55C:c                   t          |            t          | t                    r,dt          t                    j        d}t          |          t          |           r%t          |           } |                     d          S t          | t                    rsd| vrd}t          |          	 ddl}n$# t          $ r}d	}t          |          |d}~ww xY w|j                            | d                                       d          S 	 t          j        | d
          }n$# t"          $ r}d}t          |          |d}~ww xY w|                                S )z5Return a CSV string representation of the input data.z3to_csv does not yet work with data that is of type z0.
See https://github.com/vega/altair/issues/3441F)indexre   z-values expected in data dict, but not presentr   Nz4pandas is required to convert a dict to a CSV stringTrs   zAto_csv only works with data expressed as a DataFrame or as a dict)rf   r:   r$   rb   r'   r   r   r   r   r;   r   pandasImportErrorr>   	from_dictr<   r=   r   	write_csv)rS   r`   pdr   r   s        r-   r   r     s   D$,-- J>344=> > > 	
 "#&&&	T	"	" J(..{{{'''	D$		 	J4AC3--	, 	, 	, 	,HCc""+	, |%%d8n55<<5<III0.$777 0 0 0Q!#&&C/0 s0   0B5 5
C?CCD% %
E/EEdfi_dfr   pa.Tablec                    ddl }dD ]E}t          | |d          }t          |          r# |            }t          ||j                  r|c S Ft                      }|                    |           S )zMConvert a DataFrame Interchange Protocol compatible object to an Arrow Table.r   N)arrowto_arrowto_arrow_table
to_pyarrow)pyarrowgetattrcallabler:   Tabler   from_dataframe)r   paconvert_method_nameconvert_methodresultpis         r-   arrow_table_from_dfi_dataframer     s      U   )<dCCN## 	#^%%F&"(++ 	#	%	%BV$$$r,   )r4   r	   r5   r6   )..)rS   rL   rT   rU   r5   r   ).)rS   r.   rT   rU   r5   r.   )Nr[   )rS   r\   rT   rU   r5   r]   )...)rS   rL   rh   rU   ri   rj   r5   r   )rS   r1   rh   rU   ri   rj   r5   r1   )rS   r.   rh   rU   ri   rj   r5   ro   )NNN)rS   r\   rh   rU   ri   rj   r5   rq   ).....)rS   rL   r   r   r   r   r   r   r   r   r5   r   )....)rS   r.   r   r   r   r   r   r   r   r   r5   r   )Nr   r|   r   r   )rS   r\   r   r   r   r   r   r   r   r   r5   r   )rS   r   r   r   r   r   r   r   r   r   r5   r   )Nr   r{   r   r   )rS   r   r   r   r   r   r   r   r   r   r5   r   )rS   r   r   r   r   r   r   r   r   r   r   r~   r5   r   )
r   r   r   r   r   r   r   r   r5   r   )rS   r.   r5   r3   )rS   r.   r5   rL   )r   r   r5   r   )rS   r   r5   r   )rS   r.   r5   r   )r   r   r5   r   )V
__future__r   r   r|   rw   syscollections.abcr   r   	functoolsr   pathlibr   typingr   r	   r
   r   r   r   r   r   narwhals.stable.v1stablev1r<   narwhals.stable.v1.dependenciesr   narwhals.stable.v1.typingr   
_importersr   corer   r   r   r   r   plugin_registryr   version_infor   r   typing_extensionsr   r    r!   r"   r   r   r   r   r$   r;   r.   r*   r/   r1   r   listr2   r3   ro   r?   r@   rA   DataTransformerTyperC   	ExceptionrQ   rY   rm   r   r~   r   r   r   r   r   r   rf   r   r   r   r   r   r+   r,   r-   <module>r      s   " " " " " " "    



 4 4 4 4 4 4 4 4            	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	           ? ? ? ? ? ? 3 3 3 3 3 3 2 2 2 2 2 2              , + + + + +w222222222========w---------88888888 
7""!!!!!!!,,,,,,
7""$$$$$$$////// & & & & &8 & & & cNM#7F     GKx000	)???"sDcNDc3h$88	99      !%S%S#XT#s(^@T0T*U%U V  V V V VS(](;TAB    & IcNNGC!3''{8Q;7:; 	> 	> 	> 	> 	>n-@!-CD 	> 	> 	>6 6 6 6 69 6 6 6 
 L L L L 
 L	 K K K K 
 K9=, , , , ,^ 
@C    
 
DG    
 
>A    
 !% % % % %D m$    )       Y   
 
    
 
 ! ! ! ! 
! !1K K K K K  
    
 
 ! ! ! ! 
! 8<1J J J J J B B B B` ` ` `   0   > > > >: : : : 0 0 0 0,   >% % % % % %r,   