Ë
    èlÖi®2  ã                   óØ  — d Z ddlZddl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  G d„ d«      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) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 dd l:m;Z; dd!l<m=Z= dd"l>m?Z? dd#l@mAZA dd$lBmCZC dd%lDmEZE dd&lFmGZG dd'lHmIZI dd(lJmKZK dd)lLmMZM dd*lNmOZO dd+lPmQZQ dd,lRmSZS dd-lTmUZU 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        e3e_3        e5e_5        e7e_7        e9e_9        e;e_;        e=e_=        e?e_?        eAe_A        eCe_C        eEe_E        eGe_G        eIe_I        eKe_K        eMe_M        eOe_O        eQe_Q        eSe_S        eUe_U        y).aÈ  
The :class:`.Table` object is the most important class in agate. Tables are
created by supplying row data, column names and subclasses of :class:`.DataType`
to the constructor. Once created, the data in a table **can not be changed**.
This concept is central to agate.

Instead of modifying the data, various methods can be used to create new,
derivative tables. For example, the :meth:`.Table.select` method creates a new
table with only the specified columns. The :meth:`.Table.where` method creates
a new table with only those rows that pass a test. And :meth:`.Table.order_by`
creates a sorted table. In all of these cases the output is a new :class:`.Table`
and the existing table remains unmodified.

Tables are not themselves iterable, but the columns of the table can be
accessed via :attr:`.Table.columns` and the rows via :attr:`.Table.rows`. Both
sequences can be accessed either by numeric index or by name. (In the case of
rows, row names are optional.)
é    N)ÚStringIO)Úchain)Úutils)ÚColumn)ÚDataType)Ú	CastError)ÚMappedSequence)ÚRow)Ú
TypeTesterc                   ó”   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Ze	d„ «       Z
e	d	„ «       Ze	d
„ «       Ze	d„ «       Ze	d„ «       Zdd„Zd„ Zd„ Zy)ÚTablea1  
    A dataset consisting of rows and columns. Columns refer to "vertical" slices
    of data that must all be of the same type. Rows refer to "horizontal" slices
    of data that may (and usually do) contain mixed types.

    The sequence of :class:`.Column` instances are retrieved via the
    :attr:`.Table.columns` property. They may be accessed by either numeric
    index or by unique column name.

    The sequence of :class:`.Row` instances are retrieved via the
    :attr:`.Table.rows` property. They may be accessed by either numeric index
    or, if specified, unique row names.

    :param rows:
        The data as a sequence of any sequences: tuples, lists, etc. If
        any row has fewer values than the number of columns, it will be filled
        out with nulls. No row may have more values than the number of columns.
    :param column_names:
        A sequence of string names for each column or `None`, in which case
        column names will be automatically assigned using :func:`.letter_name`.
    :param column_types:
        A sequence of instances of :class:`.DataType` or an instance of
        :class:`.TypeTester` or `None` in which case a generic TypeTester will
        be used. Alternatively, a dictionary with column names as keys and
        instances of :class:`.DataType` as values to specify some types.
    :param row_names:
        Specifies unique names for each row. This parameter is
        optional. If specified it may be 1) the name of a single column that
        contains a unique identifier for each row, 2) a key function that takes
        a :class:`.Row` and returns a unique identifier or 3) a sequence of
        unique identifiers of the same length as the sequence of rows. The
        uniqueness of resulting identifiers is not validated, so be certain
        the values you provide are truly unique.
    :param _is_fork:
        Used internally to skip certain validation steps when data
        is propagated from an existing table. When :code:`True`, rows are
        assumed to be :class:`.Row` instances, rather than raw data.
    Nc                 ó>  — t        |t        «      rt        d«      ‚|rt        j                  |d¬«      | _        np|r_t        d„ t        t        |d   «      «      D «       «      | _        t        j                  dt        | j
                  «      z  t        d¬«       nt        «       | _        t        | j
                  «      }|€t        «       }nt        |t        «      r=|j                  «       D ]  }t        |t        «      rŒt        d	«      ‚ t        |¬
«      }n2t        |t        «      s"|D ]  }t        |t        «      rŒt        d	«      ‚ t        |t        «      r"|j!                  || j
                  «      | _        nt        |«      | _        |t        | j"                  «      k7  rt        d«      ‚|sÐg }	| j"                  D �
