Ë
    kQêj‘­  ã                   ó|  — d dl Z d dlZd dlZd dlmZ d dlZddlmZm	Z	 ddl
mZmZ ddlmZ ddlmZmZmZ d dlmZmZmZmZmZmZmZ er
d d	lmZmZm Z!  G d
„ d«      Z"dede"fd„Z# G d„ d«      Z$ G d„ d«      Z%dZ&dede'e(ef   fd„Z)dej                  dej                  fd„Z*de'e(ef   defd„Z+ G d„ d«      Z,y)é    N)Ú
deprecatedé   )Úasync_permutation_builderÚPermutationReader)Ú
LanceTableÚTable)ÚLOOP)Úbatch_to_tensorÚbatch_to_tensor_dictÚbatch_to_tensor_rows)ÚAnyÚCallableÚIteratorÚLiteralÚOptionalÚTYPE_CHECKINGÚUnion)ÚpandasÚnumpyÚpolarsc                   óä  — e Zd ZdZdefd„Zdddddddœdeee      deee	      dee	   d	ee	   d
ee	   deee
      dd fd„Zdddœdee
   dee	   dee	   deee
      dd f
d„Zdddddœdeee      deee	      dee	   deee
      dd f
d„Zddddddœde	deee      deee	      dee	   d	ee	   deee
      dd fd„Z	 dde
deee
      dd fd„Zdddœd	ee	   d
ee	   dd fd„Zde
dd fd„Zdefd„Zy) ÚPermutationBuildera  
    A utility for creating a "permutation table" which is a table that defines an
    ordering on a base table.

    The permutation table does not store the actual data.  It only stores row
    ids and split ids to define the ordering.  The [Permutation] class can be used to
    read the data from the base table in the order defined by the permutation table.

    Permutations can split, shuffle, and filter the data in the base table.

    A filter limits the rows that are included in the permutation.
    Splits divide the data into subsets (for example, a test/train split, or K
    different splits for cross-validation).
    Shuffling randomizes the order of the rows in the permutation.

    Splits can optionally be named.  If names are provided it will enable them to
    be referenced by name in the future.  If names are not provided then they can only
    be referenced by their ordinal index.  There is no requirement to name every split.

    The permutation is stored in memory and will be lost when the program exits.
    Útablec                 ó$   — t        |«      | _        y)a(  
        Creates a new permutation builder for the given table.

        By default, the permutation builder will create a single split that contains all
        rows in the same order as the base table.

        Tables with an RTE write spec are rejected: unflushed rows have no row id.
        N)r   Ú_async)Úselfr   s     úX/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/permutation.pyÚ__init__zPermutationBuilder.__init__,   s   € ô 0°Ó6ˆ�ó    N©ÚratiosÚcountsÚfixedÚseedÚ
clump_sizeÚsplit_namesr!   r"   r#   r$   r%   r&   Úreturnc                óH   — | j                   j                  ||||||¬«       | S )aà  
        Configure random splits for the permutation.

        One of ratios, counts, or fixed must be provided.

        If ratios are provided, they will be used to determine the relative size of each
        split. For example, if ratios are [0.3, 0.7] then the first split will contain
        30% of the rows and the second split will contain 70% of the rows.

        If counts are provided, they will be used to determine the absolute number of
        rows in each split. For example, if counts are [100, 200] then the first split
        will contain 100 rows and the second split will contain 200 rows.

        If fixed is provided, it will be used to determine the number of splits.
        For example, if fixed is 3 then the permutation will be split evenly into 3
        splits.

        Rows will be randomly assigned to splits.  The optional seed can be provided to
        make the assignment deterministic.

        If clump_size is provided, rows are shuffled as contiguous groups of that size,
        preserving I/O locality while still randomising the split assignment.

        The optional split_names can be provided to name the splits.  If not provided,
        the splits can only be referenced by their index.
        r    )r   Úsplit_random)r   r!   r"   r#   r$   r%   r&   s          r   r)   zPermutationBuilder.split_random7   s5   € ðH 	�‰× Ñ ØØØØØ!Ø#ð 	!ô 	
ð ˆr   ©Údiscard_weightr&   ÚcolumnsÚsplit_weightsr+   c                óD   — | j                   j                  ||||¬«       | S )aÆ  
        Configure hash-based splits for the permutation.

        First, a hash will be calculated over the specified columns.  The splits weights
        are then used to determine how many rows to assign to each split.  For example,
        if split weights are [1, 2] then the first split will contain 1/3 of the rows
        and the second split will contain 2/3 of the rows.

        The optional discard weight can be provided to determine what percentage of rows
        should be discarded.  For example, if split weights are [1, 2] and discard
        weight is 1 then 25% of the rows will be discarded.

        Hash-based splits are useful if you want the split to be more or less random but
        you don't want the split assignments to change if rows are added or removed
        from the table.

        The optional split_names can be provided to name the splits.  If not provided,
        the splits can only be referenced by their index.
        r*   )r   Ú
split_hash)r   r,   r-   r+   r&   s        r   r/   zPermutationBuilder.split_hashe   s.   € ð6 	�‰×ÑØØØ)Ø#ð	 	ô 	
ð ˆr   ©r!   r"   r#   r&   c                óD   — | j                   j                  ||||¬«       | S )aS  
        Configure sequential splits for the permutation.

        One of ratios, counts, or fixed must be provided.

        If ratios are provided, they will be used to determine the relative size of each
        split. For example, if ratios are [0.3, 0.7] then the first split will contain
        30% of the rows and the second split will contain 70% of the rows.

        If counts are provided, they will be used to determine the absolute number of
        rows in each split. For example, if counts are [100, 200] then the first split
        will contain 100 rows and the second split will contain 200 rows.

        If fixed is provided, it will be used to determine the number of splits.
        For example, if fixed is 3 then the permutation will be split evenly into 3
        splits.

        Rows will be assigned to splits sequentially.  The first N1 rows are assigned to
        split 1, the next N2 rows are assigned to split 2, etc.

        The optional split_names can be provided to name the splits.  If not provided,
        the splits can only be referenced by their index.
        r0   )r   Úsplit_sequential)r   r!   r"   r#   r&   s        r   r2   z#PermutationBuilder.split_sequentialˆ   s+   € ð> 	�‰×$Ñ$Ø &°À;ð 	%ô 	
ð ˆr   ©r!   r"   r#   r$   r&   Únum_samplesc                óH   — | j                   j                  ||||||¬«       | S )a#  
        Sample rows uniformly **with replacement**, independently per split.

        Unlike the other split strategies, the number of output rows is
        ``num_samples``, not the number of (optionally filtered) input rows: the
        same row can appear zero, one, or many times, and ``num_samples`` may be
        larger or smaller than the input row count. Useful for bootstrap
        resampling, oversampling rare classes, or any training workload that
        wants a fixed-size stream of random draws rather than a single
        deterministic pass over every row. Combine with :meth:`filter` to
        restrict the eligible population.

        One of ratios, counts, or fixed must be provided, with the same meaning
        as in :meth:`split_random`, except they divide ``num_samples`` across
        splits rather than the input row count: if fixed is 4, each split gets
        ``num_samples // 4`` samples.

        Each split draws its own sample using a seed derived independently from
        ``(seed, split_index)``, so a split's content does not change if the samples are
        later redistributed across a different number of splits.

        The optional split_names can be provided to name the splits.  If not provided,
        the splits can only be referenced by their index.
        r3   )r   Úbootstrap_sample)r   r4   r!   r"   r#   r$   r&   s          r   r6   z#PermutationBuilder.bootstrap_sample¬   s5   € ðD 	�‰×$Ñ$ØØØØØØ#ð 	%ô 	
