
    d#                         d Z ddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZmZ  ej        dd          Zej        j         G d d	                      ZdS )
z test feather-format compat     N)ArrowStringArrayStringArray)read_feather
to_featherpyarrowz1.0.1)
minversionc                       e Zd Zd Zd Zdi fdZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zej        j         ej        dd          d                         Zd Zd ZdS )TestFeatherc                     t          j        ||          5  t          j                    5 }t	          ||           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nmatch)pytestraisestmensure_cleanr   )selfdfexcerr_msgpaths        X/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/tests/io/test_feather.pycheck_error_on_writez TestFeather.check_error_on_write   s     ]3g... 	% 	%"" %d2t$$$% % % % % % % % % % % % % % %	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s3   A AA A	A A	A  A$'A$c                     t          j        t                    5  t          j                    5 }t	          ||           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S N)r   external_error_raised	Exceptionr   r   )r   r   r   s      r   check_external_error_on_writez)TestFeather.check_external_error_on_write   s     %i00 	% 	%"" %d2t$$$% % % % % % % % % % % % % % %	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s3   A#AA#A	A#A	A##A'*A'Nc                     ||}t          j                    5 }t          ||fi | t          |fi |}t          j        ||           d d d            d S # 1 swxY w Y   d S r   )r   r   r   r   assert_frame_equal)r   r   expectedwrite_kwargsread_kwargsr   results          r   check_round_tripzTestFeather.check_round_trip#   s    H_ 	4$r400<000!$66+66F!&(333		4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   1AAAc                     d}t          j        g d          ddt          j        d          t          j        g d          fD ]}|                     |t          |           d S )Nz'feather only support IO with DataFrames         r'   foo20130101)pdSeries	Timestampnparrayr   
ValueError)r   msgobjs      r   
test_errorzTestFeather.test_error-   st    7Iiii  L$$HYYY
 	< 	<C %%c:s;;;;	< 	<    c                 "   t          j        t          d          t          t          dd                    t	          j        dd                              d          t	          j        ddd	
          dt          j        dgg ddt          j        dgt          j        t          d                    t          j	        t          t          j
        dd                    d           t          j	        t          t          j
        ddd                    d           t          j        d          t           j        t          j        d          gt          j	        t          t          j
        ddd                    d           d          }t          j        ddd          |d<   t          j        dd          |d<   t          j        ddd          |d<   |j        j        j        j        dk    sJ |                     |           d S ) Nabcr'      r)      u1g      @g      @float64dtypeg      ?TFTTFr+   periods)freqz
US/Eastern)r@   tz20130103ns)r@   rA   )stringintuintfloatfloat_with_nullboolbool_with_nullcatdtdttzdt_with_nulldtns2013M)rA   r@   r@   z1 day
timedeltasr   	intervals)r,   	DataFramelistranger/   arangeastypenanCategoricalDatetimeIndex
date_ranger.   NaTperiod_rangetimedelta_rangeinterval_rangerN   r=   rB   zoner$   r   r   s     r   
test_basiczTestFeather.test_basic8   s   \u++E!QKK((	!Q..t4439===$'#3+++#'"7~d5kk22&z1===>>T   (z1NNNOO  
 L,,FL,,!
 (z14HHHIIPT  + 
 
6 S!DDD9-gqAAA<+Aq!44;w}$4444b!!!!!r5   c                     t          j        t          j        d                              dd          t          d                                                    }|                     |           d S )N   r8   r)   aaacolumns)r,   rU   r/   rX   reshaperV   copyr   rc   s     r   test_duplicate_columnsz"TestFeather.test_duplicate_columns[   s\     \")B--//155tE{{KKKPPRR**2.....r5   c                     t          j        t          j        d                              dd                                                    }d}|                     |t          |           d S )Nrf   r8   r)   %feather must have string column names)r,   rU   r/   rX   rj   rk   r   r1   )r   r   r2   s      r   test_stringify_columnsz"TestFeather.test_stringify_columnsa   sX    \")B--//15566;;==5!!"j#66666r5   c                    t          j        t          d          t          t          dd                    t          d          t          t          dd                    d          }ddg}|                     |||         |	           d S )
Nr7   r'   r8   xyz   )col1col2col3col4rs   ru   )r    ri   )r,   rU   rV   rW   r$   )r   r   ri   s      r   test_read_columnszTestFeather.test_read_columnsf   s    \UU1a[[))UU1a[[))	 
 
 6"b2g;HHHHHr5   c                     t          j        ddgddgddgd          }|dd	g         }|                     ||dd	g
           d S )Nr'   r(   xyTF)ABCr|   r{   rh   )r,   rU   r$   )r   r   r    s      r   !test_read_columns_different_orderz-TestFeather.test_read_columns_different_orders   sY    \Ac3ZtUmLLMMsCj>b(S#J?????r5   c                 `    t          j        dg di          }|                     |           d S )Na)r   r'          @)r,   rU   r   rc   s     r   test_unsupported_otherz"TestFeather.test_unsupported_othery   s4    \3.//**2.....r5   c                     t          j        dt          j        d          i          }|                     |d           |                     |d           d S )Nr{   i T)use_threadsF)r,   rU   r/   rX   r$   rc   s     r   test_rw_use_threadszTestFeather.test_rw_use_threads~   sX    \3	& 1 1233bd333be44444r5   c                 D   t          j        dg di          }|                     |           d}g dt          j        dd          t	          d          g d	t           j                            g d
          fD ]%}||_        |                     |t          |           &g d|_        d|j        _
        d}|                     |t          |           g d|_        t           j                            dg          |_        d}|                     |t          |           d S )Nr{   r&   zsfeather does not support serializing .* for the index; you can \.reset_index\(\) to make the index into column\(s\))r(   r)   r8   r+   r)   r?   r7   )r'   r)   r8   )r   r'   )r   r(   )br'   )r   r'   r(   r*   z=feather does not serialize index meta-data on a default indexr   rn   )r,   rU   r$   r]   rV   