cg c]  }
|
j$                  ‘Œ }}
t'        |«      D ]œ  \  }}t        |«      }||kD  rt        d|||fz  «      ‚t        |«      |k  rt)        |d g||z
  z  «      }g }t'        |«      D ]   \  }}	 |j+                   ||   |«      «       Œ" |	j+                  t/        || j
                  «      «       Œž n|}	|r´g }t        |t        «      r|	D ]  }||   }|j+                  |«       Œ nPt1        |d«      r!|	D ]  } ||«      }|j+                  |«       Œ n#t        j2                  |«      r|}nt        d«      ‚|D ]  }t5        |«      t6        u sŒt        d«      ‚ t        |«      | _        nd | _        t;        |	| j8                  «      | _        g }t        |«      D ]U  }| j
                  |   }| j"                  |   }t?        |||| j<                  | j8                  ¬«      }|j+                  |«       ŒW t;        || j
                  «      | _         y c c}
w # t,        $ r0}t-        t        |«      d|› d| j
                  |   › d�z   «      ‚d }~ww xY w)NzqWhen created directly, the first argument to Table must be a sequence of rows. Did you want agate.Table.from_csv?T)Úcolumn_namesc              3   óF   K  — | ]  }t        j                  |«      –— Œ y ­w)N)r   Úletter_name)Ú.0Úis     úY/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/agate/table/__init__.pyú	<genexpr>z!Table.__init__.<locals>.<genexpr>R   s   è ø€ Ò&YÀ¤u×'8Ñ'8¸×';Ñ&Yùs   ‚!r   z7Column names not specified. "%s" will be used as names.é   )Ú
stacklevelz+Column types must be instances of DataType.)Úforcez6column_names and column_types must be the same length.z4Row %i has %i values, but Table only has %i columns.z Error at row z column ú.Ú__call__z5row_names must be a column name, function or sequencezDRow names cannot be of type int. Use Decimal for numbered row names.)Ú	row_names)!Ú
isinstanceÚstrÚ
ValueErrorr   ÚdeduplicateÚ_column_namesÚtupleÚrangeÚlenÚwarningsÚwarnÚRuntimeWarningr   ÚdictÚvaluesr   ÚrunÚ_column_typesÚcastÚ	enumerater   Úappendr   r
   ÚhasattrÚ