ð ˆr   Úcalculationc                 ó@   — | j                   j                  ||¬«       | S )aD  
        Use pre-calculated splits for the permutation.

        The calculation should be an SQL statement that returns an integer value between
        0 and the number of splits - 1.  For example, if you have 3 splits then the
        calculation should return 0 for the first split, 1 for the second split, and 2
        for the third split.

        This can be used to implement any kind of user-defined split strategy.

        The optional split_names can be provided to name the splits.  If not provided,
        the splits can only be referenced by their index.
        )r&   )r   Úsplit_calculated)r   r7   r&   s      r   r9   z#PermutationBuilder.split_calculatedØ   s    € ð  	�‰×$Ñ$ [¸kÐ$ÔJØˆr   ©r$   r%   c                ó@   — | j                   j                  ||¬«       | S )a|  
        Randomly shuffle the rows in the permutation.

        An optional seed can be provided to make the shuffle deterministic.

        If a clump size is provided, then data will be shuffled as small "clumps"
        of contiguous rows.  This allows for a balance between randomization and
        I/O performance.  It can be useful when reading from cloud storage.
        r:   )r   Úshuffle)r   r$   r%   s      r   r<   zPermutationBuilder.shuffleë   s    € ð 	�‰×Ñ °*ÐÔ=Øˆr   Úfilterc                 ó<   — | j                   j                  |«       | S )zã
        Configure a filter for the permutation.

        The filter should be an SQL statement that returns a boolean value for each row.
        Only rows where the filter is true will be included in the permutation.
        )r   r=   )r   r=   s     r   r=   zPermutationBuilder.filterú   s   € ð 	�‰×Ñ˜6Ô"Øˆr   c                 óB   ‡ — ˆ fd„}t        j                   |«       «      S )zM
        Execute the configuration and create the permutation table.
        c               “   ó’   •K  — ‰j                   j                  «       ƒ d {  –—† } t        j                  | «      ƒ d {  –—† S 7 Œ!7 Œ­w©N)r   Úexecuter   Ú
from_inner)Ú	inner_tblr   s    €r   Ú
do_executez.PermutationBuilder.execute.<locals>.do_execute	  s9   øè ø€ Ø"Ÿk™k×1Ñ1Ó3×3ˆIÜ#×.Ñ.¨yÓ9×9Ð9ð 4øØ9ús   ƒA¡A¢A¾A¿AÁA)r	   Úrun)r   rE   s   ` r   rB   zPermutationBuilder.execute  s   ø€ ô
	:ô �x‰x™
›Ó%Ð%r   rA   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   ÚlistÚfloatÚintÚstrr)   r/   r2   r6   r9   r<   r=   r   rB   © r   r   r   r      sI  „ ñð,	7˜eó 	7ð )-Ø&*Ø#Ø"Ø$(Ø+/ò,ð ˜˜e™Ñ%ð,ð ˜˜c™Ñ#ð	,ð
 ˜‰}ð,ð �s‰mð,ð ˜S‘Mð,ð ˜d 3™iÑ(ð,ð 
ó,ðf )-Ø+/ò!à�c‘ð!ð ˜C‘yð!ð
 ! ™ð!ð ˜d 3™iÑ(ð!ð 
ó!ðL )-Ø&*Ø#Ø+/ò"ð ˜˜e™Ñ%ð"ð ˜˜c™Ñ#ð	"ð
 ˜‰}ð"ð ˜d 3™iÑ(ð"ð 
ó"ðP )-Ø&*Ø#Ø"Ø+/ò*àð*ð ˜˜e™Ñ%ð	*ð
 ˜˜c™Ñ#ð*ð ˜‰}ð*ð �s‰mð*ð ˜d 3™iÑ(ð*ð 
ó*ðZ DHñØðØ-5°d¸3±iÑ-@ðà	óð( (,ÈòØ ‘}ðØ9AÀ#¹ðà	óð˜Sð Ð%9ó ð	&˜ô 	&r   r   r   r'   c                 ó   — t        | «      S rA   )r   )r   s    r   Úpermutation_builderrQ     s   € Ü˜eÓ$Ð$r   c                   óZ   — e Zd ZdZdedefd„Zdeddfd„Zd	e	ddfd
„Z
deee	f   ddfd„Zy)ÚPermutationsaè  
    A collection of permutations indexed by name or ordinal index.

    Splits are defined when the permutation is created.  Splits can always be referenced
    by their ordinal index.  If names were provided when the permutation was created
    then they can also be referenced by name.

    Each permutation or "split" is a view of a portion of the base table.  For more
    details see [Permutation].

    Attributes
    ----------
    base_table: Table
        The base table that the permutations are based on.
    permutation_table: LanceTable
        The permutation table that defines the splits.
    split_names: list[str]
        The names of the splits.
    split_dict: dict[str, int]
        A dictionary mapping split names to their ordinal index.

    Examples
    --------
    >>> # Initial data
    >>> import lancedb
    >>> db = lancedb.connect("memory:///")
    >>> tbl = db.create_table("tbl", data=[{"x": x} for x in range(1000)])
    >>> # Create a permutation
    >>> perm_tbl = (
    ...    permutation_builder(tbl)
    ...    .split_random(ratios=[0.95, 0.05], split_names=["train", "test"])
    ...    .shuffle()
    ...    .execute()
    ... )
    >>> # Read the permutations
    >>> permutations = Permutations(tbl, perm_tbl)
    >>> permutations["train"]
    <lancedb.permutation.Permutation ...>
    >>> permutations[0]
    <lancedb.permutation.Permutation ...>
    >>> permutations.split_names
    ['train', 'test']
    >>> permutations.split_dict
    {'train': 0, 'test': 1}
    Ú
base_tableÚpermutation_tablec                 óœ  — || _         || _        |j                  j                  �”|j                  j                  j	                  d«      }|�|j                  d«      nd }|�It        j                  |«      | _        t        | j                  «      D ��ci c]  \  }}||“Œ
 c}}| _
        y g | _        i | _
        y g | _        i | _
        y c c}}w )Nó   split_namesúutf-8)rT   rU   ÚschemaÚmetadataÚgetÚdecodeÚjsonÚloadsr&   Ú	enumerateÚ
