o
    Ff)                  	   @   s  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
  mZ ddlZddlmZmZmZmZ ddlmZ ddlmZmZ ejdd Zdd	 Zd
d Zdd Zdd Zdd Zej j!dd Z"ej j!dd Z#dd Z$dd Z%dd Z&dd Z'ej (ddd  Z)d!d" Z*ej j!d#d$ Z+d%d& Z,d'd( Z-ejd)d*ej.d+e/d,d-ej.d.e/d.d-gd/d0d1 Z0ej 1d2d3d4gd5d6 Z2d<d8d9Z3d:d; Z4dS )=z1
Testing that we work in the downstream packages
    N)IntCastingNaNError)	DataFrameDatetimeIndexSeriesTimedeltaIndex)DatetimeArrayTimedeltaArrayc                   C   s   t dg diS )NA         )r    r   r   <lib/python3.10/site-packages/pandas/tests/test_downstream.pydf   s   r   c              
   C   sl   t d}z)td td}|j| dd}|jd usJ | d us&J W t d| d S t d| w )Ncompute.use_numexprZtoolzdask.dataframer   Znpartitions)pd
get_optionpytestimportorskipfrom_pandasr	   compute
set_option)r   olduseddZddfr   r   r   	test_dask!   s   


r   c               
   C   s~   t d} z2td}td}tg d}|j|dd}|| }t|}t	
|| W t d|  d S t d|  w )Nr   
dask.arrayr   )g      ?gffffff@g@g      @r   r   )r   r   r   r   r   r   Zfixr   nptmassert_series_equalr   )r   dar   sZdsresultexpectedr   r   r   test_dask_ufunc1   s   



r&   c                  C   s  t d} tg d}| |}t|}t|}t|| d}t jt	|d t|dd W d    n1 s9w   Y  d}tj
|d< t jt|d t|dd W d    n1 s]w   Y  t jt|d t|dd W d    d S 1 s{w   Y  d S )	Nr   )r   g      @r   z)Trying to coerce float values to integersmatchZi8dtypez9Cannot convert non-finite values \(NA or inf\) to integerr   )r   r   r   arrayZ
from_arrayr   r    r!   raises
ValueErrornanr   )r   arrZdarrresr%   msgr   r   r   7test_construct_dask_float_array_int_dtype_match_ndarrayD   s$   


"r2   c                 C   s   t d |  d usJ d S )Nxarray)r   r   Z	to_xarray)r   r   r   r   test_xarray^   s   
r4   c                  C   sT   t d} t d}|jddd}| ddd}|j|gdd	}d}||ks(J d S )
Ncftimer3   Z0001r   )periodsi  r   Znearest)method)r   r   Zcftime_rangeZDatetimeGregorianZget_indexer)r5   r3   timeskeyr$   r%   r   r   r   test_xarray_cftimeindex_nearestd   s   

r:   c                   C      t tjdddg d S )N-OO-cimport pandas
subprocessZ
check_callsys
executabler   r   r   r   test_oo_optimizablep   s   rC   c                   C   r;   )Nr<   r=   z_import pandas as pd, pickle; pickle.loads(pickle.dumps(pd.date_range('2021-01-01', periods=1)))r?   r   r   r   r   )test_oo_optimized_datetime_index_unpicklev   s   rD   c                  C   s>   t d} ttdtdtddd}| jd|d  d S )Nzstatsmodels.formula.api   d   i   )ZLotteryZLiteracyZPop1831z$Lottery ~ Literacy + np.log(Pop1831))data)r   r   r   rangeZolsfit)Zsmfr   r   r   r   test_statsmodels   s
   
rK   c                  C   sh   t d ddlm} m} |  }|jddd}||jd d |j	d d  |
|jdd   d S )Nsklearnr   )datasetssvmgMbP?g      Y@)ZgammaC)r   r   rL   rM   rN   Zload_digitsZSVCrJ   rH   targetZpredict)rM   rN   digitsZclfr   r   r   test_scikit_learn   s   
 rS   c                  C   s<   t d} ttjddddtdd}| jdd|d	 d S )
NseabornZ2023DrE   )freqr6   )day
total_billrW   rX   )xyrH   )r   r   r   r   Z
date_rangerI   Z	stripplot)rT   Ztipsr   r   r   test_seaborn   s
   
