
    [j                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SK
rS SKrS SKJrJrJrJrJrJrJr  S SKJrJrJr  S SKJrJrJrJr  S SKJrJrJ r J!r!J"r"  S SK#r# S SK$r%S SK&r&S S	K'J(r(  S S
K)J*r*J+r+  \"r-\#R\                  " S5        \#R\                  " S5      r/S r0\#Rb                  Re                  SS/ S/SS//5      S 5       r3S r4\#Rb                  Re                  SSS/5      S 5       r5S r6\#Rb                  Re                  S/ SQ5      S 5       r7S r8\#Rb                  Re                  S/ SQ5      S 5       r9S  r:S! r;S" r<S# r=S$ r>S% r?S& r@S' rAS( rBS) rCS* rD\#Rb                  Re                  S+S,S/ S-Q4S.S/// 4S0/ S1QSS2/4S3SS/SS/4/5      S4 5       rE\#Rb                  R                  \S5:  S6S79\#Rb                  Re                  S8S9S:/5      S; 5       5       rG\#Rb                  Re                  S<S9S:/5      S= 5       rH\#Rb                  R                  \S5:  S>S79S? 5       rIS@ rJSA rK\#Rb                  R                  \SB:  SCS79\#Rb                  Re                  SD\5      SE 5       5       rL\#Rb                  R                  \SB:  SCS79\#Rb                  Re                  SD\5      SF 5       5       rM\R                  " \OR                  SG5      /SH-  \QSI9rR\!SJ 5       rS\#Rb                  R                  SK5      \!SL 5       5       rU\#Rb                  R                  SK5      \!SM 5       5       rV\!SN 5       rW\!\#Rb                  Re                  SOSP\#R                  " SQ\#Rb                  R                  \SR:  SSS79ST9/5      SU 5       5       rY\#Rb                  Re                  SV\ R                  " 5        V s1 s H  n U SW;  d  M  U iM     sn 5      \!SX 5       5       r[\!SY 5       r\\#Rb                  Re                  SD\ 5      \!SZ 5       5       r]\#Rb                  Re                  S[S\/5      \!S] 5       5       r^\!S^ 5       r_\!\#Rb                  Re                  S2S_S`/5      Sa 5       5       r`\!Sb 5       ra\!Sc 5       rb\!Sd 5       rc\!Se 5       rd\!Sf 5       re\!Sg 5       rf\#Rb                  R                  \" \/R                  5      \" Sh5      :  SiS79\!Sj 5       5       rh\#Rb                  R                  Sk5      \!Sl 5       5       ri\!Sm 5       rj\!\#Rb                  R                  Sn5      \#Rb                  Re                  SVSoSp/5      Sq 5       5       5       rk\!Sr 5       rl\!\#Rb                  Re                  SVSsSt/5      Su 5       5       rm\!\#Rb                  Re                  SVSoSp/5      Sv 5       5       rn\!Sw 5       ro\!Sx 5       rp\!Sy 5       rq\!Sz 5       rr\!\#Rb                  Re                  SDS{S|/5      S} 5       5       rsg! \, a     GNtf = fs  sn f )~    N)BytesIO)Version)ZipFile)__gdal_version__get_gdal_config_optionlist_layersread_dataframe	read_infoset_gdal_config_optionsvsi_listtree)DataLayerErrorDataSourceError
FieldError)
open_arrow
read_arrowwritewrite_arrow)ALL_EXTS
DRIVER_EXTDRIVERSrequires_arrow_write_apirequires_pyarrow_api)assert_geodataframe_equal)assert_frame_equalassert_index_equal	geopandaspyarrowc                     [        U SS9n[        U SS9nU R                  R                  S5      (       a  SnOSn[        XUS9  g )NT	use_arrowF.geojson)check_less_precise)r	   suffix
startswithr   )naturalearth_lowres_all_extresultexpectedr"   s       [/var/www/html/Sattelite-Image/venv/lib/python3.13/site-packages/pyogrio/tests/test_arrow.pytest_read_arrowr)   0   sJ    74HF9UKH"))44Z@@!"fCUV    columns	continentiso_a3pop_estc                 x    [        XS9u  p#US   c   eUc  / SQnOUn[        US   5      [        U5      :X  d   eg )Nr+   fieldsr.   r,   namer-   
gdp_md_est)r   sorted)naturalearth_lowresr+   meta_tableexpected_fieldss        r(   test_read_arrow_columnsr:   ;   sJ    1CLD>%%%R!$x.!VO%<<<<r*   c                     [         R                  " [        SS9   [        U S-  5        SSS5        g! , (       d  f       g= f)zFReading a multi-layer file without specifying a layer gives a warning.zMore than one layer found matchzsample.osm.pbfN)pytestwarnsUserWarningr   )data_dirs    r(   )test_read_arrow_unspecified_layer_warningrB   F   s,    	k)E	F8../ 
G	F	Fs	   2
A zskip_features, expected)
      )   r   c                 >    [        XS9S   n[        U5      U:X  d   eg )Nskip_features   r   len)r6   rH   r'   tables       r(   test_read_arrow_skip_featuresrM   L   s$    *HKEu:!!!r*   c                 ~    [         R                  " [        SS9   [        U SS9  S S S 5        g ! , (       d  f       g = f)Nz'skip_features' must be >= 0r<   rG   r>   raises