split_dict)r   rT   rU   Úrawr&   ÚidxÚnames          r   r   zPermutations.__init__C  s»   € Ø$ˆŒØ!2ˆÔà×#Ñ#×,Ñ,Ð8Ø#×*Ñ*×3Ñ3×7Ñ7¸ÓGˆCØ14°˜#Ÿ*™* WÔ-ÀdˆKØÐ&Ü#'§:¡:¨kÓ#:�Ô ä/8¸×9IÑ9IÓ/J÷#Ù"+ # t�D˜#‘Ió#�•ð
 $&�Ô Ø"$�•ð  "ˆDÔØ ˆD�Oùó#s   ÂCrc   r'   ÚPermutationc                 ó~   — | j                   j                  |d«      }|€t        d|› d�«      ‚| j                  |«      S )zu
        Get a permutation by name.

        If no split named `name` is found then an error will be raised.
        NzNo split named `z` found)r`   r[   Ú
ValueErrorÚget_by_index)r   rc   rb   s      r   Úget_by_namezPermutations.get_by_nameX  sE   € ð �o‰o×!Ñ! $¨Ó-ˆØˆ;ÜÐ/°¨v°WÐ=Ó>Ð>Ø× Ñ  Ó%Ð%r   Úindexc                 óX   — t         j                  | j                  | j                  |«      S )z-
        Get a permutation by index.
        )rd   Úfrom_tablesrT   rU   ©r   ri   s     r   rg   zPermutations.get_by_indexc  s$   € ô ×&Ñ& t§¡¸×8NÑ8NÐPUÓVÐVr   c                 ó¢   — t        |t        «      r| j                  |«      S t        |t        «      r| j	                  |«      S t        d|› �«      ‚)NzInvalid split name or index: )Ú
isinstancerN   rh   rM   rg   Ú	TypeError)r   rc   s     r   Ú__getitem__zPermutations.__getitem__i  sK   € Ü�dœCÔ Ø×#Ñ# DÓ)Ð)Ü˜œcÔ"Ø×$Ñ$ TÓ*Ð*äÐ;¸D¸6ÐBÓCÐCr   N)rG   rH   rI   rJ   r   r   r   rN   rh   rM   rg   r   rp   rO   r   r   rS   rS     sb   „ ñ,ð\! 5ð !¸Zó !ð*	& ð 	&¨ó 	&ðW #ð W¨-ó WðD  c¨3 h¡ð D°Mô Dr   rS   c                   ó<  — e Zd ZdZedej                  deee	e
f      fd„«       Zedej                  dee	ee
   f   fd„«       Zedej                  dej                  fd„«       Zedej                  ddfd„«       Zedej                  dd	fd
„«       Zedd„«       Zy)Ú
Transformsz7
    Namespace for common transformation functions
    Úbatchr'   c                 ó"   — | j                  «       S rA   )Ú	to_pylist©rs   s    r   Úarrow2pythonzTransforms.arrow2pythonw  ó   € à�‰Ó Ð r   c                 ó"   — | j                  «       S rA   )Ú	to_pydictrv   s    r   Úarrow2pythoncolzTransforms.arrow2pythoncol{  rx   r   c                 ó   — | S rA   rO   rv   s    r   Úarrow2arrowzTransforms.arrow2arrow  s   € àˆr   z
np.ndarrayc                 ó>   — | j                  «       j                  «       S rA   )Ú	to_pandasÚto_numpyrv   s    r   Úarrow2numpyzTransforms.arrow2numpyƒ  s   € à�‰Ó ×)Ñ)Ó+Ð+r   zpd.DataFramec                 ó"   — | j                  «       S rA   )r   rv   s    r   Úarrow2pandaszTransforms.arrow2pandas‡  rx   r   c                  óT   ‡— dd l Šdt        j                  d‰j                  fˆfd„} | S )Nr   rs   r'   c                 ó(   •—  ‰j                   | «      S rA   )Ú
from_arrow)rs   Úpls    €r   Úimplz%Transforms.arrow2polars.<locals>.impl�  s   ø€ Ø �2—=‘= Ó'Ð'r   )r   ÚpaÚRecordBatchÚ	DataFrame)rˆ   r‡   s    @r   Úarrow2polarszTransforms.arrow2polars‹  s(   ø€ ãð	(œŸ™ð 	(¨2¯<©<õ 	(ð ˆr   N)r'   zpl.DataFrame)rG   rH   rI   rJ   Ústaticmethodr‰   rŠ   rK   ÚdictrN   r   rw   r{   r}   r�   rƒ   rŒ   rO   r   r   rr   rr   r  s÷   „ ñð ð!˜BŸN™Nð !¨t°D¸¸c¸±NÑ/Cò !ó ð!ð ð!˜rŸ~™~ð !°$°s¸DÀ¹I°~Ñ2Fò !ó ð!ð ð˜2Ÿ>™>ð ¨b¯n©nò ó ðð ð,˜2Ÿ>™>ð ,¨lò ,ó ð,ð ð!˜BŸN™Nð !¨~ò !ó ð!ð òó ñr   rr   éd   c                 óh  — ddl m} t        | |«      rd| dœS t        | t        «      st	        dt        | «      ›�«      ‚| j                  j                  }|j                  d«      rd| j                  | j                  «       dœS d	| j                  || j                  | j                  j                  d
œS )Nr   )ÚRemoteTableÚremote)Úkindr   zCannot pickle table of type ú	memory://Úmemory)r“   rc   ÚdataÚlocal)r“   rc   ÚuriÚ	namespaceÚstorage_options)Úremote.tabler‘   rn   r   rf   ÚtypeÚ_connr˜   Ú
startswithrc   Úto_arrowÚ_namespace_pathrš   )r   r‘   Úbase_uris      r   Ú_table_to_pickle_stater¢   ™  sª   € Ý)ä�%˜Ô%àØñ
ð 	
ô
 �eœZÔ(ÜÐ7¼¸U»°ÐGÓHÐHà�{‰{�‰€HØ×Ñ˜;Ô'àØ—J‘JØ—N‘NÓ$ñ
ð 	
ð Ø—
‘
ØØ×*Ñ*Ø Ÿ;™;×6Ñ6ñð r   Úpermutation_datac                 ó¶   — t        | j                  j                  xs i «      }|j                  dd«      €| S |j                  dd«       | j	                  |«      S )zMStrip the recorded base version so the reader leaves the base table unpinned.s   base_versionNs   base_branch)rŽ   rY   rZ   ÚpopÚreplace_schema_metadata)r£   rZ   s     r   Ú_drop_base_versionr§   ¶  sT   € äÐ$×+Ñ+×4Ñ4Ò:¸Ó;€HØ‡|�|�O TÓ*Ð2ØÐØ‡L�L� Ô&Ø×3Ñ3°HÓ=Ð=r   Ústatec                 óò   — ddl m} | d   }|dk(  r| d   S |dk(  r |d«      j                  | d   | d	   «      S |d
k(  r- || d   | d   ¬«      }|j                  | d   | d   xs d ¬«      S t	        d|› �«      ‚)Nr   ©Úconnectr“   r’   r   r•   r”   rc   r–   r—   r˜   rš   ©rš   r™   ©Únamespace_pathz!Unknown table pickle state kind: )Ú r«   Úcreate_tableÚ
open_tablerf   )r¨   r«   r“   Údbs       r   Ú_table_from_pickle_stater³   ¿  sš   € Ýà�‰=€DØˆxÒØ�W‰~ÐØˆxÒÙ�{Ó#×0Ñ0°°v±ÀÀfÁÓNÐNØˆw‚Ù�U˜5‘\°5Ð9JÑ3KÔLˆØ�}‰}˜U 6™]¸5ÀÑ;MÒ;UÐQUˆ}ÓVÐVÜ
Ð8¸¸Ð?Ó
@Ð@r   c                   ó   — e Zd ZdZ	 	 	 	 dEdedee   dedeeef   dede	e
j                  ef   d	ee   d
ee   dee	egef      dee   fd„Zdefd„Zdeeef   dd fd„Zdedd fd„Zde	egef   dd fd„Zededd fd„«       Ze	 	 dFdedee   deeeef      dd fd„«       Zdeeef   fd„Zdeeef   ddfd„ZdGd„Zede
j6                  fd„«       Zedefd„«       Zedefd„«       Zedee   fd„«       Z ede!eef   fd„«       Z"defd„Z#d edee   fd!„Z$dHd"„Z%d#ee   dd fd$„Z&d%ed&edd fd'„Z'd(eeef   dd fd)„Z(d#ee   dd fd*„Z)de*eeef      fd+„Z+	 dIded,e,de*eeef      fd-„Z-d.e.d/   dd fd0„Z/d1e	e
j                  ef   dd fd2„Z0d3ee   defd4„Z1d5edefd6„Z2d7ee   defd8„Z3 e4d9¬:«      d;edd fd<„«       Z5d;edd fd=„Z6 e4d>¬:«      d
edd fd?„«       Z7d
edd fd@„Z8 e4dA¬:«      dBedd fdC„«       Z9dBedd fdD„Z:y)Jrd   aü  
    A Permutation is a view of a dataset that can be used as input to model training
    and evaluation.

    A Permutation fulfills the pytorch Dataset contract and is loosely modeled after the
    huggingface Dataset so it should be easy to use with existing code.

    A permutation is not a "materialized view" or copy of the underlying data.  It is
    calculated on the fly from the base table.  As a result, it is truly "lazy" and does
    not require materializing the entire dataset in memory.
    NrT   rU   ÚsplitÚ	selectionÚ
batch_sizeÚtransform_fnÚoffsetÚlimitÚconnection_factoryÚ_readerc                 ó0  — |€J d«       ‚|€J d«       ‚|| _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
€#t        j                  | j                  «       «      }
|
| _        t        j                  «       | _        y)zx
        Internal constructor.  Use
        [from_tables][lancedb.permutation.Permutation.from_tables] instead.
        Núbase_table is requiredzselection is required)rT   rU   rµ   r¶   r¸   r·   r¹   rº   r»   r	   rF   Ú_build_readerÚreaderÚosÚgetpidÚ_pid)r   rT   rU   rµ   r¶   r·   r¸   r¹   rº   r»   r¼   s              r   r   zPermutation.__init__Ú  sš   € ð" Ð%Ð?Ð'?Ó?Ð%ØÐ$Ð=Ð&=Ó=Ð$Ø$ˆŒØ!2ˆÔØˆŒ
Ø"ˆŒØ(ˆÔØ$ˆŒØˆŒØˆŒ
Ø"4ˆÔØˆ?Ü—h‘h˜t×1Ñ1Ó3Ó4ˆGØ)0ˆŒÜ—I‘I“Kˆ�	r   r'   c              ƒ   óP  K  — t        j                  | j                  | j                  | j                  «      ƒ d {  –—† }| j
                  �#|j                  | j
                  «      ƒ d {  –—† }| j                  �#|j                  | j                  «      ƒ d {  –—† }|S 7 Œd7 Œ77 Œ
­wrA   )	r   rk   rT   rU   rµ   r¹   Úwith_offsetrº   Ú
with_limit)r   rÀ   s     r   r¿   zPermutation._build_readerû  sˆ   è ø€ Ü(×4Ñ4Ø�O‰O˜T×3Ñ3°T·Z±Zó
÷ 
ˆð �;‰;Ð"Ø!×-Ñ-¨d¯k©kÓ:×:ˆFØ�:‰:Ð!Ø!×,Ñ,¨T¯Z©ZÓ8×8ˆFØˆð
øð ;øà8ús3   ‚9B&»B ¼.B&Á*B"Á+.B&ÂB$ÂB&Â"B&Â$B&c                 ó>   — t        j                   | «      }||_        |S )z½
        Creates a new permutation with the given selection

        Does not validation of the selection and it replaces it entirely.  This is not
        intended for public use.
        )Úcopyr¶   )r   r¶   Únews      r   Ú_with_selectionzPermutation._with_selection  s   € ô �i‰i˜‹oˆØ!ˆŒØˆ
r   c                 ó>   — t        j                   | «      }||_        |S )zE
        Creates a new permutation with the given batch size
        )rÈ   r·   )r   r·   rÉ   s      r   Úwith_batch_sizezPermutation.with_batch_size  s   € ô �i‰i˜‹oˆØ#ˆŒØˆ
r   c                 óP   — |€J d«       ‚t        j                   | «      }||_        |S )a|  
        Creates a new permutation that will use ``connection_factory`` to reopen
        the base table when this permutation is unpickled in a worker process.

        The factory is a callable that takes a single argument, the base table
        name, and returns a LanceDB table. It must be picklable; the worker
        will pickle it via standard ``pickle`` and call it to recover the base
        table. Picklable callables in practice means top-level (module-level)
        functions, ``functools.partial`` of such functions, or instances of
        picklable classes implementing ``__call__``. Lambdas and closures over
        local variables don't pickle with the default protocol.

        A factory is optional for normal local and remote LanceDB connections:
        if not set, ``__getstate__`` captures the table's own picklable reopen
        state. Use a factory when that default state is not enough, for example
        when credentials should be loaded from the worker environment instead
        of being embedded in the pickle.

        Examples
        --------
        Basic native (file-system path), parameterized via ``functools.partial``::

            import functools, lancedb
            from lancedb.permutation import Permutation

            def open_native_table(uri: str, table_name: str):
                return lancedb.connect(uri).open_table(table_name)

            factory = functools.partial(open_native_table, "/data/lance_db")
            permutation = Permutation.identity(
                factory("training")
            ).with_connection_factory(factory)

        Native via :func:`lancedb.connect_namespace` (e.g. a directory- or
        REST-backed namespace client). The factory takes the
        implementation name and properties dict as partial-bound args so
        the worker can rebuild the same namespace connection::

            def open_via_namespace(
                impl: str, properties: dict[str, str], table_name: str,
            ):
                return lancedb.connect_namespace(impl, properties).open_table(
                    table_name,
                )

            factory = functools.partial(
                open_via_namespace,
                "dir",
                {"root": "/data/lance_db"},
            )

        LanceDB Cloud, reading credentials from env vars at worker startup
        so secrets aren't pickled into the dataset::

            import os, lancedb

            def open_remote_table(table_name: str):
                db = lancedb.connect(
                    "db://my-database",
                    api_key=os.environ["LANCEDB_API_KEY"],
                    region=os.environ.get("LANCEDB_REGION", "us-east-1"),
                )
                return db.open_table(table_name)

            permutation = Permutation.identity(
                open_remote_table("training")
            ).with_connection_factory(open_remote_table)
        zconnection_factory is required)rÈ   r»   )r   r»   rÉ   s      r   Úwith_connection_factoryz#Permutation.with_connection_factory  s1   € ðN "Ð-ÐOÐ/OÓOÐ-Ü�i‰i˜‹oˆØ!3ˆÔØˆ
r   r   c                 ó0   — t         j                  |dd«      S )zF
        Creates an identity permutation for the given table.
        N)rd   rk   )Úclsr   s     r   ÚidentityzPermutation.identityd  s   € ô
 ×&Ñ& u¨d°DÓ9Ð9r   c                 óR  ‡ ‡‡‡— ‰€J d«       ‚‰�Ö‰€t        d«      ‚t        ‰t        «      r˜‰j                  j                  €t        d‰› d�«      ‚‰j                  j                  j                  d«      }|�|j                  d«      nd}|€t        d‰› d�«      ‚t        j                  |«      }	 |j                  ‰«      Šn#t        ‰t        «      r‰Šnt        d
‰› �«      ‚dŠˆˆ ˆˆfd„}t        j                   |«       «      S # t         $ r t        d‰› d‰› d	�«      ‚w xY w)am  
        Creates a permutation from the given base table and permutation table.

        A permutation table identifies which rows, and in what order, the data should
        be read from the base table.  For more details see the [PermutationBuilder]
        class.

        If no permutation table is provided, then the identity permutation will be
        created.  An identity permutation is a permutation that reads all rows in the
        base table in the order they are stored.

        The split parameter identifies which split to use.  If no split is provided
        then the first split will be used.
        Nr¾   zWCannot create a permutation on split `{split}` because no permutation table is providedz&Cannot create a permutation on split `z=` because no split names are defined in the permutation tablerW   rX   z` because split `z)` is not defined in the permutation tablezInvalid split: r   c            	   “   ó  •K  — t        j                  ‰‰‰«      ƒ d {  –—† } | j                  d «      ƒ d {  –—† }|j                  D �ci c]  }||“Œ }} ‰‰‰‰|t        t
        j                  | ¬«      S 7 ŒX7 ŒAc c}w ­w)N)r¼   )r   rk   Úoutput_schemaÚnamesÚDEFAULT_BATCH_SIZErr   rw   )rÀ   rY   rc   Úinitial_selectionrT   rÐ   rU   rµ   s       €€€€r   Údo_from_tablesz/Permutation.from_tables.<locals>.do_from_tables¤  s‹   øè ø€ Ü,×8Ñ8ØÐ-¨uó÷ ˆFð "×/Ñ/°Ó5×5ˆFØ8>¿¹Ö E°  t¡Ð EÐÐ EÙØØ!ØØ!Ü"Ü×'Ñ'Øôð ðøð 6úÚ Eùs1   ƒB žA7ŸB ·A9¸B Á