r[   c                   C   s   t d d S )NZpandas_datareader)r   r   r   r   r   r   test_pandas_datareader   s   r\   z0ignore:Passing a BlockManager:DeprecationWarningc                 C   s.   t d}|j| }| }t||  d S )Npyarrow)r   r   ZTabler   Z	to_pandasr    assert_frame_equal)r   r]   tabler$   r   r   r   test_pyarrow   s   
r`   c                 C   sP   t d}|| }|j||jd}t| | |j||jd}t| | d S )Nyaml)Loader)r   r   dumploadrb   r    r^   ZUnsafeLoader)r   ra   ZdumpedZloadedZloaded2r   r   r   test_yaml_dump   s   

re   c                  C   s   t jdd} | ddg}t| }d|v rtd | dddg}d	|  d
}tjtj	|d}tj|tj
d W d    n1 sCw   Y  |jj }dD ]}||v sXJ qPd S )N\/r=   z$import pandas;print(pandas.__file__)zsite-packagesz pandas installed as site packagez-sSEr>   zCommand '\['zD', '-sSE', '-c', 'import pandas'\]' returned non-zero exit status 1.r'   )stderr)numpyZpytzZdateutil)rA   rB   replacer@   Zcheck_outputdecoder   skipr,   ZCalledProcessErrorZSTDOUTvaluestdout)ZpyexeZcalloutputr1   excnamer   r   r    test_missing_required_dependency   s   	


rr   c               
   C   s   t d} zLtd}|ddg}tdddgi}||d< ||d< d|jd	d
gdf< |jdgd d f }tdgdgdgddgd}t|| W t 	d|  d S t 	d|  w )Nr   r   r   r   abcrF   FT)rs   rt   ru   )index)
r   r   r   r   r+   r   locr    r^   r   )r   r"   Zddar   r$   r%   r   r   r   *test_frame_setitem_dask_array_into_new_col   s   

rx   c                  C   sF   G dd d} |  }t td}||tu sJ || |u s!J d S )Nc                   @   s   e Zd ZdZdd ZdS )z%test_pandas_priority.<locals>.MyClassi  c                 S   s   | S )Nr   )selfotherr   r   r   __radd__   s   z.test_pandas_priority.<locals>.MyClass.__radd__N)__name__
__module____qualname__Z__pandas_priority__r{   r   r   r   r   MyClass   s    r   r   )r   rI   __add__NotImplemented)r   leftrightr   r   r   test_pandas_priority   s
   r   
memoryviewr+   daskr   )Zmarksr3   )paramsc                 C   s   t jg dt jd}| j}|dkrt|}||fS |dkr'td|}||fS |dkr9ddl}|j|}||fS |d	krFddl}||}||fS )
z
    Fixture giving a numpy array and a parametrized 'data' object, which can
    be a memoryview, array, dask or xarray object created from the numpy array.
    r
   r)   r   r+   ir   r   Nr3   )r   r+   Zint64paramr   Z
dask.arrayr3   	DataArray)Zrequestr/   rq   rH   r   xrr   r   r   array_likes  s    

r   r*   M8[ns]m8[ns]c           
      C   s   |\}}t td|  }|j d}tjt|d ||}W d    n1 s'w   Y  |j|| d}t|| t|t	sWt
jt
jd|  }||j}||j}t|| ttd|  }	|	|}|	|}t|| d S )N)r   r   z.__init__ is deprecatedr'   r)   )r   r   r|   r    Zassert_produces_warningFutureWarningZ_from_sequenceZassert_extension_array_equal
isinstancer   r   to_datetimeZto_timedeltar+   Zassert_equalr   r   assert_index_equal)
r*   r   r/   rH   clsZdepr_msgr%   r$   funcZidx_clsr   r   r   test_from_obscure_array)  s"   



r   returnc                  C   sn   t d tg dg dd} |  }| }ddg}||ks"J tg ddd}| }|jdks5J dS )	z
    Test some basic methods of the dataframe consortium standard.

    Full testing is done at https://github.com/data-apis/dataframe-api-compat,
    this is just to check that the entry point works as expected.
    Zdataframe_api_compatr
   )   rE      )rs   rt   rs   rt   )rq   N)r   r   r   Z!__dataframe_consortium_standard__Zget_column_namesr   Z__column_consortium_standard__rq   )Zdf_pdr   Zresult_1Z
expected_1Zsercolr   r   r   test_dataframe_consortiumH  s   
r   c                  C   sH   t d} | g d}tj|dd}tg ddd d}t|| d S )Nr3   r
   ns)Zunit)z1970-01-01 00:00:00.000000001z1970-01-01 00:00:00.000000002z1970-01-01 00:00:00.000000003zdatetime64[ns])r*   rV   )r   r   r   r   r   r   r    r   )r   r/   r$   r%   r   r   r   test_xarray_coerce_unit[  s   
	r   )r   N)5__doc__r+   r@   rA   ri   r   r   Zpandas.errorsr   Zpandas.util._test_decoratorsutilZ_test_decoratorsZtdZpandasr   r   r   r   r   Zpandas._testingZ_testingr    Zpandas.core.arraysr   r   Zfixturer   r   r&   r2   r4   r:   ZmarkZ
single_cpurC   rD   rK   rS   r[   r\   filterwarningsr`   re   rr   rx   r   r   Z
skip_if_nor   Zparametrizer   r   r   r   r   r   r   <module>   s\    


	


$


