
    .i                     B   d Z ddlZddlZddlZddlZddlZddlmZ	 ddl
mZ ej                  j                  Z ej                  d      Z ej                  d      Z ej                  d      Z ej&                  dg d      Zej*                  d	        Z G d
 d      Zy)z
Tests for the Apache Iceberg format.

Tests in this file use a simple Iceberg catalog based on SQLite, with the same
data used for Parquet tests (``pandas/tests/io/data/parquet/simple.parquet``).
    N)read_iceberg	pyicebergzpyiceberg.catalogzpyarrow.parquetCatalognameuri	warehousec           	   #     K   d| d}d| }t        | d      r| j                  nd }t        j                  |xs dd||      }|j	                  d       t
        j                  t        j                  t              j                  d	z  d
z  dz        }|j                  d|j                        }|j                  |       |kt        j                  j                         dz  }t        |dd      5 }	|	j!                  d| d| d|        d d d        t#        j$                  t               t'        |xs d||       |j)                          y y # 1 sw Y   JxY ww)Nz
sqlite:///z/catalog.sqlitezfile://paramdefaultsql)typer   r	   nsdataparquetzsimple.parquetns.my_table)schemaz.pyiceberg.yamlwzutf-8)encodingzcatalog:
  z:
    type: sql
    uri: z
    warehouse: r   )hasattrr   pyiceberg_catalogload_catalogcreate_namespacepq
read_tablepathlibPath__file__parentcreate_tabler   appendhomeopenwrite	importlibreloadr   unlink)
requesttmp_pathr   r	   catalog_namecatalogdftableconfig_pathfs
             Z/var/www/app/trading-bot/venv/lib/python3.12/site-packages/pandas/tests/io/test_iceberg.pyr+   r+      sn     xj
0C($I$+GW$=7==4L,,!		 - G T"	X%%.:=MM
B   ryy AE	LLll''),==+sW5 	GG . 

 { 	 	*+
|0ycY
OO  	 	s   C2E$4EA	E$E!E$c                       e Zd Zd Zej
                  j                  dddgd      d        Zd Zd	 Z	d
 Z
d Zej
                  j                  dddgd      d        Zd Zd Zy)TestIcebergc                     t        j                  g dg dd      }t        dd|j                  i      }t	        j
                  ||       y )N         foor9   r9   ABr   r   catalog_propertiespd	DataFramer   r   tmassert_frame_equalselfr+   expectedresults       r0   	test_readzTestIceberg.test_readD   sH    <<*
  %w{{3
 	fh/    r+   r   pandas_testsT)indirectc                     t        j                  g dg dd      }t        d|j                        }t	        j
                  ||       y )Nr4   r8   r:   r   r*   )r@   rA   r   r   rB   rC   rD   s       r0   test_read_by_catalog_namez%TestIceberg.test_read_by_catalog_nameQ   sC    <<*
  
 	fh/rI   c                     t        j                  ddgddgd      }t        dd|j                  id      }t	        j
                  ||       y )	Nr6   r7   r9   r:   r   r   zA > 1)r>   
row_filterr?   rD   s       r0   test_read_with_row_filterz%TestIceberg.test_read_with_row_filter_   sS    <<VU^
  %w{{3

 	fh/rI   c                 2   t        j                  dg di      }t        dd|j                  idgd      }t	        j
                  ||       t        j                  t        d	      5  t        dd|j                  idgd
       d d d        y # 1 sw Y   y xY w)Nr;   r4   r   r   aF)r>   columnscase_sensitivez^Could not find column)matchT)	r@   rA   r   r   rB   rC   pytestraises
ValueErrorrD   s       r0   test_read_with_case_sensitivez)TestIceberg.test_read_with_case_sensitivem   s    <<Y

  %w{{3E 	
 	fh/]]:-EF 	$)7;;#7#		 	 	s   'BBc                     t        j                  ddgddgd      }t        dd|j                  id      }t	        j
                  ||       y )Nr5   r6   r9   r:   r   r   )r>   limitr?   rD   s       r0   test_read_with_limitz TestIceberg.test_read_with_limit   sS    <<VU^
  %w{{3

 	fh/rI   c                     t        j                  g dg dd      }|j                  dd|j                  i|j                         t        dd|j                  i      }t        j                  ||       y )Nr4   r8   r:   ns.new_tabler   )r>   locationr=   r@   rA   
to_icebergr   r	   r   rB   rC   rE   r+   r,   rG   s       r0   
test_writezTestIceberg.test_write   ss    \\*
 	 %w{{3&& 	 	

  %w{{3
 	fb)rI   c                     t        j                  g dg dd      }|j                  d|j                         t	        d|j                        }t        j                  ||       y )Nr4   r8   r:   r_   rM   )r@   rA   rb   r   r   rB   rC   rc   s       r0   test_write_by_catalog_namez&TestIceberg.test_write_by_catalog_name   s`    \\*
 	  	 	
  
 	fb)rI   c                 T   t        dd|j                  i      }t        j                  g dg dd      }t        j                  ||gd      }|j                  dd|j                  i|j                  d	       t        dd|j                  i      }t        j                  ||       y )
Nr   r   r=   r4   r8   r:   T)ignore_indexr>   r`   r!   )	r   r   r@   rA   concatrb   r	   rB   rC   )rE   r+   originalnewrF   rG   s         r0   *test_write_existing_table_with_append_truez6TestIceberg.test_write_existing_table_with_append_true   s     %w{{3
 ll*
 99h_4@ %w{{3&&	 	 	
  %w{{3
 	fh/rI   c                     t        j                  g dg dd      }|j                  dd|j                  i|j                  d       t        dd|j                  i      }t        j                  ||       y )	Nr4   r8   r:   r   r   Fri   r=   ra   rc   s       r0   +test_write_existing_table_with_append_falsez7TestIceberg.test_write_existing_table_with_append_false   sv    \\*
 	 %w{{3&&	 	 	
  %w{{3
 	fb)rI   N)__name__
__module____qualname__rH   rW   markparametrizerN   rQ   rZ   r]   rd   rf   rm   ro    rI   r0   r2   r2   C   s    0 [[YN(CdS0 T00,0*$ [[YN(CdS* T*"00*rI   r2   )__doc__collectionsr%   r   rW   pandasr@   pandas._testing_testingrB   pandas.io.icebergr   rs   
single_cpu
pytestmarkimportorskipr   r   r   
namedtupler   fixturer+   r2   ru   rI   r0   <module>r      s          *[[##
F,	'F''(;< V*+
 +
 
 ,H
I # #L[* [*rI   