A;Á$B Á9B Á;B )rf   rn   rN   rY   rZ   r[   r\   r]   r^   ri   rM   ro   r	   rF   )rÐ   rT   rU   rµ   ra   r&   rØ   s   ````   r   rk   zPermutation.from_tablesk  sn  û€ ð* Ð%Ð?Ð'?Ó?Ð%ØÐØ Ð(Ü ð@óð ô ˜%¤Ô%Ø$×+Ñ+×4Ñ4Ð<Ü$Ø@ÀÀð HWð Wóð ð (×.Ñ.×7Ñ7×;Ñ;¸NÓK�Ø58°_˜cŸj™j¨Ô1È$�ØÐ&Ü$Ø@ÀÀð HWð Wóð ô #Ÿj™j¨Ó5�ðØ'×-Ñ-¨eÓ4‘Eô ˜E¤3Ô'Ø‘ä /°%°Ð 9Ó:Ð:àˆE÷	ô  �x‰x™Ó(Ó)Ð)øô; "ò Ü$Ø@ÀÀð H+Ø+0¨'ð 2,ð,óð ðús   Â3D
 Ä
D&c           
      óp  — d}| j                   �| j                   j                  «       }| j                  j                  || j                  | j
                  | j                  | j                  | j                  | j                  | j                  dœ	}| j                  �|S i |¥dt        | j                  «      i¥S )aÀ  Build a picklable state dict for this permutation.

        The base table is captured either via a user-supplied
        ``connection_factory`` (see [with_connection_factory]) or, as a
        fallback, by the table's own picklable reopen state. The permutation
        table is captured as a pyarrow Table (which pickles via Arrow IPC
        natively). The reader is dropped from the wire format and rebuilt
        lazily on first use.
        N)	Úbase_table_namer£   rµ   r¶   r·   r¸   r¹   rº   r»   Úbase_table_state)rU   rŸ   rT   rc   rµ   r¶   r·   r¸   r¹   rº   r»   r¢   )r   r£   Úcommons      r   Ú__getstate__zPermutation.__getstate__¶  s´   € ð 04ÐØ×!Ñ!Ð-Ø#×5Ñ5×>Ñ>Ó@Ðð  $Ÿ™×3Ñ3Ø 0Ø—Z‘ZØŸ™ØŸ/™/Ø ×-Ñ-Ø—k‘kØ—Z‘ZØ"&×"9Ñ"9ñ