issequenceÚtypeÚintÚ
_row_namesr	   Ú_rowsr   Ú_columns)ÚselfÚrowsr   Úcolumn_typesr   Ú_is_forkÚlen_column_namesÚvÚcolumn_typeÚnew_rowsÚcÚ
cast_funcsr   ÚrowÚlen_rowÚ
row_valuesÚjÚdÚeÚcomputed_row_namesÚnameÚrow_nameÚnew_columnsÚ	data_typeÚcolumns                            r   Ú__init__zTable.__init__I   s  € Ü�dœCÔ Üð Bó Cð Cñ Ü!&×!2Ñ!2°<ÈdÔ!SˆDÕÙÜ!&Ñ&YÄUÌ3ÈtÐTUÉwË<ÓEXÔ&YÓ!YˆDÔÜ�M‰MÐSÔVYÐZ^×ZlÑZlÓVmÑmÜ(°Qö8ô "'£ˆDÔä˜t×1Ñ1Ó2Ðð ÐÜ%›<‰LÜ˜¤dÔ+Ø!×(Ñ(Ó*ò T�Ü! !¤XÕ.Ü$Ð%RÓSÐSðTô &¨LÔ9‰LÜ˜L¬*Ô5Ø+ò T�Ü! +¬xÕ8Ü$Ð%RÓSÐSðTô �l¤JÔ/Ø!-×!1Ñ!1°$¸×8JÑ8JÓ!KˆDÕä!& |Ó!4ˆDÔàœs 4×#5Ñ#5Ó6Ò6ÜÐUÓVÐVáØˆHØ*.×*<Ñ*<Ö= Q˜!Ÿ&›&Ð=ˆJÐ=ä# D›/ò E‘��3Ü˜c›(�àÐ-Ò-Ü$ØNÐRSÐU\Ð^nÐQoÑoóð ô ˜“XÐ 0Ò0Ü  d VÐ/?À'Ñ/IÑ%JÓK�Cà�
Ü% c›Nò g‘D�A�qðgØ"×)Ñ)¨-¨*°Q©-¸Ó*:Õ;ðgð —‘¤ J°×0BÑ0BÓ CÕDñ#Eð& ˆHáØ!#Ðä˜)¤SÔ)Ø#ò 4�CØ˜y™>�DØ&×-Ñ-¨dÕ3ñ4ô ˜ JÔ/Ø#ò 4�CÙ$ S›>�DØ&×-Ñ-¨dÕ3ñ4ô ×!Ñ! )Ô,Ø%.Ñ"ä Ð!XÓYÐYà.ò m�Ü˜“>¤SÒ(Ü$Ð%kÓlÐlðmô $Ð$6Ó7ˆD�Oà"ˆDŒOä# H¨d¯o©oÓ>ˆŒ
ð ˆäÐ'Ó(ò 	'ˆAØ×%Ñ% aÑ(ˆDØ×*Ñ*¨1Ñ-ˆIä˜A˜t Y°·
±
ÀdÇoÁoÔVˆFà×Ñ˜vÕ&ð	'ô ' {°D×4FÑ4FÓGˆ�ùòy >øô  %ò gÜ'¬¨A«°>À!ÀÀHÈT×M_ÑM_Ð`aÑMbÐLcÐcdÐ1eÑ(eÓfÐfûðgús   ÇOÈ?O#Ï#	PÏ,+PÐPc                 óZ   — t        «       }| j                  |¬«       |j                  «       S )zS
        Print the table's structure using :meth:`.Table.print_structure`.
        )Úoutput)r   Úprint_structureÚgetvalue)r5   Ú	structures     r   Ú__str__zTable.__str__°   s+   € ô “Jˆ	à×Ñ IÐÔ.à×!Ñ!Ó#Ð#ó    c                 ó6   — | j                   j                  «       S )z8
        Shorthand for :code:`len(table.rows)`.
        )r3   Ú__len__©r5   s    r   rT   zTable.__len__º   s   € ð �z‰z×!Ñ!Ó#Ð#rR   c                 ó6   — | j                   j                  «       S )z9
        Shorthand for :code:`iter(table.rows)`.
        )r3   Ú__iter__rU   s    r   rW   zTable.__iter__À   s   € ð �z‰z×"Ñ"Ó$Ð$rR   c                 ó8   — | j                   j                  |«      S )z8
        Shorthand for :code:`table.rows[foo]`.
        )r3   Ú__getitem__)r5   Úkeys     r   rY   zTable.__getitem__Æ   s   € ð �z‰z×%Ñ% cÓ*Ð*rR   c                 ó   — | j                   S )z8
        An tuple :class:`.DataType` instances.
        )r*   rU   s    r   r7   zTable.column_typesÌ   ó   € ð
 ×!Ñ!Ð!rR   c                 ó   — | j                   S )z&
        An tuple of strings.
        )r    rU   s    r   r   zTable.column_namesÓ   r\   rR   c                 ó   — | j                   S )z†
        An tuple of strings, if this table has row names.

        If this table does not have row names, then :code:`None`.
        )r2   rU   s    r   r   zTable.row_namesÚ   s   € ð �‰ÐrR   c                 ó   — | j                   S )zz
        A :class:`.MappedSequence` with column names for keys and
        :class:`.Column` instances for values.
        )r4   rU   s    r   ÚcolumnszTable.columnsã   s   € ð �}‰}ÐrR   c                 ó   — | j                   S )z„
        A :class:`.MappedSeqeuence` with row names for keys (if specified) and
        :class:`.Row` instances for values.
        )r3   rU   s    r   r6   z
