Ë
    kQêj0  ã                   óê  — d dl mZ d dlmZmZmZmZ d dlZd dl	Z
d dlZ	ddlmZmZ eee   de
j"                  ee
j$                     f   Zeeej*                  e
j,                  e
j.                  f   Zeeef   ZdZ G d„ d	e«      Zd
edefd„Zdee
j$                     de
j<                  dee
j$                     fd„Z	 ddedee
j<                     de
j@                  fd„Z!de
j<                  fd„Z"defd„Z#y)é    )ÚPath)ÚIterableÚListÚOptionalÚUnionNé   )Ú_check_for_pandasÚpandaszpd.DataFrameÚvectorc                   ó(   — e Zd ZdZdefd„Zdefd„Zy)Ú
CredentialzCredential fieldÚreturnc                  ó   — y©Nz********© ©Úselfs    úS/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/lancedb/common.pyÚ__repr__zCredential.__repr__   ó   € Øó    c                  ó   — yr   r   r   s    r   Ú__str__zCredential.__str__   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r   r   r      s   „ Ùð˜#ó ð˜ô r   r   Úurir   c                 ó   — t        | «      S ©N)r   )r   s    r   Úsanitize_urir"      s   € Üˆs‹8€Or   Ú
input_iterÚschemac              #   óœ  K  — | D ]‡  }t        |t        j                  «      st        dt	        |«      › �«      ‚|j
                  |k7  rA	 t        j                  j                  |g«      j                  |«      j                  «       d   }|–— Œ‰ y# t        j                  j                  $ r t        d|› d|j
                  › �«      ‚w xY w­w)a¬  
    Wrapper around an iterator of record batches. If the batches don't match the
    schema, try to cast them to the schema. If that fails, raise an error.

    This is helpful for users who might have written the iterator with default
    data types in PyArrow, but specified more specific types in the schema. For
    example, PyArrow defaults to float64 for floating point types, but Lance
    uses float32 for vectors.
    zExpected RecordBatch, got r   zjInput RecordBatch iterator yielded a batch with schema that does not match the expected schema.
Expected:
z
Got:
N)Ú
isinstanceÚpaÚRecordBatchÚ	TypeErrorÚtyper$   ÚTableÚfrom_batchesÚcastÚ
to_batchesÚlibÚArrowInvalidÚ
ValueError)r#   r$   Úbatchs      r   Ú_casting_recordbatch_iterr3   "   sÊ   è ø€ ð ò ˆÜ˜%¤§¡Ô0ÜÐ8¼¸e»¸ÐFÓGÐGØ�<‰<˜6Ò!ðäŸ™×-Ñ-¨u¨gÓ6×;Ñ;¸FÓC×NÑNÓPÐQRÑS�ð ‹ñøô —6‘6×&Ñ&ò Ü ðGØGMÀhð OØ"Ÿ\™\˜Nð,óð ðüs   ‚ACÁ	A BÂ	CÂ9C	Ã	CÚdatac                 ó\  — t        | «      rIt        | t        j                  «      r/t        j
                  j                  | |¬«      j                  «       S t        | t        j
                  «      r| j                  «       S t        | t        j                  «      r.t        j
                  j                  | g«      j                  «       S t        | t        j                  j                  «      r7t        j                  j                  j                  | «      j                  «       S t        | t        j                  j                  «      r| j                  «       S t        | t        j                  «      r| S t        | «      j                   j#                  d«      r7| j$                  j&                  dk(  r| j)                  «       j                  «       S t        | t*        «      r9|�,t-        | |«      } t        j                  j                  || «      S t/        d«      ‚t1        dt        | «      › d�«      ‚)z7Convert various types of input into a RecordBatchReader©r$   ÚpolarsÚ	DataFramez>Must provide schema to write dataset from RecordBatch iterablezUnknown data type z§. Supported types: list of dicts, pandas DataFrame, polars DataFrame, pyarrow Table/RecordBatch, or Pydantic models. See https://docs.lancedb.com/tables/ for examples.)r	   r&   Úpdr8   r'   r+   Úfrom_pandasÚ	to_readerr(   r,   ÚdatasetÚDatasetÚScannerÚfrom_datasetÚRecordBatchReaderr*   r   Ú