ˆð ×"Ñ"Ð.ð ˆMð
Øð
àÔ 6°t·±Ó Gñ
ð 	
r   r¨   c                 ó:  — ddl m} |d   }d}|� ||d   «      }nqd|v r|d   }|d   dk(  }t        |«      }nTd	|v r#d
} |d«      }|j                  |d   |d	   «      }n- ||d   |d   ¬«      }|j	                  |d   |d   xs d ¬«      }d }	|d   }
|
�'|rt        |
«      }
 |d«      }|j                  d|
«      }	|| _        |	| _        |d   | _        |d   | _	        |d   | _
        |d   | _        |d   | _        |d   | _        || _        d | _        d | _        y )Nr   rª   r»   FrÚ   rÛ   r“   r•   Úbase_table_dataTr”   Úbase_table_uriÚbase_table_storage_optionsr¬   Úbase_table_namespacer­   r£   Úpermutationrµ   r¶   r·   r¸   r¹   rº   )r¯   r«   r³   r°   r±   r§   rT   rU   rµ   r¶   r·   r¸   r¹   rº   r»   rÀ   rÃ   )r   r¨   r«   r»   Úrebuilt_baserT   Ú
base_stateÚmem_dbÚbase_dbrU   r£   s              r   Ú__setstate__zPermutation.__setstate__Û  s’  € Ýà"Ð#7Ñ8ÐØˆØÐ)Ù+¨EÐ2CÑ,DÓE‰JØ 5Ñ(ØÐ1Ñ2ˆJØ% fÑ-°Ñ9ˆLÜ1°*Ó=‰JØ %Ñ'ØˆLñ ˜[Ó)ˆFØ×,Ñ,ØÐ'Ñ(¨%Ð0AÑ*Bó‰Jñ ØÐ&Ñ'Ø %Ð&BÑ CôˆGð !×+Ñ+ØÐ'Ñ(Ø$Ð%;Ñ<ÒDÀð ,ó ˆJð
 .2ÐØ Ð!3Ñ4ÐØÐ'Ùô $6Ð6FÓ#GÐ Ù˜[Ó)ˆFØ &× 3Ñ 3°MÐCSÓ TÐà$ˆŒØ!2ˆÔØ˜7‘^ˆŒ