ValueErrorr   r6   s    r(   &test_read_arrow_negative_skip_featuresrT   R   s)    	z)G	H&b9 
I	H	H   .
<zmax_features, expected))r   r   )rC   rC   )rE      )順 rV   c                 >    [        XS9S   n[        U5      U:X  d   eg )Nmax_featuresrI   rJ   )r6   rZ   r'   rL   s       r(   test_read_arrow_max_featuresr[   W   s&     *FqIEu:!!!r*   c                 ~    [         R                  " [        SS9   [        U SS9  S S S 5        g ! , (       d  f       g = f)Nz'max_features' must be >= 0r<   rO   rY   rP   rS   s    r(   %test_read_arrow_negative_max_featuresr]   _   s)    	z)F	G&R8 
H	G	GrU   z%skip_features, max_features, expected))r   r   r   )rC   r   r   )rE   r   r   )rI   rE      )r^   rC   rI   )d   r_   M   )r_   rW   r`   c                 @    [        XUS9S   n[        U5      U:X  d   eg )N)rH   rZ   rI   rJ   )r6   rH   rZ   r'   rL   s        r(   *test_read_arrow_skip_features_max_featuresrb   d   s/     |	E u:!!!r*   c                     SSS.n[        U 4SS0UD6n[        UR                  [        R                  " SS5      5        [        U 4SS0UD6n[        UR                  [        R
                  " SS/S	S
95        g )NTzfid >= 2 AND fid <= 3)r    wherefid_as_indexFr         fid)r3   )r	   r   indexpd
RangeIndexIndex)r%   kwargsdfs      r(   test_read_df_arrow_fidro   y   sm    *ABF	3	R%	R6	RBrxxq!!45	3	Q$	Q&	QBrxx1a&u!=>r*   c                 `    [        U SS/S9nUR                  R                  5       SS/:X  d   eg )NTr,   )r    r+   geometry)r	   r+   tolist)r6   r&   s     r(   test_read_df_arrow_columnsrs      s3    /4+WF>>  "{J&????r*   c                     [        U SSS9n[        U5      [        R                  L d   e[        U SS9R	                  S/S9n[        X5        g )NTF)r    read_geometryr   rq   r0   )r	   typerj   	DataFramedropr   )r6   r&   r'   s      r(   "test_read_df_arrow_ignore_geometryry      sT    /4uUF<2<<'''1TBGG H H v(r*   c                     SS0n[        U SSUS9nUR                  R                  R                  S:X  d   e[        R
                  " UR                  R                  R                  / SQ5      (       d   eg )Nstrings_to_categoricalTF)ru   r    arrow_to_pandas_kwargscategory)abc)r	   coldtyper3   nparray_equalvalues
categories)no_geometry_filer|   rn   s      r(   #test_read_df_arrow_to_pandas_kwargsr      sf    6=	5	
B 66<<
***>>"&&--22ODDDDr*   c                     [        U 5      u  p[        U[        5      (       d   e[        U[        R                  5      (       d   eg )N)r   
isinstancedictr   Table)r6   r7   rL   s      r(   test_read_arrow_rawr      s9    01KDdD!!!!eW]]++++r*   c                 h    [        U S   5      S   n[        U5      S:X  d   e[        SSS9/ :X  d   eg )NrI   rV   /vsimem/	pyogrio_*pattern)r   rK   r   )naturalearth_lowres_vsirL   s     r(   test_read_arrow_vsir      s@    .q1215Eu: 
K8B>>>r*   c                     [        U 5      u  pUS   R                  S:X  d   e[        U5      S:X  d   e[        SSS9/ :X  d   eg Nr1   )   rg   r   r   r   r   shaperK   r   )geojson_bytesr7   rL   s      r(   test_read_arrow_bytesr      sM    ]+KD>4'''u:?? 
K8B>>>r*   c                     [        U 5      u  pUS   R                  S:X  d   e[        U5      S:X  d   e[        SSS9/ :X  d   eg )Nr1   )r   rI   r   r   r   r   )nonseekable_bytesr7   rL   s      r(   !test_read_arrow_nonseekable_bytesr      sN    ./KD>4'''u:?? 
K8B>>>r*   c                     [        U 5      u  pUS   R                  S:X  d   e[        U5      S:X  d   e[        SSS9/ :X  d   eg r   r   )geojson_fileliker7   rL   s      r(   test_read_arrow_fileliker      sN    -.KD>4'''u:?? 
K8B>>>r*   c                     [        U SS9 u  p[        U[        5      (       d   e[        U[        R                  5      (       d   e[        UR                  5       [        R                  5      (       d   e S S S 5        g ! , (       d  f       g = f)NT)use_pyarrow)r   r   r   r   RecordBatchReaderread_allr   )r6   r7   readers      r(   test_open_arrow_pyarrowr      sg    	'T	:nt$%%%%&'";";<<<<&//+W]];;;; 
;	:	:s   A*A??
Bc                    [        U 5      u  p[        R                  " [        U5      S-  5      n[	        XSS9 u  nn[        U[        5      (       d   e[        U[        R                  5      (       d   eSn/ nU H  nUR                  U5        US-  nM     US:X  d   S5       e[        US   5      U:X  d   S5       e S S S 5        g ! , (       d  f       g = f)Nrf   T)
batch_sizer   r   rI   z4Should be two batches given the batch_size parameterz'First table should match the batch size)
r   mathceilrK   r   r   r   r   r   append)r6   _rL   r   r7   r   counttabless           r(   test_open_arrow_batch_sizer      s    -.HA3u:>*J	'D	Q V$%%%%&'";";<<<<EMM% QJE  zQQQz6!9~+V-VV+ 
R	Q	Qs   BC		
Czdescr, columns, exp_columnsallr2   case_sensitiveNAMErepeats_dropped)r,   r,   r3   r3   keep_original_orderc                    [        XS9 u  pE[        U[        5      (       d   e[        U[        R                  R
                  5      (       d   e[        R                  " U5      nS S S 5        [        R                  " WS   U5      (       d
   SU 35       eUS/-   nWR                  U:X  d
   SU 35       eg ! , (       d  f       NX= f)Nr0   r1   zFailed for wkb_geometry)r   r   r   pyogrio_io_ArrowStreamr   rL   r   r   column_names)r6   descrr+   exp_columnsr7   r   r&   exp_columns_with_geoms           r(   test_open_arrow_columnsr      s     
'	9^d$%%%%&'++":":;;;;v&	 
: >>$x.+66M+eW8MM6 (>*::"77N;ug9NN7 
:	9s   AB77
C)rg      r   z;skip_features supported by Arrow stream API for GDAL>=3.8.0reasonrH   rC   rE   c                     [         R                  " [        SS9   [        XS9 u  nn SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zOskip_features are not supported for the Arrow stream interface for
GDAL < 3.8.0zDspecifying 'skip_features' is not supported for Arrow for GDAL<3.8.0r<   rG   Nr>   rQ   rR   r   )r6   rH   r7   r   s       r(   )test_open_arrow_skip_features_unsupportedr      sU     
T
 +I N
	 J	
 
 JI	
 
   
A:A
A	A
ArZ   c                     [         R                  " [        SS9   [        XS9 u  nn SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)z=max_features are not supported for the Arrow stream interfacez4specifying 'max_features' is not supported for Arrowr<   rY   Nr   )r6   rZ   r7   r   s       r(   (test_open_arrow_max_features_unsupportedr     sU     
D
 +G L
	 H	
 
 HG	
 
r   z.returns geoarrow metadata only for GDAL>=3.8.0c                    [        U 5      u  pUR                  R                  S5      nUR                  S   S:X  d   e[        R
                  " UR                  S   5      nUS   S   S   S:X  d   eUS   S   S	   S
:X  d   eg )Nr   s   ARROW:extension:names   geoarrow.wkbs   ARROW:extension:metadatacrsid	authorityEPSGcodei  )r   schemafieldmetadatajsonloads)r6   _metarL   r   parsed_metas        r(   !test_read_arrow_geoarrow_metadatar     s    
 12LELL~.E>>12oEEE**U^^,GHIKud#K0F:::ud#F+t333r*   c                 v   [         R                  " SSS9  [        U 5       u  p[        U[        5      (       d   e[        U[
        R                  R                  5      (       d   e[        R                  " U5      nS S S 5        [        U 5      u  pEWR                  U5      (       d   eg ! , (       d  f       N4= fNr   14)
minversion)r>   importorskipr   r   r   r   r   r   r   rL   r   equals)r6   r7   r   r&   r   r'   s         r(    test_open_arrow_capsule_protocolr   ,  s    
	d3	'	(NT$%%%%&'++":":;;;;v&	 
) 01KA=="""" 
)	(s   AB**
B8c                    [         R                  " SSS9nS [        R                  S'    [	        U 5       u  p#[        U[        5      (       d   e[        U[        R                  R                  5      (       d   eUR                  " U5      nS S S 5        U[        R                  S'   [        U 5      u  pVWR                  U5      (       d   eg ! , (       d  f       NG= f! U[        R                  S'   f = fr   )r>   r   sysmodulesr   r   r   r   r   r   rL   r   r   )r6   r   r7   r   r&   r   r'   s          r(   0test_open_arrow_capsule_protocol_without_pyarrowr   9  s    !!)=G "CKK	)+,dD))))fgkk&>&>????]]6*F -
 ")I01KA=="""" -,
 ")Is#   C ACC 
CC C3)rg   r   rg   z+Arrow bool value bug fixed in GDAL >= 3.8.3extc           	         U SU 3-  n[         R                  " [        R                  S5      /S-  [        S9n[         R                  " / SQ5      nU/nS/n0 nUS:X  a  SUS	'   [        UUUU4S
SS.UD6  [        X#XVS
SS9  [        U5      S   n[         R                  " US   R                  5       U5      (       d   eg )Ntest*010100000000000000000000000000000000000000r   r   TFTFTbool_col.fgbFspatial_indexPoint	EPSG:4326geometry_typer   rI   )	r   arraybytesfromhexobjectr   r   r   to_numpy)	tmp_pathr   filenamerq   r   
field_datar1   rm   rL   s	            r(   test_arrow_bool_roundtripr   J  s    
 D,&H xx	C	DEIQWH xx89HJ\FF
f}"'		
   
Jg; x #E>>%
+446AAAAr*   c           	         U SU 3-  n[         R                  " [        R                  S5      /S-  [        S9n[         R                  " / SQ5      nU/nS/n[        X#XVSSS	9  US
;   aL  [        R                  " [        SS9   [        U5          S S S 5        S S S 5        [        U/ S9    S S S 5        g [        U5          S S S 5        g ! , (       d  f       NA= f! , (       d  f       NJ= f! , (       d  f       g = f! , (       d  f       g = f)Nr   r   r   r   r   r   r   r   r   >   r   .gpkgzLGDAL < 3.8.3 does not correctly read boolean data values using the Arrow APIr<   r0   )
r   r   r   r   r   r   r>   rQ   RuntimeErrorr   )r   r   r   rq   r   r   r1   s          r(   test_arrow_bool_exceptionr   q  s    
 D,&H xx	C	DEIQWH xx89HJ\F	Jg; ]]

 H% &
 "- .- ! "! &%
 
 .- "!s<   CCC*C- C>
C	C
C*-
C;>
Dr   rg   r   c           	          [        U5      u  p#U S-  n[        UUUS   US   US   US   =(       d    SS9  UR                  5       (       d   eS H)  nUR                  U5      R                  5       (       a  M)   e   g )	Ntest.shpr   encodingr   geometry_namer   )r   r   r   r   )z.dbfz.prj)r   r   existswith_suffix)r   r6   r7   rL   r   r   s         r(   test_write_shpr    s    01KD*$HKj!?+?+=~ ??##C(//1111  r*   z-ignore:A geometry of type POLYGON is insertedc           	          [        U5      u  p#U S-  n[        UUSUS   SUS   =(       d    SS9  UR                  5       (       d   eg )N	test.gpkgGPKGr   MultiPolygonr   r   driverr   r   r   )r   r   r   r   r6   r7   rL   r   s        r(   test_write_gpkgr
    sX     01KD+%HK$?+=~ ??r*   c           
         [        U5      u  p#SUS'   U S-  n[        UUSSUS   SUS   =(       d    SS	9  UR                  5       (       d   e[        R                  " [        U5      SS//5      (       d   e[        UUSS
US   SUS   =(       d    SS	9  [        R                  " [        U5      SS/S
S//5      (       d   eg )Nr  r   r  r  firstr   r   r   r  layerr   r   r   second)r   r   r   r   r   r   r	  s        r(   test_write_gpkg_multiple_layersr    s     01KD*D+%HK$?+=~ ??>>+h/7N2K1LMMMMK$?+=~ >>H. 9Hn;UV   r*   c           	         [        U5      u  p#U S-  n[        UUSUS   US   US   =(       d    SS9  UR                  5       (       d   e[        R                  " [        U5      R                  5       5      nUS   S	:X  d   eUS
   S:X  d   eSU;   d   e[        US   5      [        U5      :X  d   e[        [        US   5      R                  US   S   S   R                  5       5      5      (       a   eg )N	test.jsonGeoJSONr   r   r   r   r  rv   FeatureCollectionr3   r   featuresr1   r   
properties)r   r   r   r   r   openreadrK   set
differencekeys)r   r6   r7   rL   r   datas         r(   test_write_geojsonr    s   01KD+%HK?+?+=~ ??::d8n))+,D<....<6!!!D==tJ CJ...DN&&tJ'7':<'H'M'M'OP    r*   write_int64FTrg   	   r   z<OpenFileGDB write support for int64 values for GDAL >= 3.9.0)marksc           
         [         R                  " / SQSS9[         R                  " / SQSS9[         R                  " / SQSS9[         R                  " / SQSS9[         R                  " / SQSS9[         R                  " / SQS	S9/n[        R                  S
[        0U Vs0 s H  o3R
                  R                  U_M     snE5      nU S-  nSS0nU(       a  SS0O0 nU(       d
  [        S:  a  [        R                  " 5       nO[        R                  " [        SS9nU   [        UU4SSS
S.UDUD6  S S S 5        [        U5      u  pU(       d  US   R                  S	5      US'   US   R                  S5      US'   U	S   US   :X  d   e[         R                   " XIS      [        5      (       d   e[#        [%        U5      5       Hj  n
XDR&                  R(                  U
      R+                  5       nUR
                  X*   R
                  :X  d   e[         R                   " XU
   5      (       a  Mj   e   g s  snf ! , (       d  f       GN= f)N)TFTboolr   rI   rf   rg   int16int32int64float32float64rq   ztest.gdbr   r   TARGET_ARCGIS_VERSIONARCGIS_PRO_3_2_OR_LATERr  z&Integer64 will be written as a Float64r<   OpenFileGDBr   )r  r   r   rg   r   r   )r   r   parL   pointsr   r3   r   
contextlibnullcontextr>   r?   RuntimeWarningr   r   astyper   rangerK   r   namesr   )r   r  expected_field_datar   rL   r   expected_metawrite_paramsctxr7   ir   s               r(   test_write_openfilegdbr:    s5     	$F3
'*
'*
'*
),
), HH	
4GH4G5{{&4GH	
E *$HK(M AL	 ";<QS  &2$$&ll"J
 
	
 !!$	
 	
 	
 
 X&KD!4Q!7!>!>y!IA 13::7C;-.... >>%_ 56????3*+,||))!,-668||25;;;;;~~f!&<==== -[ I, 
s   ! H7
!H<<
Ir  )ESRI Shapefiler  r  c           	          [        US/SS9u  p4SUS'   U S[        U    3-  n[        UUUUS   US   US   =(       d    S	S
9  UR                  5       (       d   eg)zATest drivers known to work that are not specifically tested abover-   rI   )r+   rZ   r  r   r   r   r   r   r  N)r   r   r   r   )r   r6   r  r7   rL   r   s         r(   test_write_supportedr=  O  s}     08*STUKD
 +DDF!3 455HK?+?+=~ ??r*   c           
          [        U5      u  p#[        R                  " [        SS9   [	        UU S-  SUS   US   US   =(       d    SS	9  S S S 5        g ! , (       d  f       g = f)
Nz$does not support write functionalityr<   r  ESRIJSONr   r   r   r   r  )r   r>   rQ   r   r   r   r6   r7   rL   s       r(   test_write_unsupportedrA  m  s]    01KD	.T	U{"U//A>	
 
V	U	U   $A
A"c           	         UR                  S5      (       a6  U R                  R                  [        R                  R                  SS95        US:X  a  [        R                  " S5        [        U5      u  pESUS'   USU 3-  n[        UUUS	   US   US
   =(       d    SS9  UR                  5       (       d   e[        U5      S   S:X  d   e[        UUSUS	   US   US
   =(       d    SS9  [        U5      S   S:X  d   eg )Nr!   z.Bugs with append when writing Arrow to GeoJSONr   z	.gpkg.zipz%Append is not supported for .gpkg.zipUnknownr   r   r   r   r   r   r   r   r  rV   T)r   r   r   r   ib  )r$   node
add_markerr>   markxfailskipr   r   r   r
   )requestr   r6   r   r7   rL   r   s          r(   test_write_appendrL  |  s    ~~j!! 	KK%UV	
 k;<01KD &DD,&HK?+?+=~ ??Xz*c111 K?+?+=~ Xz*c111r*   z
driver,ext)GMLz.gmlc                 f   [        U5      u  pEU S-  n[        UUSUS   US   US   =(       d    SS9  UR                  5       (       d   e[        USS	9S
   S:X  d   e[        R
                  " [        5         [        UUSSUS   US   US   =(       d    SS9  S S S 5        g ! , (       d  f       g = f)Nztest.gmlrM  r   r   r   r   r  T)force_feature_countr  rV   )r  r   r   r   r   )r   r   r   r
   r>   rQ   r   )r   r6   r  r   r7   rL   r   s          r(   test_write_append_unsupportedrP    s     01KD *$HK?+?+=~ ??X48DKKK		'U//A>	
 
(	'	's   7"B""
B0c           	          [        U 5      u  pSn[        SSSS.5        [        R                  " [        SS9   [        UUUS   US   US	   =(       d    S
S9  S S S 5        g ! , (       d  f       g = f)Nz%s3://non-existing-bucket/test.geojsoninvalidT)AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_NO_SIGN_REQUESTz#Failed to write features to datasetr<   r   r   r   r   rE  )r   r   r>   rQ   r   r   )r6   r7   rL   r   s       r(   test_write_gdalclose_errorrV    st    01KD6H !*%.#'	
 
.S	TU//A>	
 
U	T	Ts    A!!
A/zgeoarrow.wkbzogc.wkbc                 x   [        U5      u  p4UR                  R                  S5      nUR                  R                  U5      R	                  SU05      nUR                  UR                  R                  XV5      5      nU S-  n[        UUUS   US   S9  [        U5      u  pU
R                  U5      (       d   eg )Nr   ARROW:extension:nametest_geoarrow.shpr   r   r   r   )	r   r   get_field_indexr   with_metadatacastr  r   r   )r   r6   r3   r7   rL   idx	new_field	new_tabler   r   table_roundtrippeds              r(   "test_write_geometry_extension_typerb    s    
 01KD ,,
&
&~
6C""3'557Mt6TUI

5<<++C;<I--HK?+	 'x0A$$U++++r*   c                    [        U5      u  p#UR                  R                  S5      nUR                  R                  U5      R	                  SS05      nUR                  UR                  R                  XE5      5      n[        R                  " [        SS9   [        UU S-  US   US   S	9  S S S 5        g ! , (       d  f       g = f)
Nr   rX  zgeoarrow.pointzEWriting a geometry column of type geoarrow.point is not yet supportedr<   rY  r   r   rZ  )r   r   r[  r   r\  r]  r  r>   rQ   NotImplementedErrorr   )r   r6   r7   rL   r^  r_  r`  s          r(   test_write_unsupported_geoarrowre    s    01KD ,,
&
&~
6C""3'55	!12I 

5<<++C;<I	U
 	**U/		
	
 
 
s   B77
Cc                     [        U5      u  p#UR                  S5      nU S-  n[        X45        UR                  5       (       d   e[        U5      u  pVUS   b   eUS   b   eUR	                  U5      (       d   eg )Nr   r  r   r   )r   drop_columnsr   r   r   )r   r6   r   rL   r   r7   r&   s          r(   test_write_no_geomrh    s    -.HA~.E +%H ??h'LD; (((<<r*   c                 `   [        U5      u  p#[        R                  " [        SS9   [	        UU S-  US   US   =(       d    SS9  S S S 5        U S-  n[	        UUUS   S	US   =(       d    SS
9  UR                  5       (       d   e[        U5      u  pVUS   S	:X  d   eg ! , (       d  f       N_= f)Nz#'geometry_type' keyword is requiredr<   r   r   r   r   )r   r   r  rD  rE  r   )r   r>   rQ   rR   r   r   )r   r6   r7   rL   r   meta_writtenr   s          r(   test_write_geometry_typerk    s    01KD 
z)N	Oz!U/A>		
 
P +%HK?+=~ ?? *OL(I555' 
P	Os   B
B-c           
          [        U5      u  p#[        R                  " [        SS9   [	        UU S-  US   US   US   =(       d    SSS	9  S S S 5        g ! , (       d  f       g = f)
Nz.The 'promote_to_multi' option is not supportedr<   r   r   r   r   r   T)r   r   r   promote_to_multir   r>   rQ   rR   r   r@  s       r(   !test_write_raise_promote_to_multiro  6  se    01KD	J
 	z!U//A>!	

 
 
rB  c                    [        U5      u  p#U S-  n[        R                  " [        SS9   [	        UUUS   US   =(       d    SS9  S S S 5        [        U5      u  pVUR                  U5      (       d   eUS   b   eg ! , (       d  f       N<= f)	Nr   z'crs' was not providedr<   r   r   r   )r   r   r   )r   r>   r?   r@   r   r   )r   r6   r7   rL   r   meta_resultr&   s          r(   test_write_no_crsrr  G  s    01KD*$H	k)A	B//A>		
 
C %X.K<<u%%% 
C	Bs   A>>
Bc           	          [         R                  " / SQ5      n[        R                  " [        SS9   [        UU S-  SSSS9  S S S 5        g ! , (       d  f       g = f)	Nr$  z1The provided data is not recognized as Arrow datar<   ztest_no_arrow_data.shpr   r   rq   rE  )r   r   r>   rQ   rR   r   r   r  s     r(   test_write_non_arrow_dataru  Y  sQ    88ID	M
 	//!$	

 
 
s   A
Az16.0.0.dev0zCPyCapsule protocol only added to pyarrow.ChunkedArray in pyarrow 16c           	          [         R                  / SQ/ SQ/5      n[        R                  " [        SS9   [        UU S-  SSSS	9  S S S 5        g ! , (       d  f       g = f)
Nr$  )   r      z9.*should be called on a schema that is a struct of fieldsr<   ztest_no_arrow_tabular_data.shpr   r   rq   rE  )r-  chunked_arrayr>   rQ   r   r   rt  s     r(   !test_write_non_arrow_tabular_datarz  h  sZ     Y	23D	I
 	77!$	
	
 
 
s   A
Az,ignore:.*not handled natively:RuntimeWarningc           	         [         R                  R                  [         R                  [         R	                  5       [         R                  5       5      S[         R                  / SQ5      R                  5       [         R                  SS/5      S9n[         R                  [        US.5      n[        R                  " [        SS9   [        UU S	-  S
SSS9  S S S 5        g ! , (       d  f       g = f)Nrg   )r   rI   rf   r~   r   )lengthbuffers
dictionaryrq   r   z.*invalid dictionary indexr<   ztest_unsupported_list_type.fgbr   r   rq   rE  )r-  DictionaryArrayfrom_buffersr~  r'  stringr   r}  rL   r.  r>   rQ   r   r   )r   arrrL   s      r(   test_write_batch_error_messager  |  s     


)
)
bhhj"))+.#++-88S#J'	 * C HH&56E	~-I	J77!$	
 
K	J	Js   C  
C.c                    [         R                  [        [         R                  SS/S S///S-  [         R	                  [         R                  [         R                  5       [         R                  5       5      5      5      S.5      n[        R                  " [        SS9   [        UU S-  S	S
SS9  S S S 5        g ! , (       d  f       g = f)N)rI   rf   )rg   rw  )r   rx  rg   r  z.*not supportedr<   ztest_unsupported_map_type.shpr   r   rq   rE  )r-  rL   r.  r   list_map_r'  r>   rQ   r   r   )r   rL   s     r(   test_write_schema_error_messager    s    
 HH886"D6(34q8RXXZ89	
E 
z):	;66!$	
 
<	;	;s   B99
Cz"ignore:File /vsimem:RuntimeWarningr  r  c           
      ~   [        U SS9u  p#SUS'   [        5       n[        UUUSUS   US   US   =(       d    SS	9  [        UR	                  5       5      S
:  d   e[        U5      S
   S
   S:X  d   e[        U5      u  pV[        U5      [        U5      :X  d   e[        R                  " US   US   5      (       d   eg )NrI   rY   r  r   r   r   r   r   r  r   r1   )r   r   r   rK   	getbufferr   r   r   )r6   r  r7   rL   bufferactual_metaactual_tables          r(   test_write_memoryr    s     0qAKD*DYFK?+?+=~ v!"Q&&&vq!!$... *6 2K|E
***>>+h/h@@@@r*   c                     [        U SS9u  p[        5       n[        R                  " [        SS9   [        UUS SUS   US   US   =(       d    S	S
9  S S S 5        [        SSS9/ :X  d   eg ! , (       d  f       N= f)NrI   rY   z2driver must be provided to write to in-memory filer<   r   r   r   r   r   r  r   r   r   )r   r   r>   rQ   rR   r   r   r6   r7   rL   r  s       r(   !test_write_memory_driver_requiredr    s    0qAKDYF	B
 	U//A>	
	
 
K8B>>>
 
s   "A++
A9r;  r,  c                     [        U SS9u  p#[        5       n[        R                  " [        SU 3S9   [        UUUSUS   US   US   =(       d    S	S
9  S S S 5        g ! , (       d  f       g = f)NrI   rY   z/writing to in-memory file is not supported for r<   r   r   r   r   r   r  )r   r   r>   rQ   rR   r   r6   r  r7   rL   r  s        r(   $test_write_memory_unsupported_driverr    su     0qAKDYF	KF8T
 	U//A>	

 
 
s   "A
A,c                     [        U SS9u  p#SUS'   [        5       n[        R                  " [        SS9   [        UUUSUS   US   US	   =(       d    S
SS9  S S S 5        g ! , (       d  f       g = f)NrI   rY   r  r   z+append is not supported for in-memory filesr<   r   r   r   r   T)r  r  r   r   r   r   r   r   r>   rQ   rd  r   r  s        r(   $test_write_memory_append_unsupportedr    s{     0qAKD*DYF	#P
 	U//A>		

 
 
s   #A!!
A/c                     [        U SS9u  pSUS'   [        S5      n[        R                  " [        SS9   [        UUSS	US
   US   US   =(       d    SS9  S S S 5        g ! , (       d  f       g = f)NrI   rY   r  r   s   0000z5writing to existing in-memory object is not supportedr<   r  r   r   r   r   r  r  r  s       r(   &test_write_memory_existing_unsupportedr    sy    0qAKD*DWF	E
 	U//A>	
	
 
 
s   "A!!
A/c                    [        USS9u  p#SUS'   [        R                  " [        SS9   [	        U S-  S5       n[        UUS	S
US   US   US   =(       d    SS9  SSS5        SSS5        [        R                  " [        SS9   [        U S-  S5       nUR	                  SS5       n[        UUS	S
US   US   US   =(       d    SS9  SSS5        SSS5        SSS5        [        SSS9/ :X  d   eg! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       NQ= f! , (       d  f       NZ= f! , (       d  f       Nc= f)zEVerify that writing to an open file handle is not currently supportedrI   rY   r  r   z3writing to an open file handle is not yet supportedr<   ztest.geojsonwbr  r   r   r   r   r  Nztest.geojson.zipwr   r   r   )r   r>   rQ   rd  r  r   r   r   )r   r6   r7   rL   fzs         r(   test_write_open_file_handler     s=    0qAKD*D 
#X
 (^+T2a K"?3"?3E~ 3
 
#X
 X 22C8A,$ U"&"7"&"7"I> - 9
  
K8B>>>9 32
 
& -, 98
 
s^   D"C4DD8D')"DD'D84
D	>D
D
D$ D''
D5	1D88
Ec           	         Uu  p#[         R                  S[         R                  [        R	                  S5      /5      U[         R                  U/5      05      nU S-  n[        UUSSSUS9  [        U5      u  pdUS   S   U:X  d   eXC   S   R                  5       U:X  d   eUR                  S	5      R                  5         UR                  U5      R                  S
5      n[        U5      S   nUS   S   U:X  d   e[        XRS9u  pdUS   S   U:X  d   eXC   S   R                  5       U:X  d   e [        SS05        [        XRS9n	[        S5      S:X  d   e [        SS 05        g ! [        SS 05        f = f)Nrq   r   r   r   r   )r   r   r   r   r1   r   z.cpgz
ISO-8859-1)r   SHAPE_ENCODINGCP1254)r-  rL   r   r   r   r   r   as_pyr  unlinkencodedecoder   r   )
r   encoded_textr   textrL   r   r   miscoded
bad_schemar   s
             r(   #test_non_utf8_encoding_io_shapefiler  J  s   !NHHH KLM "((D6"	
E *$H  x(MF(A$&&&;q>!T)))  '') {{8$++L9HH%a(Jh"h... x;MF(A$&&&;q>!T))):!18 <=x3%&678CCC 	 !14 89!14 89s   2'E( (E7c                     [        U5      u  p#[        R                  " [        SS9   [	        UU S-  US   SUS   =(       d    SSS	S
0S9  SSS5        g! , (       d  f       g= f)zdProviding both encoding parameter and ENCODING layer creation option
(even if blank) is not allowed.zKcannot provide both encoding parameter and "ENCODING" layer creation optionr<   r   r   r  r   r   CP936ENCODING )r   r   r   r   layer_optionsNrn  r@  s       r(   4test_encoding_write_layer_option_collision_shapefiler    sl    
 01KD	
 	z!U(/A>%r*	

 
 
rB  gpkggeojsonc           
          [        U5      u  p4[        R                  " [        SS9   [	        UU SU 3-  US   SUS   =(       d    SSS	9  S S S 5        g ! , (       d  f       g = f)
Nz-non-UTF-8 encoding is not supported for Arrowr<   ztest.r   r  r   r   r  )r   r   r   r   rn  )r   r6   r   r7   rL   s        r(   )test_non_utf8_encoding_io_arrow_exceptionr    sh     01KD	I
 	se}$U(/A>	

 
 
rB  )tr/  r   r   r   ior   packaging.versionr   zipfiler   numpyr   r   r   r   r   r	   r
   r   r   pyogrio.errorsr   r   r   pyogrio.rawr   r   r   r   pyogrio.tests.conftestr   r   r   r   r   r>   pandasrj   r   geopandas.testingr   pandas.testingr   r   ImportError
pytestmarkr   r-  r)   rH  parametrizer:   rB   rM   rT   r[   r]   rb   ro   rs   ry   r   r   r   r   r   r   r   r   r   skipifr   r   r   r   r   r   r   r   r   r   r   r.  r  filterwarningsr
  r  r  paramr:  r   r=  rA  rL  rP  rV  rb  re  rh  rk  ro  rr  ru  __version__rz  r  r  r  r  r  r  r  r  r  r  r  )r  s   0r(   <module>r     s      
  %      G F B B  	;E
 "
   K  #W T2}x>S$TU= V=0 2Y4IJ" K"
:
 K""
9
 +""?@
)
E,????<W( !	NO	F8R(	>f@UV	i 89k:RS	OO 	!H   2s)4 5	
 "c3
 4
 y ;  4	4
##" y )V   ) B * BF 	!*W   ) *F 

]]?@AAE

 2 2$ KL  M  KL  MD  2 ++$$ 9,U % 	
	=> =>@  nn&&F>> 	&  * 
 
 ($2  )$2N '89
  :
8 
 
0 .)!<=, > ,* 
 
.     6 64 
 
  & &" 
 
 BNNgm44P   
 	

 JK
  L
0 
 
0 @AIv#67A 8 B A. ? ?, $4m#DE
 F 
& Iv#67
 8 
( 
 
( &? &?R 5: 5:p 
 
0  34
 5 
o#  		Ts   &W' 2
W4
 W4
'W10W1