a
    1$e?                     @   s  d Z ddlZddlZddlmZ ddlZddlm	Z	 ddl
mZ ddlZddlmZ ddlmZmZmZ ddlmZmZmZ ddlZejjd	d
Zejjdd
Zejje dd
Zejdd Z dd Z!ejdd Z"ejdd Z#ejdd Z$ejddgddd Z%ejdd Z&ejdd Z'ejdd Z(ejd d! Z)ejd"d# Z*ejd$d% Z+ejd&d'gdd(d) Z,ejd*d+ d,d+ d-d+ d.d+ gg d/d0d1d2 Z-ejd&d'gdd3d4 Z.ejd&d'gdd5d6 Z/ejd&d'gdd7d8 Z0ejd9d:gdd;d< Z1ejd&d'gdd=d> Z2ejd?d@ Z3ejg dAddBdC Z4ejdDdEgddFdG Z5ejdHdIgddJdK Z6ejddLd+ gddMdN Z7G dOdP dPej8Z9G dQdR dRej:Z;G dSdT dTej<Z=G dUdV dVej>Z?G dWdX dXej@ZAG dYdZ dZejBZCG d[d\ d\ejDZEG d]d^ d^ejFZGg d_ZHejeHdd`da ZIejJdbG dcdd ddejKZLejJdbG dedf dfejMZNG dgdh dhejOZPG didj djejQZRG dkdl dlejSZTG dmdn dnejUZVeG dodp dpejWZXdS )qaw  
This file contains a minimal set of tests for compliance with the extension
array interface test suite (by inheriting the pandas test suite), and should
contain no other tests.
Other tests (eg related to the spatial functionality or integration
with GeoSeries/GeoDataFrame) should be added to test_array.py and others.

The tests in this file are inherited from the BaseExtensionTests, and only
minimal tweaks should be applied to get the tests passing (by overwriting a
parent method).