Ø˜{Ñ+ˆŒØ Ñ-ˆŒØ! .Ñ1ˆÔØ˜H‘oˆŒØ˜7‘^ˆŒ
Ø"4ˆÔØˆŒØˆ�	r   c                 óœ  — t        j                  «       }| j                  �t        | dd «      |k(  ry t	        | j
                  d«      r| j
                  j                  «        | j                  �0t	        | j                  d«      r| j                  j                  «        t        j                  | j                  «       «      | _        || _        y )NrÃ   Ú_ensure_open)rÁ   rÂ   rÀ   ÚgetattrÚhasattrrT   rê   rU   r	   rF   r¿   rÃ   )r   Úpids     r   rê   zPermutation._ensure_open  sœ   € Ü�i‰i‹kˆØ�;‰;Ð"¤w¨t°V¸TÓ'BÀcÒ'IØô �4—?‘? NÔ3Ø�O‰O×(Ñ(Ô*Ø×!Ñ!Ð-´'Ø×"Ñ" Nô3
ð ×"Ñ"×/Ñ/Ô1Ü—h‘h˜t×1Ñ1Ó3Ó4ˆŒØˆ�	r   c                 ób   ‡ — ‰ j                  «        ˆ fd„}t        j                   |«       «      S )Nc               “   ój   •K  — ‰ j                   j                  ‰ j                  «      ƒ d {  –—† S 7 Œ­wrA   )rÀ   rÔ   r¶   ©r   s   €r   Údo_output_schemaz,Permutation.schema.<locals>.do_output_schema!  s&   øè ø€ ØŸ™×2Ñ2°4·>±>ÓB×BÐBÐBús   ƒ)3¬1­3)rê   r	   rF   )r   rñ   s   ` r   rY   zPermutation.schema  s*   ø€ à×ÑÔô	Cô �x‰xÑ(Ó*Ó+Ð+r   c                 ó,   — t        | j                  «      S )z:
        The number of columns in the permutation
        )ÚlenrY   rð   s    r   Únum_columnszPermutation.num_columns&  s   € ô
 �4—;‘;ÓÐr   c                 óV   — | j                  «        | j                  j                  «       S )z7
        The number of rows in the permutation
        )rê   rÀ   Ú
count_rowsrð   s    r   Únum_rowszPermutation.num_rows-  s#   € ð
 	×ÑÔØ�{‰{×%Ñ%Ó'Ð'r   c                 ó.   — | j                   j                  S )z=
        The names of the columns in the permutation
        )rY   rÕ   rð   s    r   Úcolumn_nameszPermutation.column_names5  s   € ð
 �{‰{× Ñ Ð r   c                 ó2   — | j                   | j                  fS )zh
        The shape of the permutation

        This will return self.num_rows, self.num_columns
        )r÷   rô   rð   s    r   ÚshapezPermutation.shape<  s   € ð �}‰}˜d×.Ñ.Ð.Ð.r   c                 ó   — | j                   S )zŠ
        The number of rows in the permutation

        This is an alias for [num_rows][lancedb.permutation.Permutation.num_rows]
        )r÷   rð   s    r   Ú__len__zPermutation.__len__E  s   € ð �}‰}Ðr   Ú_columnc                 ó   — t        d«      ‚)z;
        Get the unique values in the given column
        zunique is not yet implemented©Ú	Exception)r   rþ   s     r   ÚuniquezPermutation.uniqueM  s   € ô Ð7Ó8Ð8r   c                 ó   — t        d«      ‚)a/  
        Flatten the permutation

        Each column with a struct type will be flattened into multiple columns.

        This flattening operation happens at read time as a post-processing step
        so this call is cheap and no data is copied or modified in the underlying
        dataset.
        zflatten is not yet implementedr   rð   s    r   ÚflattenzPermutation.flattenS  s   € ô Ð8Ó9Ð9r   r,   c                 óØ   — |€J d«       ‚| j                   j                  «       D ��ci c]  \  }}||vsŒ||“Œ }}}t        |«      dk(  rt        d«      ‚| j	                  |«      S c c}}w )aY  
        Remove the given columns from the permutation

        Note: this does not actually modify the underlying dataset.  It only changes
        which columns are visible from this permutation.  Also, this does not introduce
        a post-processing step.  Instead, we simply do not read those columns in the
        first place.

        If any of the provided columns does not exist in the current permutation then it
        will be ignored (no error is raised for missing columns)

        Returns a new permutation with the given columns removed.  This does not modify
        self.
        úcolumns is requiredr   zCannot remove all columns)r¶   Úitemsró   rf   rÊ   )r   r,   rc   ÚvalueÚnew_selections        r   Úremove_columnszPermutation.remove_columns_  s€   € ð Ð"Ð9Ð$9Ó9Ð"ð ,0¯>©>×+?Ñ+?Ó+A÷
Ù'˜D %ÀTÐQXÒEXˆD�%‰Kð
ˆñ 
ô ˆ}Ó Ò"ÜÐ8Ó9Ð9à×#Ñ# MÓ2Ð2ùó
s
   §A&´A&Úold_nameÚnew_namec                 ó6  — |€J d«       ‚|€J d«       ‚|| j                   vrt        d|› d�«      ‚|| j                   v rt        d|› d|› d�«      ‚| j                   j                  «       D ��ci c]  \  }}||k(  r|n||“Œ }}}| j                  |«      S c c}}w )aé  
        Rename a column in the permutation

        If there is no column named old_name then an error will be raised
        If there is already a column named new_name then an error will be raised

        Note: this does not actually modify the underlying dataset.  It only changes
        the name of the column that is visible from this permutation.  This is a
        post-processing step but done at the batch level and so it is very cheap.
        No data will be copied.
        zold_name is requiredznew_name is requiredzCannot rename column `ú` because it does not existz` to `z0` because a column with that name already exists)r¶   rf   r  rÊ   )r   r  r  rc   r  r	  s         r   Úrename_columnzPermutation.rename_columny  s×   € ð Ð#Ð;Ð%;Ó;Ð#ØÐ#Ð;Ð%;Ó;Ð#Ø˜4Ÿ>™>Ñ)ÜØ(¨¨
