U
    +if{                     @  s  U d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
Z
d dlZd dlmZmZmZmZmZ d dlZd dlZd dlmZmZmZ d dlmZ d d	lmZmZmZmZm Z  d dl!Z"d d
l!m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZS d dlTmUZUmVZV d dlWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ d dl`maZambZbmcZcmdZd d dlemfZfmgZgmhZh d dlimjZj d dlkmlZl er8d dl!mmZmmnZn dZodZpddddgZqderd< ddd d!gZsderd"< etd#d$d%d&gZuderd'< d(d)d*d+gZvderd,< eqeu Zwesev Zxeyd-d.gZzderd/< d0d1gZ{derd2< e|d3d4gZ}derd5< e~d6d7gZderd8< d9d:gZderd;< d<d=gZderd>< ed?gZderd@< edAgZderdB< edCgZderdD< ezew Zee} e e e e e e ZejejejejejejejejgZdeje"jeydEe"jedFgZdGdH ejejfD Ze
dIZeefZdJdK ZdLdM Ze  dNdO Zd?dPdQdRZddTdUZdVdW ZdXdY Zdd[d\Zdd]d^Zdd`daZddbdcZddddeZddfdgZddhdiZddjdkZddldmZddndoZddqdrdsdtduZddqdwdsdxdyZddqdzdsd{d|Zd d}d~ZddddddddddddddddddddddddddgZdddZdd ZddqddsddZdddZdddZdddZdd ZdddZdddZdddZd	ddZd
ddZddPddZdd Zdd ZÐdddZĐdddZŐdddĄZƐdddƄZǐdddɄZȐddd̄ZG dd΄ de+ZG ddЄ de%ZG dd҄ de#Z̐dddԄZdd֜dd؄Zdddۜdd݄Ze"jjjҠӡ Zdd߄ Zd6ddddZdd Zdd Zdd Zdd Zdd Zdd Zd?dPddZdS (      )annotationsN)datetime)Decimalwraps)TYPE_CHECKINGCallableContextManagerCounterIterable)can_set_localeget_locales
set_locale)Dtype)is_float_dtypeis_integer_dtypeis_sequenceis_unsigned_integer_dtypepandas_dtype)
CategoricalCategoricalIndex	DataFrameDatetimeIndexIndexIntervalIndex
MultiIndex
RangeIndexSeriesbdate_range)closenetworkround_trip_localpathround_trip_pathlibround_trip_picklewith_connectivity_checkwrite_to_compressed)randboolrandsrands_arrayrandu_array)assert_produces_warning)assert_almost_equalassert_attr_equalassert_categorical_equalassert_class_equalassert_contains_allassert_copyassert_datetime_array_equalassert_dict_equalassert_equalassert_extension_array_equalassert_frame_equalassert_index_equal!assert_indexing_slices_equivalentassert_interval_array_equalassert_is_sorted"assert_is_valid_plot_return_objectassert_metadata_equivalentassert_numpy_array_equalassert_period_array_equalassert_series_equalassert_sp_array_equalassert_timedelta_array_equalraise_assert_detail)	get_dtypeget_obj)
RNGContextdecompress_fileensure_cleanensure_clean_dir!ensure_safe_environment_variablesset_timezoneuse_numexprwith_csv_dialect)Float64Index
Int64IndexNumericIndexUInt64Index)BaseMaskedArrayExtensionArrayPandasArray)NDArrayBackedExtensionArray)extract_array)PeriodIndexTimedeltaIndex      uint8uint16uint32uint64zlist[Dtype]UNSIGNED_INT_NUMPY_DTYPESZUInt8ZUInt16ZUInt32ZUInt64UNSIGNED_INT_EA_DTYPESint8int16int32int64SIGNED_INT_NUMPY_DTYPESZInt8ZInt16ZInt32ZInt64SIGNED_INT_EA_DTYPESfloat32float64FLOAT_NUMPY_DTYPESZFloat32ZFloat64FLOAT_EA_DTYPESZ	complex64Z
complex128COMPLEX_DTYPESstrUSTRING_DTYPESzdatetime64[ns]zM8[ns]DATETIME64_DTYPESztimedelta64[ns]zm8[ns]TIMEDELTA64_DTYPESboolBOOL_DTYPESbytesBYTES_DTYPESobjectOBJECT_DTYPESnanNaNc                 C  s    g | ]}d D ]}|d|qqS ))YMWDhmsmsusnsZpsfsasNaT ).0clsunitr   r   K/home/mars/bis/venv/lib/python3.8/site-packages/pandas/_testing/__init__.py
<listcomp>   s    r   z^$c                  C  s0   t jdd} d| kr,tD ]}td| qd S )NPANDAS_TESTING_MODENone	deprecatealwaysosenvironget_testing_mode_warningswarningssimplefilterZtesting_modecategoryr   r   r   set_testing_mode   s    r   c                  C  s0   t jdd} d| kr,tD ]}td| qd S )Nr   r   r   ignorer   r   r   r   r   reset_testing_mode   s    r   c                   C  s   t jddd dS )zJ
    Reset the display options for printing and representing objects.
    z	^display.T)ZsilentN)pdZreset_optionr   r   r   r   reset_display_options   s    r   )returnc                 C  s   t | t |kS )zO
    Checks if the set of unique elements of arr1 and arr2 are equivalent.
    )	frozenset)Zarr1Zarr2r   r   r   equalContents   s    r   Tc                 C  s   |t jkr2t| tr&tt| j} qt | } n|tkrFt	| } n|t