Table.rowsë   s   € ð �z‰zÐrR   c                 óv   — |€| j                   }|€| j                  }|€| j                  }t        ||||d¬«      S )a’  
        Create a new table using the metadata from this one.

        This method is used internally by functions like
        :meth:`.Table.order_by`.

        :param rows:
            Row data for the forked table.
        :param column_names:
            Column names for the forked table. If not specified, fork will use
            this table's column names.
        :param column_types:
            Column types for the forked table. If not specified, fork will use
            this table's column names.
        :param row_names:
            Row names for the forked table. If not specified, fork will use
            this table's row names.
        T)r   r8   )r    r*   r2   r   )r5   r6   r   r7   r   s        r   Ú_forkzTable._forkó   sI   € ð& ÐØ×-Ñ-ˆLàÐØ×-Ñ-ˆLàÐØŸ™ˆIä�T˜<¨ÀÐUYÔZÐZrR   c                 óF   —  | j                   t        j                  fi |¤Ž y)zÂ
        Print this table as a CSV.

        This is the same as passing :code:`sys.stdout` to :meth:`.Table.to_csv`.

        :code:`kwargs` will be passed on to :meth:`.Table.to_csv`.
        N)Úto_csvÚsysÚstdout©r5   Úkwargss     r   Ú	print_csvzTable.print_csv  s   € ð 	ˆ�‰”C—J‘JÑ) &Ó)rR   c                 óF   —  | j                   t        j                  fi |¤Ž y)zË
        Print this table as JSON.

        This is the same as passing :code:`sys.stdout` to
        :meth:`.Table.to_json`.

        :code:`kwargs` will be passed on to :meth:`.Table.to_json`.
        N)Úto_jsonrf   rg   rh   s     r   Ú
print_jsonzTable.print_json  s   € ð 	ˆ�‰”S—Z‘ZÑ* 6Ó*rR   )NNNF)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rK   rQ   rT   rW   rY   Úpropertyr7   r   r   r`   r6   rc   rj   rm   © rR   r   r   r   "   s˜   „ ñ%óLeHòN$ò$ò%ò+ð ñ"ó ð"ð ñ"ó ð"ð ñó ðð ñó ðð ñó ðó[ò<*ó	+rR   r   )Ú	aggregate)Ú	bar_chart)Úbins)Úcolumn_chart)Úcompute)Údenormalize)Údistinct)Úexclude)Úfind)Úfrom_csv)Ú
from_fixed)Ú	from_json)Úfrom_object)Úgroup_by)Ú
homogenize)Újoin)Úlimit)Ú
line_chart)Úmerge)Ú	normalize)Úorder_by)Úpivot)Ú
print_bars)Ú
print_html)rN   )Úprint_table)Úrename)Úscatterplot)Úselect)re   )rl   )Úwhere)Vrq   rf   r$   Úior   Ú	itertoolsr   Úagater   Úagate.columnsr   Úagate.data_typesr   Úagate.exceptionsr   Úagate.mapped_sequencer	   Ú
agate.rowsr
   Úagate.type_testerr   r   Úagate.table.aggregatert   Úagate.table.bar_chartru   Úagate.table.binsrv   Úagate.table.column_chartrw   Úagate.table.computerx   Úagate.table.denormalizery   Úagate.table.distinctrz   Úagate.table.excluder{   Úagate.table.findr|   Úagate.table.from_csvr}   Úagate.table.from_fixedr~   Úagate.table.from_jsonr   Úagate.table.from_objectr€   Úagate.table.group_byr�   Úagate.table.homogenizer‚   Úagate.table.joinrƒ   Úagate.table.limitr„   Úagate.table.line_chartr…   Úagate.table.merger†   Úagate.table.normalizer‡   Úagate.table.order_byrˆ   Úagate.table.pivotr‰   Úagate.table.print_barsrŠ   Úagate.table.print_htmlr‹   Úagate.table.print_structurerN   Úagate.table.print_tablerŒ   Úagate.table.renamer�   Úagate.table.scatterplotrŽ   Úagate.table.selectr�   Úagate.table.to_csvre   Úagate.table.to_jsonrl   Úagate.table.wherer�   rs   rR   r   ú<module>rº      s‡  ðñó& Û Ý Ý å Ý  Ý %Ý &Ý 0Ý Ý (÷B+ñ B+õJ ,Ý +Ý !Ý 1Ý 'Ý /Ý )Ý 'Ý !Ý )Ý -Ý +Ý /Ý )Ý -Ý !Ý #Ý -Ý #Ý +Ý )Ý #Ý -Ý -Ý 7Ý /Ý %Ý /Ý %Ý %Ý 'Ý #à€„Ø€„Ø€„
Ø!€Ô Ø€„Ø€Ô Ø€„Ø€„Ø€„
Ø€„Ø€Ô Ø€„Ø€Ô Ø€„Ø€Ô Ø€„
Ø€„Ø€Ô Ø€„Ø€„Ø€„Ø€„Ø€Ô Ø€Ô Ø'€Ô Ø€Ô Ø€„Ø€Ô Ø€„Ø€„Ø€„Ø€…rR   