Ð2MÐNóð ð �t—~‘~Ñ%ÜØ(¨¨
°&¸¸
ð C0ð 0óð ð  $Ÿ~™~×3Ñ3Ó5÷
á��eð  Ò)‰X¨t°eÑ;ð
ˆñ 
ð ×#Ñ# MÓ2Ð2ùó	
s   Á-BÚ
column_mapc                 óp   — |€J d«       ‚| }|j                  «       D ]  \  }}|j                  ||«      }Œ |S )aê  
        Rename the given columns in the permutation

        If any of the columns do not exist then an error will be raised
        If any of the new names already exist then an error will be raised

        Note: this does not actually modify the underlying dataset.  It only changes
        the name of the column that is visible from this permutation.  This is a
        post-processing step but done at the batch level and so it is very cheap.
        No data will be copied.
        zcolumn_map is required)r  r  )r   r  Únew_permutationr  r  s        r   Úrename_columnszPermutation.rename_columns—  sR   € ð Ð%Ð?Ð'?Ó?Ð%àˆØ",×"2Ñ"2Ó"4ò 	PÑˆH�hØ-×;Ñ;¸HÀhÓO‰Oð	PàÐr   c                 óî   — |€J d«       ‚t        |«      dk(  rt        d«      ‚i }|D ]<  }| j                  j                  |d«      }|€|dk(  rd}nt        d|› d�«      ‚|||<   Œ> | j	                  |«      S )a�  
        Select the given columns from the permutation

        This method refines the current selection, potentially removing columns.  It
        will not add back columns that were previously removed.

        If any of the columns do not exist then an error will be raised.

        This does not introduce a post-processing step.  It simply reduces the amount
        of data we read.
        Nr  r   zMust select at least one columnÚ_rowidzCannot select column `r  )ró   rf   r¶   r[   rÊ   )r   r,   r	  rc   r  s        r   Úselect_columnszPermutation.select_columnsª  s¥   € ð Ð"Ð9Ð$9Ó9Ð"Üˆw‹<˜1ÒÜÐ>Ó?Ð?àˆØò 	(ˆDØ—N‘N×&Ñ& t¨TÓ2ˆEØˆ}Ø˜8Ò#ð %‘Eä$Ø0°°Ð6QÐRóð ð #(ˆM˜$Òð	(ð ×#Ñ# MÓ2Ð2r   c                 ó<   — | j                  | j                  d¬«      S )z.
        Iterate over the permutation
        T)Úskip_last_batch)Úiterr·   rð   s    r   Ú__iter__zPermutation.__iter__É  s   € ð �y‰y˜Ÿ™¸$ˆyÓ?Ð?r   r  c              #   ó  ‡ ‡‡K  — ‰ j                  «        ˆˆ fd„}t        j                   |«       «      Šˆfd„}	 	 t        j                   |«       «      }|j                  ‰k(  s|s‰ j	                  |«      –— Œ?# t
        $ r Y yw xY w­w)z¬
        Iterate over the permutation in batches

        If skip_last_batch is True, the last batch will be skipped if it is not a
        multiple of batch_size.
        c               “   ón   •K  — ‰j                   j                  ‰j                  ‰ ¬«      ƒ d {  –—† S 7 Œ­w)N)r·   )rÀ   Úreadr¶   )r·   r   s   €€r   Úget_iterz"Permutation.iter.<locals>.get_iterÚ  s+   øè ø€ ØŸ™×)Ñ)¨$¯.©.ÀZÐ)ÓP×PÐPÐPúó   ƒ+5®3¯5c               “   ó@   •K  — ‰ j                  «       ƒ d {  –—† S 7 Œ­wrA   )Ú	__anext__)Ú
async_iters   €r   Úget_nextz"Permutation.iter.<locals>.get_nextß  s   øè ø€ Ø#×-Ñ-Ó/×/Ð/Ð/ús   ƒ—˜N)rê   r	   rF   r÷   r¸   ÚStopAsyncIteration)r   r·   r  r  r#  rs   r"  s   ``    @r   r  zPermutation.iterÏ  s�   úè ø€ ð 	×ÑÔõ	Qô —X‘X™h›jÓ)ˆ
ô	0ð	ØÜŸ™¡£Ó,�Ø—>‘> ZÒ/±Ø×+Ñ+¨EÓ2Ò2ð øô "ò 	Ùð	üs#   …6B¼A A< Á<	BÂBÂBÂBÚformat)	r   ÚpythonÚ
python_colr   ÚarrowÚtorchÚ	torch_rowÚ	torch_colr   c                 ó„  — |€J d«       ‚|dk(  r| j                  t        j                  «      S |dk(  r| j                  t        j                  «      S |dk(  r| j                  t        j                  «      S |dk(  r| j                  t        j
                  «      S |dk(  r| j                  t        j                  «      S |dk(  r| j                  t        «      S |dk(  r| j                  t        «      S |d	k(  r| j                  t        «      S |d
k(  r#| j                  t        j                  «       «      S t        d|› �«      ‚)a`  
        Set the format for batches

        If this method is not called, the "python" format will be used.

        The format can be one of:
        - "numpy" - the batch will be a dict of numpy arrays (one per column)
        - "python" - the batch will be a list of dicts (one per row)
        - "python_col" - the batch will be a dict of lists (one entry per column)
        - "pandas" - the batch will be a pandas DataFrame
        - "arrow" - the batch will be a pyarrow RecordBatch
        - "torch" - the batch will be a list of per-row dicts mapping column
          name to a 0-D torch tensor. Works with the default
          ``torch.utils.data.DataLoader`` collate, which stacks the per-row
          dicts back into a dict of batched tensors.
        - "torch_row" - the batch will be a list of tensors, one per row
        - "torch_col" - the batch will be a 2D torch tensor (first dim indexes columns)
        - "polars" - the batch will be a polars DataFrame

        Conversion may or may not involve a data copy.  Lance uses Arrow internally
        and so it is able to zero-copy to the arrow and polars formats.

        Conversion to torch and torch_col will be zero-copy but will only support a
        subset of data types (numeric types).

        Conversion to numpy and/or pandas will typically be zero-copy for numeric
        types.  Conversion of strings, lists, and structs will require creating python
        objects and this is not zero-copy.

        For custom formatting, use
        [with_transform][lancedb.permutation.Permutation.with_transform] which
        overrides this method.
        zformat is requiredr&  r'  r   r   r(  r)  r*  r+  r   zInvalid format: )Úwith_transformrr   rw   r{   r�   rƒ   r}   r   r   r
   rŒ   rf   )r   r%  s     r   Úwith_formatzPermutation.with_formatê  s4  € ð^ Ð!Ð7Ð#7Ó7Ð!Ø�XÒØ×&Ñ&¤z×'>Ñ'>Ó?Ð?Ø�\Ò!Ø×&Ñ&¤z×'AÑ'AÓBÐBØ�wÒØ×&Ñ&¤z×'=Ñ'=Ó>Ð>Ø�xÒØ×&Ñ&¤z×'>Ñ'>Ó?Ð?Ø�wÒØ×&Ñ&¤z×'=Ñ'=Ó>Ð>Ø�wÒØ×&Ñ&Ô';Ó<Ð<Ø�{Ò"Ø×&Ñ&Ô';Ó<Ð<Ø�{Ò"Ø×&Ñ&¤Ó7Ð7Ø�xÒØ×&Ñ&¤z×'>Ñ'>Ó'@ÓAÐAäÐ/°¨xÐ8Ó9Ð9r   Ú	transformc                 óP   — |€J d«       ‚t        j                   | «      }||_        |S )ab  
        Set a custom transform for the permutation

        The transform is a callable that will be invoked with each record batch.  The
        return value will be used as the batch for iteration.

        Note: transforms are not invoked in parallel.  This method is not a good place
        for expensive operations such as image decoding.
        ztransform is required)rÈ   r¸   )r   r/  rÉ   s      r   r-  zPermutation.with_transform/  s0   € ð Ð$Ð=Ð&=Ó=Ð$Ü�i‰i˜‹oˆØ$ˆÔØˆ