krXt
| } nn|tkrt
|  } |r| j} t j| gd dd} n:|tjks|tjkrt| } n|tkrt| } nt|| S )z
    Helper function to wrap the expected output of a test in a given box_class.

    Parameters
    ----------
    expected : np.ndarray, Index, Series
    box_cls : {Index, Series, DataFrame}

    Returns
    -------
    subclass of box_cls
       T)Zignore_index)r   array
isinstancer   rR   npasarray_valuesr   Z_with_inferr   r   Zto_frameTconcatndarrayto_arrayNotImplementedError)expectedZbox_clsZ	transposer   r   r   box_expected   s&    



r   c                 C  s*   t | dd}|dkrt| S t| ddS )zQ
    Similar to pd.array, but does not cast numpy dtypes to nullable dtypes.
    dtypeNT)Zextract_numpy)getattrr   r   rT   )objr   r   r   r   r     s    
r   c                 C  s   t jd |  S N)stringascii_uppercasekr   r   r   getCols%  s    r   
   c                 C  s   t td| d|dS Nr   Zncharssizename)r   r(   r   r   r   r   r   makeStringIndex*  s    r   c                 C  s   t td| d|dS r   )r   r)   r   r   r   r   makeUnicodeIndex.  s    r      c                 K  s4   t d|d}ttjt| | |dfd|i|S )z%make a length k index or n categoriesrX   r   )
categoriesr   )r(   r   r   Z
from_codesr   arange)r   nr   kwargsxr   r   r   makeCategoricalIndex2  s    r   c                 K  s*   t jdd| d d}tj|fd|i|S )zmake a length k IntervalIndexr   d      )numr   )r   Zlinspacer   Zfrom_breaks)r   r   r   r   r   r   r   makeIntervalIndex:  s    r   c                 C  sL   | dkrt dg|dS | dkr.t ddg|dS t ddgdg| d   |dS )Nr   Tr   r   F)r   r   r   r   r   makeBoolIndex@  s
    r   c                C  s   t |}t|tjstt|rNtj| |d}t|r|d|jd d  7 }nNt	|rtj
