
    Q/Ph2              
          d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
Zd dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d	ed
edefdZdededefdZdedede	eef         fdZdedede	eeef         fdZdee         dedefdZdee         ddfdZ dee         ddfdZ!dee"         de"fdZ#	 d'dee         dee         deee"         ee         f         fdZ$dee         deee"         ee         f         fdZ%de	ee         ee         f         dee         ddfdZ&dededefdZ'ded edefd!Z(d"edefd#Z)	 	 d(de	ee         ee         f         dee         d%edefd&Z*dS ))    N)asdict)AnyListOptionalTupleUnion)	from_dict)CorrelationSettings)BaseDescription)Alert)ProfileReportv1v2returnc                    t          | t          t          f          rdS t          | t          j                  r/t          |t          j                  r|                     |          S t          | t          j                  r/t          |t          j                  r|                     |          S 	 | |k    S # t          $ r Y dS w xY wNF)
isinstancelistdictpd	DataFrameequalsSeries
ValueError)r   r   s     _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ydata_profiling/compare_reports.py_should_wrapr      s    "tTl## u"bl## 
2r|(D(D yy}}"bi   ZBI%>%> yy}}Rx   uus   2B8 8
CCd1d2c                 >     i   fdh  h z  D             S )Nc                     i | ]K}|t          |         |                   r|         |         gnt          |         |                   LS  )r   _update_merge_mixed).0kr   r   s     r   
<dictcomp>z&_update_merge_dict.<locals>.<dictcomp>'   sj     
 
 
  BqE2a5))31r!u~~$RUBqE22
 
 
    r"   r   r   s   ``r   _update_merge_dictr)      s\    	
	
	
 
 
 
 
 rUUrU]	
 
 
	 	r'   c                 ,   t          | t                    rt          |t                    r| |fS t          | t                    rt          |t                    rg | |R S g t          | t                    r| n| gt          |t                    r|n|gS N)r   r   tupler(   s     r   _update_merge_seqr-   0   s    
 "d 	

2t 4 4 	
2v	B		 
:b$#7#7 
yRyy
r4((2bbrd
r4((2bbrd
 	
r'   c                     t          | t                    r%t          |t                    rt          | |          S t          | |          S r+   )r   r   r)   r-   r(   s     r   r#   r#   A   sE    "d )
2t 4 4 )!"b))) R(((r'   c                     | |S t          | t                    rt          |t                    st          d          t          | |          S )NzLBoth arguments need to be of type dictionary (ProfileReport.description_set))r   r   	TypeErrorr)   r(   s     r   _update_merger1   H   sV    	z	b$ 
z"d';'; 
Z
 
 	
 b"%%%r'   reportsc                     d | D             }d | D             }| D ]b}|D ]9}|D ]4}||j         vr
i |j         |<   ||j         |         vrd|j         |         |<   5:|D ]!}||j        d         vrd|j        d         |<   "cdS )z?Generates placeholders in the dataset descriptions where neededc                 &    h | ]}|j         D ]}|S r"   )scatterr$   rvs      r   	<setcomp>z _placeholders.<locals>.<setcomp>X   s'    222!	221A2222r'   c                 2    h | ]}|j         d          D ]}|S )types)tabler6   s      r   r9   z _placeholders.<locals>.<setcomp>Y   s,    >>>qQWW-=>>>>>>r'    r;   r   N)r5   r<   )r2   keys	type_keysreportk1k2type_keys          r   _placeholdersrD   U   s     32w222D>>G>>>I 4 4 	0 	0B 0 0V^++)+FN2&V^B///-/FN2&r*	0 " 	4 	4Hv|G44423W%h/	44 4r'   c                     t          |           D ]4\  }}|j        j        dk    rdt          d|z              |j        _        5dS )z/Redefine title of reports with the default one.zYData Profiling ReportzDataset A   N)	enumerateconfigtitlechr)r2   idxr@   s      r   _update_titlesrL   i   sU     )) = =V=":::"<Sc]]"<"<FM= =r'   titlesc                      t           fd dd          D                       r d         S d                     d d                   }d| d d          S )Nc              3   0   K   | ]}d          |k    V  dS r   Nr"   )r$   rI   rM   s     r   	<genexpr>z!_compare_title.<locals>.<genexpr>q   s,      
6
6%6!9
6
6
6
6
6
6r'      r   z, z<em>Comparing</em> z <em>and</em> )alljoin)rM   rI   s   ` r   _compare_titlerV   p   sn    

