
    ch\9              	      0   % S SK Jr  S SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
  S SKJr  S SKJrJrJrJrJrJrJrJr  S SKJs  Jr  S SKJr  S SKJr  S	S
KJr  S	SK J!r!J"r"J#r#J$r$J%r%  S	SK&J'r'  \RP                  S:  a	  S SKJ)r)J*r*  OS SK+J)r)J*r*  \RP                  S:  a	  S SKJ,r,J-r-  OS SK+J,r,J-r-  \(       aB  \RP                  S:  a  S SKJ.r.  OS SK+J.r.  \RP                  S:  a  S SKJ/r/  OS SK+J/r/  S SK0r1S SK2r3\* " S S\)5      5       r4\\5\\4   \\4\!4   r6S\7S'   \" S\6S9r8\" S\S9r9\5\:\\:\5\\4   \;\5\\4      4   4   r<S\7S'   \5\:\\5\\4   \;\5\\4      4   4   r=S\7S'   \\\5\:\4   S4   r>S>S jr?\-" S5      r@\" S\<\5      rA\\,\6\@4   \A4   rB " S S \'\B\A4   5      rC " S! S"\D5      rE\S?S@S# jj5       rF\SASBS$ jj5       rF SC     SDS% jjrF\ SE       SFS& jj5       rG\ S?       SGS' jj5       rG\ S?       SHS( jj5       rG   SI       SJS) jjrG\S*   rH " S+ S,\5      rI " S- S.\5      rJ\     SK           SLS/ jj5       rK\    SM           SNS0 jj5       rK     SO           SPS1 jjrK\     SK           SLS2 jj5       rL\    SM           SQS3 jj5       rL     SR           SSS4 jjrL              STS5 jrMSUS6 jrNSVS7 jrOSWS8 jrPSXS9 jrQSYS: jrRSZS; jrSSZS< jrTS[S= jrUg)\    )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                       \ rS rSr% S\S'   Srg)SupportsGeoInterface:   r   __geo_interface__ N__name__
__module____qualname____firstlineno____annotations____static_attributes__r'       dC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\altair/utils/data.pyr$   r$   :   s    %%r/   r$   r"   DataType	TDataType)boundTIntoDataFrameVegaLiteDataDictToValuesReturnTypec                    [        U [        [        45      =(       d.    [        [        R                  " U SSS9[        R
                  5      $ )NT)eager_or_interchange_onlypass_through)
