Ë
    èlÖi£  ã                   óœ  — d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d„ de«      Z	ddl
mZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ee	_        ee	_        ee	_        ee	_        ee	_        ee	_        e e	_         e!e	_!        e"e	_"        ee	_        ee	_        e#e	_#        ee	_        e$e	_$        e%e	_%        e&e	_&        ee	_        ee	_        e'e	_'        e(e	_(        e)e	_)        ee	_        e-e	_-        e*e	_*        e/e	_/        e1e	_1        e+e	_+        y)aÇ  
The :class:`.TableSet` class collects a set of related tables in a single data
structure. The most common way of creating a :class:`.TableSet` is using the
:meth:`.Table.group_by` method, which is similar to SQL's ``GROUP BY`` keyword.
The resulting set of tables will all have identical columns structure.

:class:`.TableSet` functions as a dictionary. Individual tables in the set can
be accessed by using their name as a key. If the table set was created using
:meth:`.Table.group_by` then the names of the tables will be the grouping
factors found in the original data.

:class:`.TableSet` replicates the majority of the features of :class:`.Table`.
When methods such as :meth:`.TableSet.select`, :meth:`.TableSet.where` or
:meth:`.TableSet.order_by` are used, the operation is applied to *each* table
in the set and the result is a new :class:`TableSet` instance made up of
entirely new :class:`.Table` instances.

:class:`.TableSet` instances can also contain other TableSet's. This means you
can chain calls to :meth:`.Table.group_by` and :meth:`.TableSet.group_by`
and end up with data grouped across multiple dimensions.
:meth:`.TableSet.aggregate` on nested TableSets will then group across multiple
dimensions.
é    )ÚStringIO)Úzip_longest)ÚText)ÚMappedSequencec                   ól   — e Zd ZdZdd„Zd„ Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
dd	„Zd
„ Zy)ÚTableSeta^  
    An group of named tables with identical column definitions. Supports
    (almost) all the same operations as :class:`.Table`. When executed on a
    :class:`TableSet`, any operation that would have returned a new
    :class:`.Table` instead returns a new :class:`TableSet`. Any operation
    that would have returned a single value instead returns a dictionary of
    values.

    TableSet is implemented as a subclass of :class:`.MappedSequence`

    :param tables:
        A sequence :class:`Table` instances.
    :param keys:
        A sequence of keys corresponding to the tables. These may be any type
        except :class:`int`.
    :param key_name:
        A name that describes the grouping properties. Used as the column
        header when the groups are aggregated. Defaults to the column name that
        was grouped on.
    :param key_type:
        An instance some subclass of :class:`.DataType`. If not provided it
        will default to a :class`.Text`.
    :param _is_fork:
        Used internally to skip certain validation steps when data
        is propagated from an existing tablset.
    Nc                 ót  — t        |«      }t        |«      }|| _        |xs
 t        «       | _        |d   | _        t        | j                  t        «      r/| j                  d   | _        t        | j                  t        «      rŒ/| j                  j                  | _        | j                  j                  | _
        |sf|D ]a  }t        d„ t        |j                  | j                  «      D «       «      rt        d«      ‚|j                  | j                  k7  sŒXt        d«      ‚ t        j                  | ||«       y )Nr   c              3   óN   K  — | ]  \  }}t        |t        |«      «       –— Œ y ­w)N)Ú