6
6
6
66!"":
6
6
666 Gay		&"+&&FUFF&*FFFr'   rH   c                 "   d | D             }|tt          | d         j        j        j        j                  dk    rFt          |           D ]6\  }}|j        j        j        j        |         g|j        j        j        _        7n\t          |j        j        j                  dk    r:t          |           D ]*\  }}|j        j        j        |j        j        j        _        +d | D             }t          ||          D ]\  }}||j        _        ||fS )Nc                 &    g | ]}|j         j        S r"   )rH   rI   r$   r@   s     r   
<listcomp>z6_compare_profile_report_preprocess.<locals>.<listcomp>}   s    888ffm!888r'   r   rR   c                 6    g | ]}|                                 S r"   )get_descriptionrY   s     r   rZ   z6_compare_profile_report_preprocess.<locals>.<listcomp>   s$    CCCF**,,CCCr'   )	lenrH   htmlstyleprimary_colorsrG   zipanalysisrI   )r2   rH   labelsrK   r@   descriptionslabeldescriptions           r   "_compare_profile_report_preprocessrg   x   s(   
 98888F ~wqz %+:;;a??(11  VM&,;C@;"(77 v{ /00144(11  VK%4 "(77
 DC7CCCL!&,77 + +{%*""<r'   c                 "    d | D             }|| fS )Nc                 &    g | ]}|j         j        S r"   )rb   rI   rY   s     r   rZ   z;_compare_dataset_description_preprocess.<locals>.<listcomp>   s    :::fo#:::r'   r"   )r2   rc   s     r   '_compare_dataset_description_preprocessrj      s!     ;:':::F7?r'   configsc                 d   t          |           dk     rt          d          t          |           dk    rt          j        d           d |D             }t	          |          t          |          k    rt          d          t          | d         t                    r*d | D             }t	          |          st          d          t          | d         t                    rd	 | D             nd
 | D             t	          fdD                       st          j        d           dS dS )zValidate if the reports are comparable.

    Args:
        reports: two reports to compare
                 input may either be a ProfileReport, or the summary obtained from report.get_description()
       z5At least two reports are required for this comparisonzsComparison of more than two reports is not supported. Reports may be produced, but may yield unexpected formatting.c                 0    g | ]}|j         j        j        S r"   )vars
timeseriesactive)r$   cs     r   rZ   z$validate_reports.<locals>.<listcomp>   s     >>>AF%,>>>r'   zCComparison between timeseries and tabular reports is not supported.r   c                      g | ]}|j         d uS r+   )dfr$   r7   s     r   rZ   z$validate_reports.<locals>.<listcomp>   s    ===14t+===r'   z/Reports where not initialized with a DataFrame.c                 @    g | ]}t          |j        j                  S r"   )setrt   columnsru   s     r   rZ   z$validate_reports.<locals>.<listcomp>   s$    777!C%%777r'   c                 Z    g | ](}t          |j                                                  )S r"   )rw   	variablesr>   ru   s     r   rZ   z$validate_reports.<locals>.<listcomp>   s.    ===C((**++===r'   c              3   0   K   | ]}d          |k    V  dS rP   r"   )r$   xfeaturess     r   rQ   z#validate_reports.<locals>.<genexpr>   s,      22Ax{a222222r'   zkThe datasets being profiled have a different set of columns. Only the left side profile will be calculated.N)r]   r   warningswarnrT   anyr   r   )r2   rk   report_typesis_df_availabler}   s       @r   validate_reportsr      sq    7||aPQQQ
7||aL	
 	
 	

 ?>g>>>L
<C----Q
 
 	
 '!*m,, P==W===?## 	PNOOO'!*m,, >77w777==W===222222222 
=	
 	
 	
 	
 	

 
r'   rf   c                    fd| j                                         D             | _         fd| j                                        D             | _        j        j        j        j        j        j        g}d |D             }t          |          r| j        ng | _        j	        j        dk    r| j	        nd| _	        j
        j        r| j        ni | _        | S )aI  Apply the configuration for visualilzation purposes.

    This handles the cases in which the report description
    was computed prior to comparison with a different config

    Args:
        description: report summary
        config: the settings object for the ProfileReport

    Returns:
        the updated description
    c                 6    i | ]\  }}j         |         ||S r"   )missing_diagramsr$   r%   r8   rH   s      r   r&   z!_apply_config.<locals>.<dictcomp>   s=       A8OPQ8R	1  r'   c                 x    i | ]6\  }}j                             |t          d           j                  3||7S )F)	calculate)correlationsgetr
   r   r   s      r   r&   z!_apply_config.<locals>.<dictcomp>   sV          Aq""1kE&B&B&B&LMM 	1     r'   c                     g | ]}|d k    	S )r   r"   )r$   ss     r   rZ   z!_apply_config.<locals>.<listcomp>   s    &&&q1u&&&r'   r   N)missingitemsr   samplesheadtailrandomr   sample
duplicatesinteractions
continuousr5   )rf   rH   r   s    ` r   _apply_configr      s	      $,2244  K       ,2244     K ~"FN$79NOG&&g&&&G/27||C++K"("3"81"<"<$  281D1OW+--UWKr'   alert
alert_listc                 :     t           fd|D                       S )Nc              3   X   K   | ]$}|j         j         k    o|j        j        k    V  %d S r+   )column_name
alert_type)r$   ar   s     r   rQ   z$_is_alert_present.<locals>.<genexpr>   sP         	
**Oq|u?O/O     r'   )r   )r   r   s   ` r   _is_alert_presentr      s;             r'   report_alertsc                 `   ddl m } d | D             }t          |           D ]~\  }}|D ]v}||                             |           t          |          D ]I\  }}||k    rt          || |                   s' ||          }d|_        |                    |           Jwt          |          S )Nr   )copyc                     g | ]}g S r"   r"   )r$   _s     r   rZ   z-_create_placehoder_alerts.<locals>.<listcomp>   s    ---!2---r'   T)r   rG   appendr   	_is_emptyr,   )	r   r   fixedrK   alertsr   ifixempty_alerts	            r   _create_placehoder_alertsr      s    --}---E // 	, 	,V 	, 	,E#Je$$$#E** , ,388(a0@AA ,"&$u++K,0K)JJ{+++,	, <<r'   Fcomputec                 "   t          |           dk    rt          d          d | D             }t          t          |                    dk    rt          d          t	          | d         t
                    rd | D             }nKd | D             }g }|D ]:}t                      }|                    |          }|                    |           ;t          | |           t	          | d         t
                    rp| d         j
        j        }| dd	         D ]+fd
|D             }	j
        j        d	d	|	f         _
        ,d | D             } t          |           dk    r| d         S nt          | d         j                                                  }d}
| dd	         D ](fd|D             }	t          |	          dk    r|
dz  }
)|
dk    r&t          d	|d                   }| d         |_        |S d	||d                                         n|                                t	          | d         t
                    rk| D ]hj        j        j        j        }j        j        }|                                _        |j        _        |j        j        j        _        |rd	_        it/          d | D                       r#t1          |            t3          |           \  }}n;t/          d | D                       rt5          |           \  }}nt          d          |j        j        _        t=          |           fd|D             }t?          d	|d                   }|dd	         D ]}t?          ||          }tA          |d         d                   |d         d<   tC          |d                   |d<   tE          |d                   sd	|d<   t          d	          }tG          tH          |          |_        |S )a  
    Compare Profile reports

    Args:
        reports: two reports to compare
                 input may either be a ProfileReport, or the summary obtained from report.get_description()
        config: the settings object for the merged ProfileReport
        compute: recompute the profile report using config or the left report config
                 recommended in cases where the reports were created using different settings

    r   z$No reports available for comparison.c                 ,    g | ]}t          |          S r"   )typeru   s     r   rZ   zcompare.<locals>.<listcomp>  s    ...T!WW...r'   rR   zThe input must have the same data type for all reports. Comparing ProfileReport objects to summaries obtained from the get_description() method is not supported.c                     g | ]	}|j         