r   Úoffsetsc                 óˆ   ‡ ‡— ‰ j                  «        ˆˆ fd„}t        j                   |«       «      }‰ j                  |«      S )zý
        Take rows from the permutation by offset

        The returned value is passed through the permutation's current transform,
        so `with_format` and `with_transform` affect this method in the same way
        they affect iteration.
        c               “   ón   •K  — ‰j                   j                  ‰ ‰j                  ¬«      ƒ d {  –—† S 7 Œ­w)N)r¶   )rÀ   Útake_offsetsr¶   )r1  r   s   €€r   Údo_take_offsetsz1Permutation.take_offsets.<locals>.do_take_offsetsH  s+   øè ø€ ØŸ™×1Ñ1°'ÀTÇ^Á^Ð1ÓT×TÐTÐTúr  )rê   r	   rF   r¸   )r   r1  r5  rs   s   ``  r   r4  zPermutation.take_offsets>  s;   ù€ ð 	×ÑÔõ	Uô —‘™Ó*Ó+ˆØ× Ñ  Ó'Ð'r   ri   c                 ó&   — | j                  |g«      S )zE
        Returns a single row from the permutation by offset
        ©r4  rl   s     r   rp   zPermutation.__getitem__N  s   € ð × Ñ  % Ó)Ð)r   Úindicesc                 ó$   — | j                  |«      S )z=
        Returns rows from the permutation by offset
        r7  )r   r8  s     r   Ú__getitems__zPermutation.__getitems__T  s   € ð × Ñ  Ó)Ð)r   zUse with_skip instead)ÚdetailsÚskipc                 ó$   — | j                  |«      S )aB  
        Skip the first `skip` rows of the permutation

        Note: this method returns a new permutation and does not modify `self`
        It is provided for compatibility with the huggingface Dataset API.

        Use [with_skip][lancedb.permutation.Permutation.with_skip] instead to
        avoid confusion.
        )Ú	with_skip)r   r<  s     r   r<  zPermutation.skipZ  s   € ð �~‰~˜dÓ#Ð#r   c                 óà   — | j                  «        t        j                  | «      }||_        t        j                  |j                  «       «      |_        t        j                  «       |_	        |S )z?
        Skip the first `skip` rows of the permutation
        )
rê   rÈ   r¹   r	   rF   r¿   rÀ   rÁ   rÂ   rÃ   )r   r<  rÉ   s      r   r>  zPermutation.with_skipg  sO   € ð 	×ÑÔÜ�i‰i˜‹oˆØˆŒ
Ü—X‘X˜c×/Ñ/Ó1Ó2ˆŒ
Ü—9‘9“;ˆŒØˆ
r   zUse with_take insteadc                 ó$   — | j                  |«      S )aQ  
        Limit the permutation to `limit` rows (following any `skip`)

        Note: this method returns a new permutation and does not modify `self`
        It is provided for compatibility with the huggingface Dataset API.

        Use [with_take][lancedb.permutation.Permutation.with_take] instead to
        avoid confusion.
        )Ú	with_take)r   rº   s     r   ÚtakezPermutation.taker  s   € ð �~‰~˜eÓ$Ð$r   c                 óà   — | j                  «        t        j                  | «      }||_        t        j                  |j                  «       «      |_        t        j                  «       |_	        |S )zN
        Limit the permutation to `limit` rows (following any `skip`)
        )
rê   rÈ   rº   r	   rF   r¿   rÀ   rÁ   rÂ   rÃ   )r   rº   rÉ   s      r   rA  zPermutation.with_take  sO   € ð 	×ÑÔÜ�i‰i˜‹oˆØˆŒ	Ü—X‘X˜c×/Ñ/Ó1Ó2ˆŒ
Ü—9‘9“;ˆŒØˆ
r   zUse with_repeat insteadÚtimesc                 ó$   — | j                  |«      S )a=  
        Repeat the permutation `times` times

        Note: this method returns a new permutation and does not modify `self`
        It is provided for compatibility with the huggingface Dataset API.

        Use [with_repeat][lancedb.permutation.Permutation.with_repeat] instead
        to avoid confusion.
        )Úwith_repeat©r   rD  s     r   ÚrepeatzPermutation.repeatŠ  s   € ð ×Ñ Ó&Ð&r   c                 ó   — t        d«      ‚)z6
        Repeat the permutation `times` times
        z"with_repeat is not yet implementedr   rG  s     r   rF  zPermutation.with_repeat—  s   € ô Ð<Ó=Ð=r   )NNNN)NN)r'   N)r'   rd   )F);rG   rH   rI   rJ   r   r   rM   rŽ   rN   r   r‰   rŠ   r   r   r   r¿   rÊ   rÌ   rÎ   ÚclassmethodrÑ   r   rk   rÝ   rè   rê   ÚpropertyÚSchemarY   rô   r÷   rK   rù   Útuplerû   rý   r  r  r
  r  r  r  r   r  Úboolr  r   r.  r-  r4  rp   r:  r   r<  r>  rB  rA  rH  rF  rO   r   r   rd   rd   Í  sj  „ ñ
ð( !%Ø#Ø?CØ/3ñ àð ð $ E™?ð ð ð	 ð
 ˜˜S˜‘>ð ð ð ð ˜rŸ~™~¨sÐ2Ñ3ð ð ˜‘ð ð ˜‰}ð ð % X¨s¨e°U¨lÑ%;Ñ<ð ð Ð+Ñ,ó ðBÐ%6ó ð	¨¨c°3¨h©ð 	¸Mó 	ð¨#ð °-ó ðJØ"*¨C¨5°%¨<Ñ"8ðJà	óJðX ð:˜Uð : }ò :ó ð:ð ð .2Ø+/ñ	H*àðH*ð $ E™?ðH*ð ˜˜c 3˜h™Ñ(ð	H*ð
 
òH*ó ðH*ðT#
˜d 3¨ 8™nó #
ðJ1 $ s¨C x¡.ð 1°Tó 1ófð ð,˜Ÿ	™	ò ,ó ð,ð ð ˜Sò  ó ð ð ð(˜#ò (ó ð(ð ð!˜d 3™iò !ó ð!ð ð/�u˜S #˜X‘ò /ó ð/ð˜ó ð9˜cð 9 d¨3¡ió 9ó
:ð3 d¨3¡ið 3°Mó 3ð43 cð 3°Sð 3¸]ó 3ð<¨¨c°3¨h©ð ¸Mó ð&3 d¨3¡ið 3°Mó 3ð>@˜( 4¨¨S¨¡>Ñ2ó @ð 8=ñØðØ04ðà	�$�s˜C�x‘.Ñ	!óð6C:àðñ

ðC:ð 
óC:ðJ¨°·±ÀÐ1DÑ(Eð È-ó ð( D¨¡Ið (°#ó (ð * ð *¨ó *ð* D¨¡Ið *°#ó *ñ Ð/Ô0ð
$˜ð 
$ ò 
$ó 1ð
$ð	˜cð 	 mó 	ñ Ð/Ô0ð
%˜#ð 
% -ò 
%ó 1ð
%ð	˜sð 	 }ó 	ñ Ð1Ô2ð
'˜Cð 
' Mò 
'ó 3ð
'ð> ð >¨ô >r   rd   )-rÈ   r]   rÁ   Údeprecationr   Úpyarrowr‰   Ú_lancedbr   r   r   r   r   Úbackground_loopr	   Úutilr
   r   r   Útypingr   r   r   r   r   r   r   Úlancedb.dependenciesr   Úpdr   Únpr   r‡   r   rQ   rS   rr   rÖ   rŽ   rN   r¢   r§   r³   rd   rO   r   r   ú<module>rX     sÚ   ðó Û Û 	å "Û ç Bß $Ý !ß MÑ Mß S× SÑ SáßLÑL÷x&ñ x&ðv%˜uð %Ð);ó %÷[Dñ [D÷| ñ  ðH Ð ð %ð ¨D°°c°©Nó ð:>¨¯©ð >°b·h±hó >ðA D¨¨c¨¡Nð A°uó A÷N>ò N>r   