o
    d                     @   sJ   d dl mZ d dlmZ d dlmZ d dlmZ 						d
dd	ZdS )    )reducegroupby)add)htmlNTFc                    s  ddl }	ddl}
|durjdd|f dur0dgjD ]}| fdd|< q  durKdgjD ]}|  fdd|< q;|r] |dur]jd|id	|rt|t	t
|	j|
jfr{z|_W n tyz   td
w t|trj|d	jj}fddt|D dd D dd D fddtd|d D dd D tfddt|D g}ng }|tfddttD  | |fi |S )a  
    Generate a Table component from a dataframe.

    Parameters
    ----------
    df : pandas.DataFrame
        DataFrame to render as a table.
    float_format : str, optional
        Format to use for floating point numbers.
    columns : sequence, optional
        Columns to render.
    header : boolean or list(str) or dict(str: str), optional
        Write out the column names. If a list of strings is given it is assumed
        to be aliases for the columns names (and hence must be the same length
        as df.columns). A dict can be passed to rename some columns, the format
        is {'<current_name>': '<new_name>'}. The dictionary need not have an
        entry for every column.
    index : boolean, optional
        Render the row names (index).
    index_label : str, optional
        Column label for index column if desired. If None is passed, but both
        header and index are True, then the index name is used.
    date_format : str, optional
        Format string for datetime objects.
    **table_kwargs : Keyword arguments
        Additional arguments to pass to the table component. See
        dash_bootstrap_components.Table for details.
    r   Nfloatc                    s   d  | S )Nz{1:{0}})formatx)float_format e/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/dash_bootstrap_components/_table.py<lambda>7   s    z)_generate_table_from_df.<locals>.<lambda>datetimec                    s
   |   S N)strftimer	   )date_formatr   r   r   ;   s   
 index)columnsziIf specifying column names with a sequence, the number of names must exactly match the number of columns.c                    s   g | ]
}t  j|qS r   )listr   get_level_values.0leveldfr   r   
<listcomp>P   s    z+_generate_table_from_df.<locals>.<listcomp>c                 S   s   g | ]}d d t |D qS )c                 S   s   g | ]
\}}t t|qS r   )lenr   )r   _groupr   r   r   r   W       6_generate_table_from_df.<locals>.<listcomp>.<listcomp>r   )r   level_valuesr   r   r   r   V   s    c                    s,   g | ]  fd dt dt d D qS )c                    s   g | ]
}t  d | qS r   )sumr   ilevel_spansr   r   r   ]   r    r!      )ranger   r   r   r&   r   r   \   s    c              	      s.   g | ]}t ttt d | dhqS )Nr   )sortedsetr   r   unionr   )header_breaksr   r   r   b   s     r(   c                    s2   g | ] t  fd dtt d ddD qS )c                    s    g | ]} |  |d    qS )r(   r   r$   level_breaksr   r   r   j   s    r!   r(   r   )reversedr)   r   r*   r   r/   r   r   h   s    
c                    s6   g | ] t j fd dt    D dqS )c                    s&   g | ]\}}t j  | |d qS ))colSpan)r   Th)r   posspan)header_valuesr   r   r   r   v   s    
r!   )children)r   Trzipr*   )r.   header_spansr7   )r   r   r   t   s    c                    s0   g | ] t  fd dttjD qS )c                    s    g | ]}t  j|f qS r   )r   Tdiloc)r   j)r   r%   r   r   r      s     r!   )r   r9   r)   r   r   r*   r   )r%   r   r      s    )numpypandaslocselect_dtypesr   mapreset_indexrename
isinstancetupler   ndarrayIndex
ValueErrordictnlevelsr)   r   TheadappendTbodyr   )clsr   r   r   headerr   index_labelr   table_kwargsnppdcn_levelstabler   )r   r   r   r.   r;   r7   r   _generate_table_from_df   sp   '






rY   )NNTFNN)		functoolsr   	itertoolsr   operatorr   dashr   rY   r   r   r   r   <module>   s    