
    M/Phm              
       6   d dl mZmZmZmZmZmZ d dlZd dl	m
Z
 d dlmZ ee
         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ef         ef         fd
Zdededeeeef         ef         fdZdededeeeeef                  fdZdej        dedefdZdS )    )DictListSequenceTupleTypeUnionN)VisionsBaseType)VisionsTypesetdatatypesetreturnc                 ,    |                     |           S )a3  Casts a DataFrame into a typeset by first performing column wise type detection against
    a provided typeset

    Args:
        data: the DataFrame to cast
        typeset: the Typeset in which we cast

    Returns:
        A tuple of the casted DataFrame and the types to which the columns were cast
    )cast_to_detectedr   r   s     R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/visions/functional.pyr   r           ##D)))    c                 ,    |                     |           S )a3  Casts a DataFrame into a typeset by first performing column wise type inference against
    a provided typeset

    Args:
        data: the DataFrame to cast
        typeset: the Typeset in which we cast

    Returns:
        A tuple of the casted DataFrame and the types to which the columns were cast
    )cast_to_inferredr   s     r   r   r      r   r   c                 ,    |                     |           S )a  Infer the current types of each column in the DataFrame given the typeset.

    Args:
        data: the DataFrame to infer types on
        typeset: the Typeset that provides the type context

    Returns:
        A dictionary with a mapping from column name to type
    )
infer_typer   s     r   r   r   '   s     d###r   c                 ,    |                     |           S )zDetect the type in the base graph

    Args:
        data: the DataFrame to detect types on
        typeset: the Typeset that provides the type context

    Returns:
        A dictionary with a mapping from column name to type
    )detect_typer   s     r   r   r   4   s     t$$$r   c                 B   g }t          | |          }t          | |          }t          |t                    rt          |t                    sJ |                                |                                z  D ]&}|                    |||         ||         f           '|S )a&  Compare the types given by inference on the base graph and the relational graph

    Args:
        data: the sequence to detect types on
        typeset: the Typeset that provides the type context

    Examples:
        >>> for column, type_before, type_after in compare_detect_inference_frame(data, typeset):
        >>>    print(f"{column} was {type_before} is {type_after}")

    See Also:
        :doc:`type_inference_report_frame <visions.functional.type_inference_report_frame>`:
            Formatted report of the output of this function
    )r   r   
isinstancedictkeysappend)r   r   comparisonsdetected_typesinferred_typeskeys         r   compare_detect_inference_framer#   A   s    " K w//Ng..Nnd++ 
1 1    ""$$~':':'<'<< L LC!4nS6IJKKKKr   dfc                 <   d}t          d | j        D                       |z   }d}d}d}t          | |          D ]5\  }}}	||	k    }
|
rd}|dz  }nd}||d	| d
|d	| d
| d
|	d	| dz  }6|d                    |t	          | j                            z  }|S )aq  Return formatted report of the output of `compare_detect_inference_frame`.

    Args:
        df: the DataFrame to detect types on
        typeset: the Typeset that provides the type context

    Returns:
        Text-based comparative type inference report

    Examples:
        >>> import pandas as pd
        >>> from visions.functional import type_inference_report_frame
        >>> from visions.typesets import StandardSet
        >>>
        >>> typeset = StandardSet()
        >>> df = pd.read_csv('dataset.csv')
        >>>
        >>> report = type_inference_report_frame(df, typeset)
        >>> print(report)
       c              3   4   K   | ]}t          |          V  d S )N)len).0columns     r   	<genexpr>z.type_inference_report_frame.<locals>.<genexpr>v   s(      AAFCKKAAAAAAr       r   z!=   z==z < z 
z@In total {change_count} out of {type_count} types were changed.
)change_count
type_count)maxcolumnsr#   formatr(   )r$   r   paddingmax_column_lengthmax_type_lengthreportr0   r*   type_before
type_afterchangedfills               r   type_inference_report_framer=   `   s0   * GAAbjAAAAAGKOFL+I"g+V+V 
 
'Z+ 	DALLD 3* 3P 3 3k 3_ 3P 3 33 33,323 3 3	

 KRR%#bj// 	S 	
 	
F
 Mr   )typingr   r   r   r   r   r   pandaspdvisions.types.typer	   visions.typesets.typesetr
   Tr   r   strr   r   r#   	DataFramer=    r   r   <module>rG      s   ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;     . . . . . . 3 3 3 3 3 3*8 *n * * * * **8 *n * * * * *
$X 
$ 
$5c1fq;Q 
$ 
$ 
$ 
$
%h 
% 
%E$sAv,PQ/<R 
% 
% 
% 
%
+	%Q	
   >,BL ,> ,c , , , , , ,r   