| tj
d }|  |dtj
dd  }ntd| t|||d	S )
Nr   r      r   r   r   	   zwrong dtype )r   r   )r   r   r   r   AssertionErrorr   r   r   itemsizer   randomZrandom_samplesortrandintr   rN   )r   r   r   valuesr   r   r   makeNumericIndexH  s    r   c                 C  s   t | |dd}t|S )Nrb   r   r   )r   rM   r   r   Zbase_idxr   r   r   makeIntIndexZ  s    r   c                 C  s   t | |dd}t|S )Nr\   r   )r   rO   r   r   r   r   makeUIntIndex_  s    r   c                 K  s   t d| dfd|i|S )Nr   r   r   )r   )r   r   r   r   r   r   makeRangeIndexd  s    r   c                 C  s   t | |dd}t|S )Nrf   r   )r   rL   r   r   r   r   makeFloatIndexh  s    r   Bintr   )r   r   c                 K  s0   t ddd}t|| ||d}t|fd|i|S )N  r   )periodsfreqr   r   )r   r   r   )r   r   r   r   dtZdrr   r   r   makeDateIndexm  s    r   rz   rV   c                 K  s   t jf d| ||d|S )Nz1 daystartr   r   r   )r   Ztimedelta_range)r   r   r   r   r   r   r   makeTimedeltaIndexs  s    r   rU   c                 K  s&   t ddd}tjf || d|d|S )Nr   r   r   r   )r   r   Zperiod_range)r   r   r   r   r   r   r   makePeriodIndexw  s    r   c                 K  s   t jdd|i|S )N)Zfoobar)r   r   names)r   )r   Zfrom_product)r   r   r   r   r   r   makeMultiIndex|  s    r   ZAliceZBobZCharlieZDanZEdithZFrankZGeorgeZHannahZIngridZJerryZKevinZLauraZMichaelZNorbertZOliverZPatriciaZQuinnZRayZSarahZTimZUrsulaZVictorZWendyZXavierZYvonneZZelda
2000-01-01
2000-12-311Dc           	      C  s   t j| ||dd}t|}tj|}|jt|d|jd|d|	|d d |	|d d d}t
||t|d}|jd	 |kr|jd
d	 }|S )a  
    Make a DataFrame with a DatetimeIndex

    Parameters
    ----------
    start : str or Timestamp, default "2000-01-01"
        The start of the index. Passed to date_range with `freq`.
    end : str or Timestamp, default "2000-12-31"
        The end of the index. Passed to date_range with `freq`.
    freq : str or Freq
        The frequency to use for the DatetimeIndex
    seed : int, optional
        The random state seed.

        * name : object dtype with string names
        * id : int dtype with
        * x, y : float dtype

    Examples
    --------
    >>> _make_timeseries()  # doctest: +SKIP
                  id    name         x         y
    timestamp
    2000-01-01   982   Frank  0.031261  0.986727
    2000-01-02  1025   Edith -0.086358 -0.032920
    2000-01-03   982   Edith  0.473177  0.298654
    2000-01-04  1009   Sarah  0.534344 -0.750377
    2000-01-05   963   Zelda -0.271573  0.054424
    ...          ...     ...       ...       ...
    2000-12-27   980  Ingrid -0.132333 -0.422195
    2000-12-28   972   Frank -0.376007 -0.298687
    2000-12-29  1009  Ursula -0.865047 -0.503133
    2000-12-30  1000  Hannah -0.063757 -0.507336
    2000-12-31   972     Tim -0.869120  0.531685
    	timestamp)r   endr   r   )r   i  r   r   )r   idr   y)indexcolumnsN)r   Z
date_rangelenr   r   RandomStatechoice_namesZpoissonrandr   sortedr   iloc)	r   r   r   seedr   r   stater   dfr   r   r   _make_timeseries  s    $r   c                  c  s    t ttttttg} | E d H  d S r   )r   r   r   r   r   r   r   )make_index_funcsr   r   r   index_subclass_makers_generator  s    	r   zIterable[Index]c                 c  s$   t ttg}|D ]}|| dV  qdS )z
    Generator which can be iterated over to get instances of all the classes
    which represent time-series.

    Parameters
    ----------
    k: length of each of the index instances
    r   N)r   r   r   )r   r   Zmake_index_funcr   r   r   all_timeseries_index_generator  s    