startswithÚ	__class__r   Úto_arrowr   r3   r1   r)   )r4   r$   s     r   Údata_to_readerrD   >   sŸ  € ô ˜Ô¤:¨d´B·L±LÔ#AÜ�x‰x×#Ñ# D°Ð#Ó8×BÑBÓDÐDÜ	�Dœ"Ÿ(™(Ô	#Ø�~‰~ÓÐÜ	�Dœ"Ÿ.™.Ô	)Ü�x‰x×$Ñ$ d VÓ,×6Ñ6Ó8Ð8ô 
�Dœ"Ÿ*™*×,Ñ,Ô	-Ü�z‰z×!Ñ!×.Ñ.¨tÓ4×>Ñ>Ó@Ð@Ü	�Dœ"Ÿ*™*×,Ñ,Ô	-Ø�~‰~ÓÐÜ	�Dœ"×.Ñ.Ô	/ØˆäˆT‹
×Ñ×(Ñ(¨Ô2Ø�N‰N×#Ñ# {Ò2à�}‰}‹×(Ñ(Ó*Ð*ä	�Dœ(Ô	#ØÐÜ,¨T°6Ó:ˆDÜ×'Ñ'×4Ñ4°V¸TÓBÐBäØPóð ô Ø ¤ d£ ð -Að Aó
ð 	
r   c                 óH   — | j                   �t        | j                   «       yy)z.
    Make sure the metadata is valid utf8
    N)ÚmetadataÚ_validate_metadatar6   s    r   Úvalidate_schemarH   g   s   € ð ‡�Ð"Ü˜6Ÿ?™?Õ+ð #r   rF   c                 óê   — | j                  «       D ]D  \  }}t        |t        «      r	 |j                  d«       Œ)t        |t        «      sŒ:t        |«       ŒF y# t        $ r t        d|› d�«      ‚w xY w)zo
    Make sure the metadata values are valid utf8 (can be nested)

    Raises ValueError if not valid utf8
    Úutf8zMetadata key zG is not valid utf8. Consider base64 encode for generic binary metadata.N)Úitemsr&   ÚbytesÚdecodeÚUnicodeDecodeErrorr1   ÚdictrG   )rF   ÚkÚvs      r   rG   rG   o   s~   € ð —‘Ó ò 
"‰ˆˆ1Ü�aœÔðØ—‘˜Õ ô ˜œ4Õ Ü˜qÕ!ñ
"øô &ò Ü Ø# A 3ð 'Jð Jóð ðús   ¨AÁA2r!   )$Úpathlibr   Útypingr   r   r   r   ÚnumpyÚnpÚpyarrowr'   Úpyarrow.datasetÚdependenciesr	   r
   r9   rO   r+   r(   ÚDATAÚlistÚndarrayÚArrayÚChunkedArrayÚVECr   ÚURIÚVECTOR_COLUMN_NAMEr   r"   ÚSchemar3   r@   rD   rH   rG   r   r   r   ú<module>rb      s  ðõ
 ß 2Ó 2ã Û Û ç 9àˆT�$‰Z˜¨¯©°8¸B¿N¹NÑ3KÐKÑL€ØˆD�"—*‘*˜bŸh™h¨¯©Ð7Ñ8€ØˆC�ˆIÑ€ØÐ ô�ô ð�cð ˜có ðØ˜Ÿ™Ñ(ðØ24·)±)ðàˆb�n‰nÑóð: /3ñ&
Ø
ð&
Ø  §¡Ñ+ð&
à×Ñó&
ðR,˜BŸI™Ió ,ð" ô "r   