isinstancedictr$   nwfrom_native	DataFrame)objs    r0   is_data_typer@   M   s:    cD"678 J
sdN
= r/   PRc                  X    \ rS rSrSS0r\SS j5       r\R                  S	S j5       rSrg)
DataTransformerRegistryf   consolidate_datasetsTc                     U R                   S   $ NrF   _global_settings)selfs    r0   rF   ,DataTransformerRegistry.consolidate_datasetsi   s    $$%;<<r/   c                     XR                   S'   g rH   rI   )rK   values     r0   rF   rL   m   s    8=45r/   r'   N)returnbool)rN   rP   rO   None)	r)   r*   r+   r,   rJ   propertyrF   setterr.   r'   r/   r0   rD   rD   f   s9    .5= =   > !>r/   rD   c                      \ rS rSrSrSrg)MaxRowsErrors   z+Raised when a data model has too many rows.r'   N)r)   r*   r+   r,   __doc__r.   r'   r/   r0   rU   rU   s   s    5r/   rU   c                    g Nr'   datamax_rowss     r0   
limit_rowsr]   w   s    ILr/   c                    g rY   r'   rZ   s     r0   r]   r]   y   s    HKr/   c                h  ^ U c  [        [        TS9$ [        U 5        U4S jn[        U [        5      (       a0  U R
                  S   S:X  a  U R
                  S   nO=U R
                  nO0[        U [        5      (       a  SU ;   a  U S   nOU $ [        U 5      n U nTb  [        U5      T:  a  U" 5         U $ )zs
Raise MaxRowsError if the data model has more than max_rows.

If max_rows is None, then do not perform any check.
)r\   c                 &   > ST S3n [        U 5      e)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.)rU   )msgr\   s    r0   raise_max_rows_error(limit_rows.<locals>.raise_max_rows_error   s)    ))1
 3-	- 	 3r/   typeFeatureCollectionfeaturesvalues)	r   r]   check_data_typer:   r$   r&   r;   r   len)r[   r\   rb   rg   s    `  r0   r]   r]   {   s     |zH55D  $,--!!&)-@@++J7F++F	D$		t(^FK*40Fh 6Kr/   c                    g rY   r'   r[   nfracs      r0   samplern      s     r/   c                    g rY   r'   rk   s      r0   rn   rn      s     r/   c                    g rY   r'   rk   s      r0   rn   rn      s     r/   c                F   U c  [        [        XS9$ [        U 5        [        U 5      (       a  U R                  XS9$ [	        U [
        5      (       aT  SU ;   aM  U S   nU(       d'  Uc  Sn[        U5      e[        U[        U5      -  5      n[        R                  " X15      nSU0$ g[        R                  " U SS9n U(       d'  Uc  Sn[        U5      e[        U[        U 5      -  5      n[        R                  " [        [        U 5      5      U5      nX   R                  5       $ )zBReduce the size of the data model by sampling without replacement.N)rl   rm   rg   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   rn   rh   r   r:   r;   
ValueErrorintri   randomr<   r=   range	to_native)r[   rl   rm   rg   ra   indicess         r0   rn   rn      s    |v..D4  {{Q{**	D$		t(^F<UC$S/)s6{*+]]6-Ff%% >>$40D<NCS/!s4y !mmE#d),a0G=""$$r/   )csvjsonc                       \ rS rSr% S\S'   Srg)_FormatDict   _FormatTyperd   r'   Nr(   r'   r/   r0   r}   r}      s    
r/   r}   c                  *    \ rS rSr% S\S'   S\S'   Srg)_ToFormatReturnUrlDict   strurlr}   formatr'   Nr(   r'   r/   r0   r   r      s    	Hr/   r   c                    g rY   r'   r[   prefix	extensionfilenameurlpaths        r0   to_jsonr           r/   c                    g rY   r'   r   s        r0   r   r           !r/   c           	         [        XX45      nU c  [        [        40 UD6$ [        U 5      n[	        U40 UDS[        SS90D6$ )zGWrite the data model to a .json file and return a url based data model.r   r{   rd   )_to_text_kwdsr   r   _data_to_json_string_to_textr}   r[   r   r   r   r   kwdsdata_strs          r0   r   r      sI     H>D|w'$'''-JDJ&1IJJr/   c                    g rY   r'   r   s        r0   to_csvr     r   r/   c                    g rY   r'   r   s        r0   r   r     r   r/   c           	         [        XX45      nU c  [        [        40 UD6$ [        U 5      n[	        U40 UDS[        SS90D6$ )zFWrite the data model to a .csv file and return a url based data model.r   rz   r   )r   r   r   _data_to_csv_stringr   r}   r   s          r0   r   r     sI     H>D|v&&&&t,IDI%1HIIr/   c                    [        U 5      nUR                  XUS9n[        U5      R                  U SS9  [	        [        XC5      5      n[        XuS.5      $ )N)r   hashr   zutf-8)encoding)r   r   )_compute_data_hashr   r   
write_textr   r   )r[   r   r   r   r   r   	data_hashr   s           r0   r   r   ,  sT     #4(If	RHNdW5
d7%
&C!#"@AAr/   c                   XX#S.$ )Nr   r   r   r   r'   r   s       r0   r   r   ;  s    (__r/   c                   [        U 5        [        R                  " U SS9n[        U[        5      (       a  S[        U5      0$ [        U5      (       a  [        U5      nSUR                  SS90$ [        U[        5      (       a  SU;  a  Sn[        U5      eU$ [        U [        R                  5      (       a  [        U 5      n SU R                  SS90$ S[        U 5       3n[        U5      e)	z0Replace a DataFrame by a data model with values.T)r9   rg   records)orient.values expected in data dict, but not present.namedzUnrecognized data type: )rh   r<   rx   r:   r$   _from_geo_interfacer   r   to_dictr;   KeyErrorr>   r   rowsrd   rt   )r[   data_nativera   s      r0   	to_valuesr   ?  s    D,,t$7K+344-k:;;	[	)	)/<+--Y-?@@	K	&	&;&BC3-	D",,	'	'*40$))$)/00 )d5or/   c                V    [        U 5      (       d  S[        U 5       3n[        U5      eg )Nz@Expected dict, DataFrame or a __geo_interface__ attribute, got: )r@   rd   	TypeError)r[   ra   s     r0   rh   rh   W  s0    PQUVZQ[P\]n r/   c                l    [         R                  " U R                  5       5      R                  5       S S $ )N    )hashlibsha256encode	hexdigest)r   s    r0   r   r   `  s(    >>(//+,668"==r/   c                b    [        U 5      (       a  [        U 5      n [        U R                  5      $ )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&   )r[   s    r0   r   r   d  s*     4  (.!$"8"899r/   c                   [        U 5        [        U [        5      (       a  [        R                  " [        U 5      5      $ [        U 5      (       a  [        U 5      n U R                  SSS9$ [        U [        5      (       a+  SU ;  a  Sn[        U5      e[        R                  " U S   SS9$  [        R                  " U SS9n[        U5      n[        R                  " UR!                  SS95      $ ! [         a  nS	n[        U5      UeS
nAff = f)z6Return a JSON string representation of the input data.r      )r   double_precisionrg   r   T)	sort_keysrr   zBto_json only works with data expressed as a DataFrame or as a dictNr   )rh   r:   r$   r{   dumpsr   r   r   r   r;   r   r<   r=   r   NotImplementedErrorr   r   )r[   ra   data_nwexcs       r0   r   r   t  s    D$,--zz-d344	T	"	"(.||9r|BB	D$		4BC3-zz$x.D990..$7 *'2G::glll.//	  0R!#&C/0s   ,C/ /
D9DDc                d   [        U 5        [        U [        5      (       a)  S[        [        5      R                  < S3n[        U5      e[        U 5      (       a  [        U 5      n U R                  SS9$ [        U [        5      (       aC  SU ;  a  Sn[        U5      e SSKnUR                  R                  U S   5      R                  SS9$  [        R                   " U S
S9nUR%                  5       $ ! [         a  nS	n[        U5      UeSnAff = f! ["         a  nSn[        U5      UeSnAff = f)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)indexrg   z-values expected in data dict, but not presentr   Nz4pandas is required to convert a dict to a CSV stringTrr   zAto_csv only works with data expressed as a DataFrame or as a dict)rh   r:   r$   rd   r)   r   r   r   r   r;   r   pandasImportErrorr>   	from_dictr<   r=   r   	write_csv)r[   ra   pdr   r   s        r0   r   r     s4   D$,--34==@ A=> 	
 "#&&	T	"	"(.{{{''	D$		4AC3-	, ||%%d8n5<<5<II0..$7   	,HCc"+	,  0Q!#&C/0s0   C2 D 2
D<D

D
D/D**D/c                    SSK nS HF  n[        XS5      n[        U5      (       d  M!  U" 5       n[        XAR                  5      (       d  MD  Us  $    [        5       nUR                  U 5      $ )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)dfi_dfpaconvert_method_nameconvert_methodresultpis         r0   arrow_table_from_dfi_dataframer     sb      U dCN###%F&((++  U 
$	%BV$$r/   )r?   r	   rO   zTypeIs[DataType])..)r[   rQ   r\   
int | NonerO   r   ).)r[   r1   r\   r   rO   r1   )Ni  )r[   DataType | Noner\   r   rO   zpartial | DataType)...)r[   rQ   rl   r   rm   float | NonerO   r   )r[   r4   rl   r   rm   r   rO   r4   )r[   r1   rl   r   rm   r   rO   SampleReturnType)NNN)r[   r   rl   r   rm   r   rO   zpartial | SampleReturnType).....)r[   rQ   r   r   r   r   r   r   r   r   rO   r   )....)r[   r1   r   r   r   r   r   r   r   r   rO   r   )Naltair-datar{   {prefix}-{hash}.{extension} )r[   r   r   r   r   r   r   r   r   r   rO    partial | _ToFormatReturnUrlDict)r[   z#dict | pd.DataFrame | DataFrameLiker   r   r   r   r   r   r   r   rO   r   )Nr   rz   r   r   )r[   z*dict | pd.DataFrame | DataFrameLike | Noner   r   r   r   r   r   r   r   rO   r   )r[   r   r   r   r   r   r   r   r   r   r   r}   rO   r   )
r   r   r   r   r   r   r   r   rO   zdict[str, str])r[   r1   rO   r6   )r[   r1   rO   rQ   )r   r   rO   r   )r[   zSupportsGeoInterface | AnyrO   zdict[str, Any])r[   r1   rO   r   )r   r   rO   zpa.Table)V
__future__r   r   r{   rv   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;   r1   r-   r2   r4   r   listr5   r6   r   r@   rA   rB   DataTransformerTyperD   	ExceptionrU   r]   rn   r   r}   r   r   r   r   r   r   rh   r   r   r   r   r   r'   r/   r0   <module>r      s   "    
 4  	 	 	    ? 3 2  ,w22=w--8
7"!,
7"$/ &8 & & cNM#7F)  Kx0	)?"sDcNDc3h$88	99 )  !%S%S#XT#s(^@T0T*U%U V I VS(](;TAB & cNC!3'{8Q;7:; 	>n-@!-CD 	>69 6 
 L 
 L	 K 
 K9=,
,,6,,^ 
@C
#1= 
 
DG
'5A 
 
>A
!/; 
 !%
%% %  	%D m$) Y 
 

  	
   
 
 !
!! ! 	!
 ! ! 
! !1K
KK K 	K
 K &K  

  	
   
 
 !
-!! ! 	!
 ! ! 
! 8<1J
4JJ J 	J
 J &J B
BB B 	B
 B B B`0>: 0,>%r/   