r   c                 C  s   t t}ttjt|| dS Nr   r   r   _Nr   r   r   randnr   r   r   r   r   makeFloatSeries  s    r  c                 C  s   t t}ttjt|| dS r  r  r  r   r   r   makeStringSeries  s    r  c                 C  s*   t t}t|td}t t}t||| dS )Nr   r  )r   r  r   rs   r   )r   datar   r   r   r   makeObjectSeries  s    r
  c                     s   t t  fddttD S )Nc                   s"   i | ]}|t tjt d qS )r   )r   r   r   r  r  r   cr  r   r   
<dictcomp>  s      z!getSeriesData.<locals>.<dictcomp>)r   r  r   _Kr   r   r  r   getSeriesData  s    r  c                 C  s*   | d krt } ttj| t| |d|dS )N)r   r  )r  r   r   r   r  r   )nperr   r   r   r   r   makeTimeSeries  s    
 
 r  c                 C  s&   | d krt } ttj| t| |dS r  )r  r   r   r   r  r   )r  r   r   r   r   makePeriodSeries  s    r  c                   s    fddt tD S )Nc                   s   i | ]}|t  qS r   )r  r  r   r  r   r   r    s      z%getTimeSeriesData.<locals>.<dictcomp>r   r  )r  r   r   r  r   getTimeSeriesData  s    r  c                   s    fddt tD S )Nc                   s   i | ]}|t  qS r   )r  r  r  r   r   r    s      z!getPeriodData.<locals>.<dictcomp>r  r  r   r  r   getPeriodData  s    r  c                 C  s   t | |}t|S r   )r  r   )r  r   r	  r   r   r   makeTimeDataFrame  s    
r  r   c                  C  s   t  } t| S r   )r  r   )r	  r   r   r   makeDataFrame#  s    r  c                  C  sN   t dddddg} dddd	d
gdddddgdddddgtdddd}| |fS )Nabr  deg              ?g       @g      @g      @Zfoo1Zfoo2Zfoo3Zfoo4Zfoo5z1/1/2009   )r   )Ar   Crz   )r   r   )r   r	  r   r   r   getMixedTypeDict(  s    
r#  c                   C  s   t t d S )Nr   )r   r#  r   r   r   r   makeMixedDataFrame5  s    r$  c                 C  s   t | }t|S r   )r  r   )r  r	  r   r   r   makePeriodFrame9  s    r%  #Fc                   sT  |dkrdg| }t |r&t||ks*t|dksR|dksR|dksRt||ksRt|dksn|dkrj|dksnt|dkr fddt|D }|dkrd}t|tr|dkr|g}tttt	t
ttd}||}|r|| }|r|d	 |_|S |dk	rtt| d
t||k r.|dg|t|   t||ks@ttdd |D sXtg }	t|D ]x}
dd }| ||
  d }t }t|D ]&}  d|
 d| }||
 ||< qt| |dd|  }|	| qdtt|	 }| dkr