MultiIndexfrom_tuplesindexr   r1   nameri   )r   r   r2   r   s       r   test_write_with_indexz!TestFeather.test_write_with_index   s/   \3			*++b!!!L 	 IIM*a000KKIIM%%&D&D&DEE
 	; 	;E BH%%b*c:::: 99M!!"j#666 99]..z::
5!!"j#66666r5   c                     t          j                                                    }t          j        |j        t
                    }t          j        ||           d S r   )r   makeDataFramereset_indexround_trip_pathlibr   r   r   r   r   r#   s      r   test_path_pathlibzTestFeather.test_path_pathlib   sI    ++--&r}lCC
b&)))))r5   c                     t          j                                                    }t          j        |j        t
                    }t          j        ||           d S r   )r   r   r   round_trip_localpathr   r   r   r   s      r   test_path_localpathzTestFeather.test_path_localpath   sI    ++--(EE
b&)))))r5   c                     t          j                                                    }|                     |ddi           d S )Nversionr'   )r!   )r   r   r   r$   rc   s     r   test_passthrough_keywordsz%TestFeather.test_passthrough_keywords   s?    ++--b	1~>>>>>r5   khttps://raw.githubusercontent.com/pandas-dev/pandas/main/pandas/tests/io/data/feather/feather-0_3_1.featherT)urlcheck_before_testc                 p    d}t          |          }t          |          }t          j        ||           d S )Nr   )r   r   r   )r   feather_filer   r    ress        r   test_http_pathzTestFeather.test_http_path   sB    A 	  --3
h,,,,,r5   c                   	
 t          j        d          
t          j        t          j        dt
          j        dgd          t          j        g dd          t          j        dt
          j        dgd	          t          j        g d
d	          g dg dg dg dd          }|dk    rjt          t          j        g dt
          j	                            }t          t          j        ddt          j
        gt
          j	                            }nHt          
                    g d                    }t          
                    g d                    }t          j                    5 }t          ||           t          j        d|          5  t!          ||          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        t          j        dt
          j        dgd          t          j        g dd          t          j        dt
          j        dgd	          t          j        g d
d	          t          j        ddt          j
        gd          t          j        g dd          ||d          	|dk    r-ddlm t          j        	
fd	j        D                       	t          j        |	           d S )Nr   r'   r)   Int64r<   r&         ?      @Float64)r   r   r   )TFNr>   )r   r   c)r   r   N)r   r   r   defghpythonr   r   zmode.string_storagedtype_backendTFbooleanr   )ArrowExtensionArrayc           	      ^    i | ])}|                      |         d                     *S )T)from_pandas)r0   ).0colr   r    pas     r   
<dictcomp>z?TestFeather.test_read_feather_dtype_backend.<locals>.<dictcomp>   sL        ,,RXXhsmQUX-V-VWW  r5   )r   importorskipr,   rU   r-   r/   rZ   r   r0   object_NAr   r   r   r   option_contextr   pandas.arraysr   ri   r   )r   string_storager   r   string_arraystring_array_nar   r#   r   r    r   s           @@@r   test_read_feather_dtype_backendz+TestFeather.test_read_feather_dtype_backend   s    ++\Y261~W===Yyyy888YRVS1CCCYi@@@(((((($__%%%	 	
 
 X%%&rxrz'R'R'RSSL)"(Cbe3DBJ*W*W*WXXOO ,BHH___,E,EFFL.rxx8H8H8H/I/IJJO_ 	I$r4   "#8.II I I%d-HHHI I I I I I I I I I I I I I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I
 <Y261~W===Yyyy888YRVS1CCCYi@@@YeRU39EEEY222)DDD!$	 	
 
 I%%999999|     '/   H 	fh/////s6   6&GF:.G:F>	>GF>	GGGc           	      x   d}t          j        dt          t          dd                    i          }t	          j        d          5 }|                    |           t          j        t          |          5  t          |d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.rF   r'   r8   ztmp.featherr   numpyr   )r,   rU   rV   rW   r   r   r   r   r   r1   r   )r   r2   r   r   s       r   test_invalid_dtype_backendz&TestFeather.test_invalid_dtype_backend   s2   % 	 \5$uQ{{"3"3455_]++ 	:tMM$z555 : :T9999: : : : : : : : : : : : : : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s6   1B/9BB/B	B/B	B//B36B3)__name__
__module____qualname__r   r   r$   r4   rd   rl   ro   rw   r~   r   r   r   r   r   r   r   marknetworkr   r   r   r    r5   r   r
   r
      ss       % % %% % % -1r 4 4 4 4	< 	< 	<!" !" !"F/ / /7 7 7
I I I@ @ @/ / /
5 5 5
7 7 7>* * *
* * *
? ? ? [RZA   - -  -40 40 40l	: 	: 	: 	: 	:r5   r
   )__doc__r   r/   r   pandasr,   pandas._testing_testingr   pandas.core.arraysr   r   pandas.io.feather_formatr   r   r   r   r   
single_cpur
   r   r5   r   <module>r      s    " "                      
 > = = = = = = =
&
iG
<
<
< o: o: o: o: o: o: o: o: o: o:r5   