isinstanceÚtype)Ú.0ÚaÚbs      ú\/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/agate/tableset/__init__.pyú	<genexpr>z$TableSet.__init__.<locals>.<genexpr>K   s"   è ø€ Òr±d°a¸œ: a¬¨a«Ó1Ô1Ñrùs   ‚#%z*Not all tables have the same column types!z*Not all tables have the same column names!)ÚtupleÚ	_key_namer   Ú	_key_typeÚ_sample_tabler   r   Úcolumn_typesÚ_column_typesÚcolumn_namesÚ_column_namesÚanyr   Ú
ValueErrorr   Ú__init__)ÚselfÚtablesÚkeysÚkey_nameÚkey_typeÚ_is_forkÚtables          r   r   zTableSet.__init__;   s
  € Ü�v“ˆÜ�T‹{ˆà!ˆŒØ!Ò+¤T£VˆŒØ# A™YˆÔä˜×+Ñ+¬XÔ6Ø!%×!3Ñ!3°AÑ!6ˆDÔô ˜×+Ñ+¬XÕ6ð "×/Ñ/×<Ñ<ˆÔØ!×/Ñ/×<Ñ<ˆÔáØò S�ÜÑr¼kÈ%×J\ÑJ\Ð^b×^pÑ^pÓ>qÔrÔrÜ$Ð%QÓRÐRà×%Ñ%¨×);Ñ);Ó;Ü$Ð%QÓRÐRðSô 	×Ñ  f¨dÕ3ó    c                 óZ   — t        «       }| j                  |¬«       |j                  «       S )zV
        Print the tableset's structure via :meth:`TableSet.print_structure`.
        )Úoutput)r   Úprint_structureÚgetvalue)r   Ú	structures     r   Ú__str__zTableSet.__str__S   s+   € ô “Jˆ	à×Ñ IÐÔ.à×!Ñ!Ó#Ð#r$   c                 ó   — | j                   S )z 
        Get the name of the key this TableSet is grouped by. (If created using
        :meth:`.Table.group_by` then this is the original column name.)
        )r   ©r   s    r   r    zTableSet.key_name]   ó   € ð �~‰~Ðr$   c                 ó   — | j                   S )z£
        Get the :class:`.DataType` this TableSet is grouped by. (If created
        using :meth:`.Table.group_by` then this is the original column type.)
        )r   r,   s    r   r!   zTableSet.key_typee   r-   r$   c                 ó   — | j                   S )z¡
        Get an ordered list of this :class:`.TableSet`'s column types.

        :returns:
            A :class:`tuple` of :class:`.DataType` instances.
        )r   r,   s    r   r   zTableSet.column_typesm   ó   € ð ×!Ñ!Ð!r$   c                 ó   — | j                   S )z‹
        Get an ordered list of this :class:`TableSet`'s column names.

        :returns:
            A :class:`tuple` of strings.
        )r   r,   s    r   r   zTableSet.column_namesw   r0   r$   c                 óZ   — |€| j                   }|€| j                  }t        ||||d¬«      S )z¯
        Create a new :class:`.TableSet` using the metadata from this one.

        This method is used internally by functions like
        :meth:`.TableSet.having`.
        T)r"   )r   r   r   )r   r   r   r    r!   s        r   Ú_forkzTableSet._fork�   s5   € ð ÐØ—~‘~ˆHàÐØ—~‘~ˆHä˜  h°À4ÔHÐHr$   c                 ó¸   — g }| j                  «       D ]&  \  }}|j                   t        ||«      |i |¤Ž«       Œ( | j                  || j	                  «       «      S )zJ
        Calls a method on each table in this :class:`.TableSet`.
        )ÚitemsÚappendÚgetattrr3   r   )r   Úmethod_nameÚargsÚkwargsr   Úkeyr#   s          r   Ú_proxyzTableSet._proxy�   sc   € ð ˆàŸ*™*›,ò 	H‰JˆC�Ø�M‰MÐ5œ' %¨Ó5°tÐF¸vÑFÕGð	Hð �z‰zØØ�I‰I‹Kó
ð 	
r$   )ÚgroupNF)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   Úpropertyr    r!   r   r   r3   r<   © r$   r   r   r       sl   „ ñó44ò0$ð ñó ðð ñó ðð ñ"ó ð"ð ñ"ó ð"óIó
r$   r   )Ú	aggregate)Ú	bar_chart)Úcolumn_chart)Úfrom_csv)Ú	from_json)Úhaving)Ú
line_chart)Úmerge)r'   )ÚbinsÚcomputeÚdenormalizeÚdistinctÚexcludeÚfindÚgroup_byÚ
homogenizeÚjoinÚlimitÚ	normalizeÚorder_byÚpivotÚselectÚwhere)Úscatterplot)Úto_csv)Úto_jsonN)2rA   Úior   Ú	itertoolsr   Úagate.data_typesr   Úagate.mapped_sequencer   r   Úagate.tableset.aggregaterD   Úagate.tableset.bar_chartrE   Úagate.tableset.column_chartrF   Úagate.tableset.from_csvrG   Úagate.tableset.from_jsonrH   Úagate.tableset.havingrI   Úagate.tableset.line_chartrJ   Úagate.tableset.mergerK   Úagate.tableset.print_structurer'   Úagate.tableset.proxy_methodsrL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   Úagate.tableset.scatterplotr[   Úagate.tableset.to_csvr\   Úagate.tableset.to_jsonr]   rC   r$   r   ú<module>ro      s9  ðñõ0 Ý !å !Ý 0ô|
ˆ~ô |
õ~ /Ý .Ý 4Ý ,Ý .Ý (Ý 0Ý &Ý :÷b÷ b÷ b÷ bñ bå 2Ý (Ý *à€Ô Ø€Ô Ø€„Ø$€Ô Ø€Ô Ø"€Ô Ø€Ô Ø€Ô Ø€„Ø€Ô Ø€Ô Ø€Ô Ø€„Ø €Ô Ø€„Ø€„Ø €Ô Ø€„Ø€Ô Ø€Ô Ø€„Ø*€Ô Ø"€Ô Ø€„Ø€„Ø€Ô Ø€…r$   