t|d	 |d	 d}nF|dkrB|dkr"dn|d	 }tdd |D |d}ntj||d}|S )a  
    Create an index/multindex with given dimensions, levels, names, etc'

    nentries - number of entries in index
    nlevels - number of levels (> 1 produces multindex)
    prefix - a string prefix for labels
    names - (Optional), bool or list of strings. if True will use default
       names, if false will use no names, if a list is given, the name of
       each level in the index will be taken from the list.
    ndupe_l - (Optional), list of ints, the number of rows for which the
       label will repeated at the corresponding level, you can specify just
       the first few, the rest will use the default ndupe_l of 1.
       len(ndupe_l) <= nlevels.
    idx_type - "i"/"f"/"s"/"u"/"dt"/"p"/"td".
       If idx_type is not None, `idx_nlevels` must be 1.
       "i"/"f" creates an integer/float index,
       "s"/"u" creates a string/unicode index
       "dt" create a datetime index.
       "td" create a datetime index.

        if unspecified, string labels will be generated.
    Nr   FTifr}   ur   ptdc                   s   g | ]} t | qS r   )rj   )r   r(  prefixr   r   r   a  s     z#makeCustomIndex.<locals>.<listcomp>)r(  r)  r}   r*  r   r,  r+  r   zI is not a legal value for `idx_type`, use  'i'/'f'/'s'/'u'/'dt'/'p'/'td'.c                 s  s   | ]}|d kV  qdS r   Nr   r   r   r   r   r   	<genexpr>  s     z"makeCustomIndex.<locals>.<genexpr>c                 S  s*   dd l }|dd| d}dd |D S )Nr   z[^\d_]_? _c                 S  s   g | ]}t |qS r   )r   )r   r   r   r   r   r     s     z4makeCustomIndex.<locals>.keyfunc.<locals>.<listcomp>)resubsplit)r   r4  Znumeric_tupler   r   r   keyfunc  s    z makeCustomIndex.<locals>.keyfuncZ_lZ_g)keyr   c                 s  s   | ]}|d  V  qdS r/  r   r0  r   r   r   r1    s     )r   )r   r   r   ranger   rj   r   r   r   r   r   r   r   r   r   
ValueErrorreprextendallcollectionsr
   r   elementsappendlistzipr   r   from_tuples)Znentriesnlevelsr.  r   ndupe_lidx_typeZidx_func_dictZidx_funcidxZlist_of_listsr(  r7  Z
div_factorZcntjlabelresultZtuplesr   r   r   r-  r   makeCustomIndex>  sn    
(	




rK  r   c                   s   |dkst |dkst |dks4|dkr0|dks4t |
dksP|
dkrL|dksPt t|d|||
d}t| |d|||d} dkrdd	   fd
dt| D }t||||	dS )a
  
    Create a DataFrame using supplied parameters.

    Parameters
    ----------
    nrows,  ncols - number of data rows/cols
    c_idx_names, idx_names  - False/True/list of strings,  yields No names ,
            default names or uses the provided names for the levels of the
            corresponding index. You can provide a single string when
            c_idx_nlevels ==1.
    c_idx_nlevels - number of levels in columns index. > 1 will yield MultiIndex
    r_idx_nlevels - number of levels in rows index. > 1 will yield MultiIndex
    data_gen_f - a function f(row,col) which return the data value
            at that position, the default generator used yields values of the form
            "RxCy" based on position.
    c_ndupe_l, r_ndupe_l - list of integers, determines the number
            of duplicates for each label at a given level of the corresponding
            index. The default `None` value produces a multiplicity of 1 across
            all levels, i.e. a unique index. Will accept a partial list of length
            N < idx_nlevels, for just the first N levels. If ndupe doesn't divide
            nrows/ncol, the last label might have lower multiplicity.
    dtype - passed to the DataFrame constructor as is, in case you wish to
            have more control in conjunction with a custom `data_gen_f`
    r_idx_type, c_idx_type -  "i"/"f"/"s"/"u"/"dt"/"td".
        If idx_type is not None, `idx_nlevels` must be 1.
        "i"/"f" creates an integer/float index,
        "s"/"u" creates a string/unicode index
        "dt" create a datetime index.
        "td" create a timedelta index.

            if unspecified, string labels will be generated.

    Examples
    --------
    # 5 row, 3 columns, default names on both, single index on both axis
    >> makeCustomDataframe(5,3)

    # make the data a random int between 1 and 100
    >> mkdf(5,3,data_gen_f=lambda r,c:randint(1,100))

    # 2-level multiindex on rows with each label duplicated
    # twice on first level, default names on both axis, single
    # index on both axis
    >> a=makeCustomDataframe(5,3,r_idx_nlevels=2,r_ndupe_l=[2])

    # DatetimeIndex on row, index with unicode labels on columns
    # no names on either axis
    >> a=makeCustomDataframe(5,3,c_idx_names=False,r_idx_names=False,
                             r_idx_type="dt",c_idx_type="u")

    # 4-level multindex on rows with names provided, 2-level multindex
    # on columns with default labels and default names.
    >> a=makeCustomDataframe(5,3,r_idx_nlevels=4,
                             r_idx_names=["FEE","FIH","FOH","FUM"],
                             c_idx_nlevels=2)

    >> a=mkdf(5,3,r_idx_nlevels=2,c_idx_nlevels=4)
    r   Nr'  r   r"  )rD  r.  r   rE  rF  Rc                 S  s   d|  d| S )NrL  r"  r   )rr  r   r   r   <lambda>      z%makeCustomDataframe.<locals>.<lambda>c                   s$   g | ]  fd dt D qS )c                   s   g | ]} |qS r   r   r  )