A set of fixtures are defined to provide data for the tests (the fixtures
expected to be available to pytest by the inherited pandas tests).

    N)assert_array_equal)assert_series_equal)base)Point)GeometryArrayGeometryDtypefrom_shapely)ignore_shapely2_warningsSHAPELY_GE_20PANDAS_GE_15zNot yet implementedreasonzMin/max not supportedzRequires hashable geometriesc                   C   s   t  S )z3A fixture providing the ExtensionDtype to validate.)r    r   r   `/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopandas/tests/test_extension_array.pydtype1   s    r   c                  C   sZ   t jdtd} t * dd tdD | d d < W d    n1 sD0    Y  t| }|S )Nd   r   c                 S   s   g | ]}t j||qS r   )shapelygeometryr   ).0ir   r   r   
<listcomp>:       zmake_data.<locals>.<listcomp>)npemptyobjectr	   ranger   )agar   r   r   	make_data7   s
    8r   c                   C   s   t  S )zLength-100 array for this type.

    * data[0] and data[1] should both be non missing
    * data[0] and data[1] should not be equal
    )r   r   r   r   r   data?   s    r    c                   C   s   t dS )z3Length-100 array in which all the elements are two.N)NotImplementedErrorr   r   r   r   data_for_twosI   s    r"   c                   C   s   t dtjddgS )zLength-2 array with [NA, Valid]N   r   r   r   r   r   r   r   r   data_missingO   s    r%   )paramsc                 C   s    | j dkr|S | j dkr|S dS )z5Parametrized fixture giving 'data' and 'data_missing'r    r%   Nparam)requestr    r%   r   r   r   all_dataU   s    

r*   c                    s    fdd}|S )a  
    Generate many datasets.

    Parameters
    ----------
    data : fixture implementing `data`

    Returns
    -------
    Callable[[int], Generator]:
        A callable that takes a `count` argument and
        returns a generator yielding `count` datasets.
    c                 3   s   t | D ]
} V  qd S N)r   )count_r    r   r   genn   s    zdata_repeated.<locals>.genr   )r    r/   r   r.   r   data_repeated^   s    r0   c                   C   s    t tddtddtddgS )ziLength-3 array with a known sort order.

    This should be three items [B, C, A] with
    A < B < C
    r   r#   r   r   r   r   r   r   data_for_sortingu   s    r2   c                   C   s   t tdddtddgS )zvLength-3 array with a known sort order.

    This should be three items [B, NA, A] with
    A < B and NA missing.
    r#      Nr   r1   r   r   r   r   data_missing_for_sorting   s    r4   c                   C   s   dd S )zBinary operator for comparing NA values.
    Should return a function of two arguments that returns
    True if both arguments are (scalar) NA for your type.
    By default, uses ``operator.or``
    c                 S   s   | d u o|d u S r+   r   )xyr   r   r   <lambda>   r   zna_cmp.<locals>.<lambda>r   r   r   r   r   na_cmp   s    r8   c                   C   s   dS )z6The scalar missing value for this type. Default 'None'Nr   r   r   r   r   na_value   s    r9   c                   C   sT   t tjddtjddddtjddtjddtjddtjddgS )zData for factorization, grouping, and unique tests.

    Expected to be like [B, B, NA, NA, A, A, B, C]

    Where A < B < C and NA is missing
    r#   Nr   r3   r$   r   r   r   r   data_for_grouping   s    r:   TFc                 C   s   | j S )z#Whether to box the data in a Seriesr'   r)   r   r   r   box_in_series   s    r<   c                 C   s   dS Nr#   r   r5   r   r   r   r7      r   r7   c                 C   s   dgt |  S r=   lenr>   r   r   r   r7      r   c                 C   s   t dgt|  S r=   pdSeriesr@   r>   r   r   r   r7      r   c                 C   s   | S r+   r   r>   r   r   r   r7      r   ZscalarlistZseriesr   )r&   idsc                 C   s   | j S )z,
    Functions to test groupby.apply().
    r'   r;   r   r   r   groupby_apply_op   s    rG   c                 C   s   | j S )zU
    Boolean fixture to support Series and Series.to_frame() comparison testing.
    r'   r;   r   r   r   as_frame   s    rH   c                 C   s   | j S )zL
    Boolean fixture to support arr and Series(arr) comparison testing.
    r'   r;   r   r   r   	as_series   s    rI   c                 C   s   | j S )zd
    Boolean fixture to support comparison testing of ExtensionDtype array
    and numpy array.
    r'   r;   r   r   r   	use_numpy   s    rJ   ZffillZbfillc                 C   s   | j S )z{
    Parametrized fixture giving method parameters 'ffill' and 'bfill' for
    Series.fillna(method=<method>) testing.
    r'   r;   r   r   r   fillna_method   s    rK   c                 C   s   | j S )zR
    Boolean fixture to support ExtensionDtype _from_sequence method testing.
    r'   r;   r   r   r   as_array   s    rL   c                 C   s
   t t S )z
    A scalar that *cannot* be held by this ExtensionArray.

    The default should work for most subclasses, but is not guaranteed.

    If the array can hold any item (i.e. object dtype), then use pytest.skip.
    )r   __new__r.   r   r   r   invalid_scalar   s    	rN   )
summaxminmeanprodZstdvarZmedianZkurtZskewc                 C   s   | j S )z-
    Fixture for numeric reduction names
    r'   r;   r   r   r   all_numeric_reductions   s    rU   allanyc                 C   s   | j S )z-
    Fixture for boolean reduction names
    r'   r;   r   r   r   all_boolean_reductions	  s    rX   __eq____ne__c                 C   s   | j S )zu
    Fixture for dunder names for common compare operations

    * >=
    * >
    * ==
    * !=
    * <
    * <=
    r'   r;   r   r   r   all_compare_operators  s    r[   c                 C   s   | S r+   r   r>   r   r   r   r7   "  r   c                 C   s   | j S )zk
    Simple fixture for testing keys in sorting methods.
    Tests None (no key) and the identity key.
    r'   r;   r   r   r   sort_by_key"  s    r\   c                   @   s   e Zd Zdd Zdd ZdS )	TestDtypec                 C   s   |  tu sJ d S r+   )Zconstruct_array_typer   )selfr    r   r   r   r   test_array_type_with_arg3  s    z"TestDtype.test_array_type_with_argc                 C   sF   t jt|td}|d}t|jts.J t |}t	|| d S )Nr   r   )
rB   rC   r   Zasarrayr   Zastype
isinstancearrayr   r   )r^   r    r   sresultexpectedr   r   r   test_registry6  s
    

zTestDtype.test_registryN)__name__
__module____qualname__r_   re   r   r   r   r   r]   0  s   r]   c                   @   s   e Zd Zdd Zdd ZdS )TestInterfacec                 C   s   t |}|d |d ksJ t j|td}t jt|td}t   t||d d < W d    n1 sj0    Y  t|| d S )Nr   r   )r   ra   r   r   r@   r	   rE   r   )r^   r    rc   rd   r   r   r   test_array_interface?  s    
.z"TestInterface.test_array_interfacec                 C   sX   ||    }|d |v sJ |d |v s.J d |v s:J d |vsFJ tj|vsTJ d S Nr   )ZisnarB   ZNaT)r^   r    r%   r   r   r   test_containsM  s    zTestInterface.test_containsN)rf   rg   rh   rj   rl   r   r   r   r   ri   >  s   ri   c                   @   s   e Zd ZdS )TestConstructorsNrf   rg   rh   r   r   r   r   rm   ^  s   rm   c                   @   s   e Zd ZdS )TestReshapingNrn   r   r   r   r   ro   b  s   ro   c                   @   s   e Zd ZdS )TestGetitemNrn   r   r   r   r   rp   f  s   rp   c                   @   s   e Zd ZdS )TestSetitemNrn   r   r   r   r   rq   j  s   rq   c                   @   sd   e Zd Zdd Zejddd Zejddd Zejddd	 Z	ejdd
d Z
dS )TestMissingc                 C   s   |d }t |}||}t |||g}t|| t ttjddtjddg}||}t |||g}t|| t jttjddtjddgddgd}||}t|| d S )Nr#   r3   
      )index)	rB   rC   fillnaZ_from_sequencer   r   r   r   r   )r^   r%   Z
fill_valueZserrc   rd   Zfillerr   r   r   test_fillna_serieso  s2    




	
zTestMissing.test_fillna_serieszfillna method not supportedc                 C   s   d S r+   r   r^   r%   r   r   r   test_fillna_limit_pad  s    z!TestMissing.test_fillna_limit_padc                 C   s   d S r+   r   rx   r   r   r   test_fillna_limit_backfill  s    z&TestMissing.test_fillna_limit_backfillc                 C   s   d S r+   r   )r^   r%   methodr   r   r   test_fillna_series_method  s    z%TestMissing.test_fillna_series_methodc                 C   s   d S r+   r   r^   r    r   r   r   test_fillna_no_op_returns_copy  s    z*TestMissing.test_fillna_no_op_returns_copyN)rf   rg   rh   rw   pytestmarkskipry   rz   r|   r~   r   r   r   r   rr   n  s   '






rr   c                   @   s    e Zd Zejddd ZdS )
TestReducez6boolean reduce (any/all) tested in test_pandas_methodsc                 C   s   d S r+   r   r^   r   r   r   test_reduce_series_boolean  s    z%TestReduce.test_reduce_series_booleanN)rf   rg   rh   r   r   r   r   r   r   r   r   r     s   
r   )__add____radd____mul____rmul____floordiv____rfloordiv____truediv____rtruediv____pow____rpow____mod____rmod__c                 C   s   | j S )z
    Fixture for dunder names for common arithmetic operations

    Adapted to exclude __sub__, as this is implemented as "difference".
    r'   r;   r   r   r   all_arithmetic_operators  s    r   zOignore:The array interface is deprecated and will no longer work in Shapely 2.0c                   @   s8   e Zd Zejjdddd Zejjdddd ZdS )TestArithmeticOpsznot applicabler   c                 C   s   d S r+   r   )r^   r    r"   r   r   r   test_divmod_series_array  s    z*TestArithmeticOps.test_divmod_series_arrayc                 C   s   d S r+   r   r}   r   r   r   $test_add_series_with_extension_array  s    z6TestArithmeticOps.test_add_series_with_extension_arrayN)rf   rg   rh   r   r   r   r   r   r   r   r   r   r     s   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestComparisonOpsc                 C   s4   t t|d}|||}|||}t|| d S )Nr-   )getattroperatorstripcombiner   )r^   rb   r    op_nameotheroprc   rd   r   r   r   _compare_other  s    
z TestComparisonOps._compare_otherc                 C   s&   |}t |}| ||||d  d S rk   )rB   rC   r   )r^   r    r[   r   rb   r   r   r   test_compare_scalar  s    
z%TestComparisonOps.test_compare_scalarc                 C   s:   |}t |}t |d gt| }| |||| d S rk   )rB   rC   r@   r   )r^   r    r[   r   rb   r   r   r   r   test_compare_array  s    
z$TestComparisonOps.test_compare_arrayN)rf   rg   rh   r   r   r   r   r   r   r   r     s   r   c                       s   e Zd Zejje ddejdddgdd Zejje dddd	 Z	e
ejd
ddg fddZejjdddd Zedd Zejjdddd Zedd Zedd Zedd Zedd Zedd Zedd  Z  ZS )!TestMethodsz/sorting index not yet working with older pandasr   dropnaTFc                 C   s   d S r+   r   )r^   r*   r   r   r   r   test_value_counts  s    zTestMethods.test_value_countsc                 C   s   d S r+   r   r}   r   r   r    test_value_counts_with_normalize  s    z,TestMethods.test_value_counts_with_normalize	ascendingc                    s   t  || d S r+   )supertest_sort_values_frame)r^   r2   r   	__class__r   r   r     s    z"TestMethods.test_sort_values_framezsearchsorted not supportedc                 C   s   d S r+   r   )r^   r2   rI   r   r   r   test_searchsorted  s    zTestMethods.test_searchsortedc                 C   s   d S r+   r   r   r   r   r   test_combine_le  s    zTestMethods.test_combine_lezaddition not supportedc                 C   s   d S r+   r   r   r   r   r   test_combine_add
  s    zTestMethods.test_combine_addc                 C   sH   d}t jt|d" ||dg W d    n1 s:0    Y  d S )Nz!Length of 'value' does not match.)matchr#   )r   Zraises
ValueErrorrv   take)r^   r%   msgr   r   r   test_fillna_length_mismatch  s    z'TestMethods.test_fillna_length_mismatchc                 C   s   d S r+   r   r   r   r   r   test_argmin_argmax  s    zTestMethods.test_argmin_argmaxc                 C   s   d S r+   r   r   r   r   r   test_argmin_argmax_empty_array  s    z*TestMethods.test_argmin_argmax_empty_arrayc                 C   s   d S r+   r   r   r   r   r   test_argmin_argmax_all_na  s    z%TestMethods.test_argmin_argmax_all_nac                 C   s   d S r+   r   r   r   r   r   test_argreduce_series   s    z!TestMethods.test_argreduce_seriesc                 C   s   d S r+   r   r   r   r   r   +test_argmax_argmin_no_skipna_notimplemented$  s    z7TestMethods.test_argmax_argmin_no_skipna_notimplemented)rf   rg   rh   r   r   skipifr   parametrizer   r   requires_shapely2r   r   r   not_yet_implementedr   r   r   	no_minmaxr   r   r   r   r   __classcell__r   r   r   r   r     s<   








r   c                   @   s   e Zd ZdS )TestCastingNrn   r   r   r   r   r   )  s   r   c                       s   e Zd Zeejdddg fddZe fddZeejjdd	d
 dd
 dd
 dd
 gg dd fddZ	  Z
S )TestGroupbyas_indexTFc                    s   t  || d S r+   )r   test_groupby_extension_agg)r^   r   r:   r   r   r   r   .  s    z&TestGroupby.test_groupby_extension_aggc                    s   t  | d S r+   )r    test_groupby_extension_transform)r^   r:   r   r   r   r   3  s    z,TestGroupby.test_groupby_extension_transformr   c                 C   s   dS r=   r   r>   r   r   r   r7   ;  r   zTestGroupby.<lambda>c                 C   s   dgt |  S r=   r?   r>   r   r   r   r7   <  r   c                 C   s   t dgt|  S r=   rA   r>   r   r   r   r7   =  r   c                 C   s   | S r+   r   r>   r   r   r   r7   >  r   rD   )rF   c                    s   t  || d S r+   )r   test_groupby_extension_apply)r^   r:   r   r   r   r   r   7  s    z(TestGroupby.test_groupby_extension_apply)rf   rg   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   -  s    
r   c                   @   s   e Zd ZdS )TestPrintingNrn   r   r   r   r   r   F  s   r   c                   @   s   e Zd ZdS )TestParsingNrn   r   r   r   r   r   J  s   r   )Y__doc__r   numpyr   Znumpy.testingr   ZpandasrB   Zpandas.testingr   Zpandas.tests.extensionr   Zextension_testsZshapely.geometryr   r   Zgeopandas.arrayr   r   r   Zgeopandas._compatr	   r
   r   r   r   r   r   r   r   r   Zfixturer   r   r    r"   r%   r*   r0   r2   r4   r8   r9   r:   r<   rG   rH   rI   rJ   rK   rL   rN   rU   rX   r[   r\   ZBaseDtypeTestsr]   ZBaseInterfaceTestsri   ZBaseConstructorsTestsrm   ZBaseReshapingTestsro   ZBaseGetitemTestsrp   ZBaseSetitemTestsrq   ZBaseMissingTestsrr   ZBaseNoReduceTestsr   Z_all_arithmetic_operatorsr   filterwarningsZBaseArithmeticOpsTestsr   ZBaseComparisonOpsTestsr   ZBaseMethodsTestsr   ZBaseCastingTestsr   ZBaseGroupbyTestsr   ZBasePrintingTestsr   ZBaseParsingTestsr   r   r   r   r   <module>   s   


	




	
	
	


	








	

 9

: