
    Q/Ph5                     @   d dl Z d dlZd dlmZmZmZmZmZ d dlZ	d dl
mZ  G d d          Z G d d          Z G d d	e          Z G d
 de          Z G d de          Zdededeeef         fdZdede	j        deeef         deeeef                  fdZdS )    N)AnyCallableDictOptionalSized)Settingsc                   .    e Zd ZdZdefdZdedefdZdS )MissingDataBackendzXHelper class to select and cache the appropriate missing-data backend (Pandas or Spark).dfc                     t          |t          j                  rd| _        nd| _        t	          j        | j                  | _        dS )zFDetermine backend once and store it for all missing-data computations.z+ydata_profiling.model.pandas.missing_pandasz)ydata_profiling.model.spark.missing_sparkN)
isinstancepd	DataFramebackend_module	importlibimport_modulemodule)selfr   s     ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ydata_profiling/model/missing.py__init__zMissingDataBackend.__init__   sC    b",'' 	N"OD"MD-d.ABB    method_namereturnc                     	 t          | j        |          S # t          $ r!}t          d| d| j         d          |d}~ww xY w)zGRetrieve the appropriate missing-data function from the backend module.zMissing-data function 'z' is not available in .N)getattrr   AttributeErrorr   )r   r   exs      r   
get_methodzMissingDataBackend.get_method   sf    	4;444 	 	 	 c+ccTM`ccc 	s    
A=AN)	__name__
__module____qualname____doc__r   r   strr   r    r   r   r
   r
   
   s\        bbC5 C C C Cc h      r   r
   c            	       B    e Zd ZU dZeed<   dededede	e         fdZ
dS )	MissingData _method_nameconfigr   backendr   c                     	 |                     | j                  } |||          S # t          $ r}t                      |d}~ww xY w)zAComputes correlation using the correct backend (Pandas or Spark).N)r   r)   r   NotImplementedError)r   r*   r   r+   methodr   s         r   computezMissingData.compute#   s`    	&''(9::F 6&"%%%  	0 	0 	0%''R/	0s   ( 
AAAN)r    r!   r"   r)   r$   __annotations__r   r   r
   r   r/   r%   r   r   r'   r'       s^         L#	&	&$)	&4F	&	%	& 	& 	& 	& 	& 	&r   r'   c                       e Zd ZdZdS )
MissingBarmissing_barNr    r!   r"   r)   r%   r   r   r2   r2   /   s         LLLr   r2   c                       e Zd ZdZdS )MissingMatrixmissing_matrixNr4   r%   r   r   r6   r6   3   s        #LLLr   r6   c                       e Zd ZdZdS )MissingHeatmapmissing_heatmapNr4   r%   r   r   r9   r9   7   s        $LLLr   r9   r*   table_statsr   c                      dddt                      ddddt                      dddd	t                      dd
} fd|                                D             }|S )z

    Args:
        config: report Settings object
        table_stats: The overall statistics for the DataFrame.

    Returns:

    r   Countz,A simple visualization of nullity by column.)min_missingnamecaptionfunctionMatrixzlNullity matrix is a data-dense display which lets you quickly visually pick out patterns in data completion.   HeatmapzThe correlation heatmap measures nullity correlation: how strongly the presence or absence of one variable affects the presence of another.)barmatrixheatmapc                     i | ]H\  }}j         |         r6d          |d         k    r$|dk    sd          d         z
  |d         k    E||IS )n_vars_with_missingr>   rG   n_vars_all_missing)missing_diagrams).0r?   settingsr*   r;   s      r   
<dictcomp>z&get_missing_active.<locals>.<dictcomp>[   s       D(#D)	
 12h}6MMM I12[AU5VVM*+ + 	h+ + +r   )r2   r6   r9   items)r*   r;   missing_maps   `` r   get_missing_activerQ   ;   s     E"	
 
  F%	
 
  e&((	
 
 K*    )//11  K  r   r   rM   c           
      *   t          |          }|                    d          }|dS 	 |                    | ||          }|d         |d         |dS # t          $ r5}t	          j        d|d          d|d          d| d	           Y d}~dS d}~ww xY w)
as  Gets the rendered diagrams for missing values.

    Args:
        config: report Settings object
        df: The DataFrame on which to calculate the missing values.
        settings: missing diagram name, caption and function

    Returns:
        A dictionary containing the base64 encoded plots for each diagram that is active in the config (matrix, bar, heatmap).
    rA   Nr?   r@   )r?   r@   rF   z%There was an attempt to generate the z missing values diagrams, but this failed.
        To hide this warning, disable the calculation
        (using `df.profile_report(missing_diagrams={"z": False}`)
        If this is problematic for your use case, please report this as an issue:
        https://github.com/ydataai/ydata-profiling/issues
        (include the error message: 'z'))r
   getr/   
ValueErrorwarningswarn)r*   r   rM   r+   missing_funcresultes          r   get_missing_diagramrZ   n   s     !$$G<<
++Lt
%%fb':: V$	*
 
 	
  	 	 	.hv6F . .7?7G. .
 '(. . .	
 	
 	
 ttttt	s   A 
B*BB)r   rU   typingr   r   r   r   r   pandasr   ydata_profiling.configr   r
   r'   r2   r6   r9   dictr$   rQ   r   rZ   r%   r   r   <module>r_      s        7 7 7 7 7 7 7 7 7 7 7 7 7 7     + + + + + +       ,& & & & & & & &! ! ! ! ! ! ! !$ $ $ $ $K $ $ $% % % % %[ % % %0x 0d 0tCH~ 0 0 0 0f$
$
,$
26sCx.$
d38n$
 $
 $
 $
 $
 $
r   