data_gen_frM  r   r   r     s     z2makeCustomDataframe.<locals>.<listcomp>.<listcomp>)r9  )r   rP  ncols)rM  r   r     s     z'makeCustomDataframe.<locals>.<listcomp>r   )r   rK  r9  r   )nrowsrR  Zc_idx_namesZr_idx_namesZc_idx_nlevelsZr_idx_nlevelsrP  Z	c_ndupe_lZ	r_ndupe_lr   Z
c_idx_typeZ
r_idx_typer   r   r	  r   rQ  r   makeCustomDataframe  s@    H
rT  c                   s   |d krt j}nt j|}td|    d}d}t| | } fdd}|||}|jk r|d9 }|||}qdt |d  t}	||	  t}
|
	 |		 fS )Nr   r   gRQ?c                   s.   |  t|}tt|   d  S r   )r   r   r   uniquefloor)rngZ_extra_sizeindrR  rS  r   r   r   _gen_unique_rand#  s    z-_create_missing_idx.<locals>._gen_unique_randg?r  )
r   r   r   roundminr   rV  Zastyper   tolist)rS  rR  densityrandom_stateZmin_rowsZfac
extra_sizerZ  rX  rH  r(  r   rY  r   _create_missing_idx  s    

ra  ?c                 C  s0   t  }t|j| |d\}}tj|j||f< |S )N)r^  r_  )r  ra  shaper   ru   r   )r^  r_  r   r(  rH  r   r   r   makeMissingDataframe1  s    rd  r   c                   sF   dkst dk	  r(tks(t ddl fdd}|S )a
  
    Decorator to run the same function multiple times in parallel.

    Parameters
    ----------
    num_threads : int, optional
        The number of times the function is run in parallel.
    kwargs_list : list of dicts, optional
        The list of kwargs to update original
        function kwargs on different threads.

    Notes
    -----
    This decorator does not pass the return value of the decorated function.

    Original from scikit-image:

    https://github.com/scikit-image/scikit-image/pull/1519

    r   Nc                   s    t   fdd}|S )Nc                    s|   r fdd}n fdd}g }t D ]&}||}j| |d}|| q,|D ]}|  qX|D ]}|  qjd S )Nc                   s   t  f|  S r   )dictr(  )r   kwargs_listr   r   rN  W  rO  z?test_parallel.<locals>.wrapper.<locals>.inner.<locals>.<lambda>c                   s    S r   r   rf  r   r   r   rN  Y  rO  )targetargsr   )r9  Threadr@  r   join)rj  r   Zupdate_kwargsthreadsr(  Zupdated_kwargsthread)funchas_kwargs_listrg  num_threads	threadingrh  r   innerT  s    
z-test_parallel.<locals>.wrapper.<locals>.innerr   )ro  rs  rp  rg  rq  rr  )ro  r   wrapperS  s    ztest_parallel.<locals>.wrapper)r   r   rr  )rq  rg  ru  r   rt  r   test_parallel8  s    rv  c                   @  s,   e Zd ZddgZedd Zedd ZdS )SubclassedSeriestestattrr   c                 C  s   dd S )Nc                  _  s
   t | |S r   rw  rj  r   r   r   r   rN  s  rO  z/SubclassedSeries._constructor.<locals>.<lambda>r   selfr   r   r   _constructorl  s    zSubclassedSeries._constructorc                 C  s   dd S )Nc                  _  s
   t | |S r   SubclassedDataFramerz  r   r   r   rN  w  rO  z9SubclassedSeries._constructor_expanddim.<locals>.<lambda>r   r{  r   r   r   _constructor_expanddimu  s    z'SubclassedSeries._constructor_expanddimN)__name__
__module____qualname__	_metadatapropertyr}  r  r   r   r   r   rw  i  s
   