S r"   rH   ru   s     r   rZ   zcompare.<locals>.<listcomp>  s    111Aqx111r'   c                 L    g | ]!}t          j        |j        d                    "S )ydata_profiling_config)jsonloadspackageru   s     r   rZ   zcompare.<locals>.<listcomp>  s7     
 
 
@ADJqy!9:;;
 
 
r'   )r2   rk   Nc                 0    g | ]}|j         j        v |S r"   )rt   rx   r$   colr@   s     r   rZ   zcompare.<locals>.<listcomp>)  s(    WWWccVYEV>V>Vc>V>V>Vr'   c                 *    g | ]}|j         j        |S r"   )rt   emptyru   s     r   rZ   zcompare.<locals>.<listcomp>+  s!    888QTZ81888r'   c                 d    g | ],}|t          j                                                  v *|-S r"   )r   rz   r>   r   s     r   rZ   zcompare.<locals>.<listcomp>2  sA       tF<L<Q<Q<S<S7T7T0T0T0T0T0Tr'   r   c              3   @   K   | ]}t          |t                    V  d S r+   )r   r   rY   s     r   rQ   zcompare.<locals>.<genexpr>K  s,      
C
C:fm,,
C
C
C
C
C
Cr'   c              3   @   K   | ]}t          |t                    V  d S r+   )r   r   rY   s     r   rQ   zcompare.<locals>.<genexpr>P  s,      GGVZ00GGGGGGr'   c                 J    g | ]}t          t          |                     S r"   )r   r   )r$   d_configs     r   rZ   zcompare.<locals>.<listcomp>[  s+    QQQqa 9 9::QQQr'   rb   rI   r   time_index_analysis)
data_classdata)%r]   r   rw   r0   r   r   r   updater   r   rt   rx   locr   rz   r>   _description_setr   rH   ro   rp   rq   rI   rT   rL   rg   rj   r^   r_   _labelsrD   r1   rV   r   r   r	   r   )r2   rH   r   report_dtypesall_configsconfigs_strc_str	c_settingbase_featurescols_2_comparenon_empty_reportsprofiletsmoderI   rc   rd   descriptions_dictresr7   r   r@   s                      @@r   comparer      s     7||q?@@@..g...M
3}"" p
 
 	
 '!*m,, 
*11111
 
EL
 
 
   	* 	*E 

I!((//Iy))))Wk::::'!*m,, 
-abbk 	9 	9FWWWW]WWWN	aaa&78FII88g888w<<11:  WQZ1668899abbk 	' 	'F   ,  N >""Q&&!Q&!!!#DQ@@@G'.qzG$NG~a.%%''++--gaj-00 	3! 3 3+6=+ &&+#7="-4 3.2F+

C
C7
C
C
CCC 

 	wA'7SS	GGwGGG	G	G 
FwOO p
 
 	
 "(GL,QQQQLQQQd$5a$899Cqrr" $ $C##-c*og.FGGC
OG-c(m<<CMs()** *%)!"D111G(O#NNNGNr'   r+   r   )+r   r~   dataclassesr   typingr   r   r   r   r   pandasr   daciter	   ydata_profiling.configr
   r   ydata_profiling.modelr   ydata_profiling.model.alertsr   ydata_profiling.profile_reportr   boolr   r   r)   r   r,   r-   r#   r1   rD   rL   strrV   rg   rj   r   r   r   r   r   r"   r'   r   <module>r      s           4 4 4 4 4 4 4 4 4 4 4 4 4 4           8 8 8 8 8 8 8 8 1 1 1 1 1 1 . . . . . . 8 8 8 8 8 8S c d    3 C D    $
# 
3 
5u+= 
 
 
 
")C )S )U4u3D-E ) ) ) )
&htn 
&$ 
&4 
& 
& 
& 
&440 4T 4 4 4 4(=D/ =D = = = =G49 G G G G G "&   -  X  49d?++,       :/"
49d?++,   &
4&_(==>&
IMd&
	&
 &
 &
 &
R  _    DU      U u    & "&h h4&_(==>hXh h 	h h h h h hr'   