rw  c                   @  s*   e Zd ZdgZedd Zedd ZdS )r  rx  c                 C  s   dd S )Nc                  _  s
   t | |S r   r~  rz  r   r   r   rN    rO  z2SubclassedDataFrame._constructor.<locals>.<lambda>r   r{  r   r   r   r}  }  s    z SubclassedDataFrame._constructorc                 C  s   dd S )Nc                  _  s
   t | |S r   ry  rz  r   r   r   rN    rO  z9SubclassedDataFrame._constructor_sliced.<locals>.<lambda>r   r{  r   r   r   _constructor_sliced  s    z'SubclassedDataFrame._constructor_slicedN)r  r  r  r  r  r}  r  r   r   r   r   r  z  s
   
r  c                   @  s   e Zd Zedd ZdS )SubclassedCategoricalc                 C  s   t S r   )r  r{  r   r   r   r}    s    z"SubclassedCategorical._constructorN)r  r  r  r  r}  r   r   r   r   r    s   r  c                   s"   rfdd}n fdd}|S )a`  
    Create a function for calling on an array.

    Parameters
    ----------
    alternative : function
        The function to be called on the array with no NaNs.
        Only used when 'skipna_alternative' is None.
    skipna_alternative : function
        The function to be called on the original array

    Returns
    -------
    function
    c                   s
    | j S r   )r   r   )skipna_alternativer   r   skipna_wrapper  s    z,_make_skipna_wrapper.<locals>.skipna_wrapperc                   s"   |   }t|dkrtjS  |S )Nr   )Zdropnar   r   ru   )r   Znona)alternativer   r   r    s    r   )r  r  r  r   )r  r  r   _make_skipna_wrapper  s    r  z	list[str])	rows_listc                 C  s   t j}|| | S )aW  
    Convert list of CSV rows to single CSV-formatted string for current OS.

    This method is used for creating expected value of to_csv() method.

    Parameters
    ----------
    rows_list : List[str]
        Each element represents the row of csv.

    Returns
    -------
    str
        Expected output of to_csv() in current OS.
    )r   lineseprl  )r  sepr   r   r   convert_rows_list_to_csv_str  s    r  ztype[Exception]r	   )expected_exceptionr   c                 C  s   ddl }|j| ddS )a$  
    Helper function to mark pytest.raises that have an external error message.

    Parameters
    ----------
    expected_exception : Exception
        Expected error to raise.

    Returns
    -------
    Callable
        Regular `pytest.raises` function with `match` equal to `None`.
    r   N)match)pytestZraises)r  r  r   r   r   external_error_raised  s    r  c                   s@   g }|D ]2\ |  f | fddtD 7 }q|S )a  
    Combine frame, functions from com._cython_table
    keys and expected result.

    Parameters
    ----------
    ndframe : DataFrame or Series
    func_names_and_expected : Sequence of two items
        The first item is a name of a NDFrame method ('sum', 'prod') etc.
        The second item is the expected return value.

    Returns
    -------
    list
        List of three items (DataFrame, function, expected result)
    c                   s"   g | ]\}}|kr| fqS r   r   )r   ro  r   r   	func_namendframer   r   r     s   z+get_cython_table_params.<locals>.<listcomp>)r@  cython_table)r  Zfunc_names_and_expectedresultsr   r  r   get_cython_table_params  s    
r  r   )op_namer   c                   sP   |  d}ztt|}W n2 tk
rJ   tt|dd   fdd}Y nX |S )z
    The operator function for a given op name.

    Parameters
    ----------
    op_name : str
        The op name, in form of "add" or "__add__".

    Returns
    -------
    function
        A function performing the operation.
    r3  r   Nc                   s
    || S r   r   )r   r   Zropr   r   rN    rO  z"get_op_from_name.<locals>.<lambda>)stripr   operatorAttributeError)r  Zshort_opnameopr   r  r   get_op_from_name  s    
r  c                 C  s   | S r   r   r  r   r   r   getitem  s    r  c                 C  s   | S r   r   r  r   r   r   setitem  s    r  c                 C  s   | j S r   )locr  r   r   r   r    s    r  c                 C  s   | j S r   )r   r  r   r   r   r     s    r   c                 C  s   | j S r   )atr  r   r   r   r    s    r  c                 C  s   | j S r   )iatr  r   r   r   r  #  s    r  c                 C  s  t | tjr$t |tjr$t| |S t | tjr:t|| S t | trHdS t | tr^t| j|S t | ttfrxt| j	|S t | t
rt| j|S t | tjjjrt| j|S t | tjjjrt| j|pt| j|S t | tr:| jdkr:t |tr:|jdkr:| j}|j}|d d }|d d }||kS t | trtt |trtt| j|jprt| j|jS t | trt| jjdkr| jjd }t||S tt| t|dS )z-
    Pandas-compat for np.shares_memory.
    Fzstring[pyarrow]r   r   N) r   r   r   shares_memoryr   r   _codesr   r   r   rS   Z_ndarrayr   coreZarraysZSparseArrayZ	sp_valuesZIntervalArray_left_rightrQ   r   _datachunkbuffersrP   Z_maskr   r   Z_mgrr   type)leftrightZleft_pa_dataZright_pa_dataZ	left_buf1Z
right_buf1Zarrr   r   r   r  *  s@    



 
r  )T)r   N)r   N)r   r   N)r   N)r   N)r   N)r   N)r   N)r   N)r   N)r   r   N)r   rz   N)r   N)r   N)r   r   r   N)r   )N)N)N)Nr   N)NN)Nr   )N)Nr   )N)r&  FNN)
TTr   r   NNNNNN)N)rb  N)r   N)N)
__future__r   r>  r   decimalr   	functoolsr   r  r   r4  r   typingr   r   r	   r
   r   r   numpyr   Zpandas._config.localizationr   r   r   Zpandas._typingr   Zpandas.core.dtypes.commonr   r   r   r   r   Zpandasr   r   r   r   r   r   r   r   r   r   r   Zpandas._testing._ior   r    r!   r"   r#   r$   r%   Zpandas._testing._randomr&   r'   r(   r)   Zpandas._testing._warningsr*   Zpandas._testing.assertersr+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   Zpandas._testing.compatrB   rC   Zpandas._testing.contextsrD   rE   rF   rG   rH   rI   rJ   rK   Zpandas.core.apirL   rM   rN   rO   Zpandas.core.arraysrP   rQ   rR   Zpandas.core.arrays._mixinsrS   Zpandas.core.constructionrT   rU   rV   r  r  r]   __annotations__r^   r   rc   rd   ZALL_INT_NUMPY_DTYPESZALL_INT_EA_DTYPESfloatrg   rh   complexri   rj   rl   rm   rn   ro   rp   rq   rr   rs   rt   ZALL_REAL_NUMPY_DTYPESZALL_NUMPY_DTYPESZfloat16re   r_   r`   ra   rY   rZ   r[   ZNARROW_NP_DTYPESru   r   ZNAZNULL_OBJECTSZ
datetime64Ztimedelta64ZNP_NAT_OBJECTScompileZEMPTY_STRING_PATTERNDeprecationWarningResourceWarningr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r  r  r#  r$  r%  rK  rT  ra  rd  rv  rw  r  r  r  r  r  r  commonZ_cython_tableitemsr  r  r  r  r  r  r   r  r  r  r   r   r   r   <module>   sd   0$	d(



)









3      
p         
k1 