3
®ybdB  ã               @   s:  d dl Zd dlZd dlmZ d dlZd dljZ	d dl
mZmZ ddlm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„ ƒZejdd„ ƒZejdd„ ƒZejjdƒZG dd„ dƒZG dd „ d eejƒZG d!d"„ d"eej ƒZ!G d#d$„ d$eej"ƒZ#G d%d&„ d&eej$ƒZ%G d'd(„ d(eej&ƒZ'G d)d*„ d*eej(ƒZ)G d+d,„ d,eej*ƒZ+eG d-d.„ d.eej,ƒƒZ-G d/d0„ d0eej.ƒZ/eG d1d2„ d2eej0ƒƒZ1eG d3d4„ d4eej2ƒƒZ3G d5d6„ d6eej4ƒZ5G d7d8„ d8eej6ƒZ7G d9d:„ d:eej8ƒZ9eG d;d<„ d<eej:ƒƒZ;dS )=é    N)Ú_np_version_under1p16)ÚPandasArrayÚPandasDtypeé   )ÚbaseÚfloatÚobject)Úparamsc             C   s   t tj| jƒƒS )N)r   ÚnpÚdtypeÚparam)Úrequest© r   úE/tmp/pip-install-4cy230dp/pandas/pandas/tests/extension/test_numpy.pyr      s    r   c             c   s,   | j ƒ �}|jtddƒ dV  W dQ R X dS )aó  
    A monkeypatch to tells pandas to let us in.

    By default, passing a PandasArray to an index / series / frame
    constructor will unbox that PandasArray to an ndarray, and treat
    it as a non-EA column. We don't want people using EAs without
    reason.

    The mechanism for this is a check against ABCPandasArray
    in each constructor.

    But, for testing, we need to allow them in pandas. So we patch
    the _typ of PandasArray, so that we evade the ABCPandasArray
    check.
    Z_typÚ	extensionN)ÚcontextÚsetattrr   )ZmonkeypatchÚmr   r   r   Úallow_in_pandas   s    
r   c             C   s:   |j dkr$tjdd„ tdƒD ƒƒjS ttjdd|jd�ƒS )Nr   c             S   s   g | ]
}|f‘qS r   r   )Ú.0Úir   r   r   ú
<listcomp>+   s    zdata.<locals>.<listcomp>éd   r   ée   )r   )	Únumpy_dtypeÚpdÚSeriesÚrangeÚarrayr   r
   ÚarangeÚ_dtype)r   r   r   r   r   Údata(   s    
r!   c             C   sD   |j dkr0trtjdƒ‚ttjtjdgtd�ƒS ttjtjdgƒƒS )Nr   zSkipping for NumPy <1.16r   )r   g      ð?)r   )	r   r   ÚpytestÚskipr   r
   r   Únanr   )r   r   r   r   r   Údata_missing/   s
    

r%   c               C   s   t jS )N)r
   r$   r   r   r   r   Úna_value:   s    r&   c              C   s   dd„ } | S )Nc             S   s   t j| ƒot j|ƒS )N)r
   Úisnan)ÚaÚbr   r   r   ÚcmpA   s    zna_cmp.<locals>.cmpr   )r*   r   r   r   Úna_cmp?   s    r+   c             C   s@   |j dkr,ttjf dd	d
gtd�dd… ƒS ttjd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   Nr   )r,   )r-   )r   )r   r   r
   r   r   )r   r   r   r   r   Údata_for_sortingG   s    
"r.   c             C   s:   |j dkr$ttjdtjdgtd�ƒS ttjdtj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   r   r   )r   )r   )r   )r   r   r
   r   r$   r   )r   r   r   r   r   Údata_missing_for_sortingU   s    
r/   c          
   C   sN   |j dkrd	\}}}ntjdƒ\}}}ttj||tjtj||||g|j d�ƒS )
z“Data 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   r   r,   r-   )r   ©r   ©r,   ©r-   )r0   r1   r2   )r   r
   r   r   r   r$   )r   r   r(   r)   Úcr   r   r   Údata_for_groupinga   s
    
r4   c             C   s   | dkrt jdƒ‚dS )aŒ  
    Tests for PandasArray with nested data. Users typically won't create
    these objects via `pd.array`, but they can show up through `.array`
    on a Series with nested data. Many of the base tests fail, as they aren't
    appropriate for nested data.

    This fixture allows these tests to be skipped when used as a usefixtures
    marker to either an individual test or a test class.
    r   zSkipping for object dtype.N)r"   r#   )r   r   r   r   Úskip_numpy_objectr   s    r5   c               @   s   e Zd ZdS )ÚBaseNumPyTestsN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r6   „   s   r6   c                   s0   e Zd Ze‡ fdd„ƒZe‡ fdd„ƒZ‡  ZS )ÚTestCastingc                s   t ƒ j|ƒ d S )N)ÚsuperÚtest_astype_str)Úselfr!   )Ú	__class__r   r   r<   ‰   s    zTestCasting.test_astype_strc                s   t ƒ j|ƒ d S )N)r;   Útest_astype_string)r=   r!   )r>   r   r   r?   Ž   s    zTestCasting.test_astype_string)r7   r8   r9   Úskip_nestedr<   r?   Ú__classcell__r   r   )r>   r   r:   ˆ   s   r:   c                   sF   e Zd Zejjdd�dd„ ƒZe‡ fdd„ƒZe‡ fdd„ƒZ	‡  Z
S )	ÚTestConstructorszWe don't register our dtype)Úreasonc             C   s   d S )Nr   )r=   r!   r   r   r   Útest_from_dtype–   s    z TestConstructors.test_from_dtypec                s   t ƒ j|ƒ d S )N)r;   Útest_array_from_scalars)r=   r!   )r>   r   r   rE   ›   s    z(TestConstructors.test_array_from_scalarsc                s   t ƒ j||ƒ d S )N)r;   Ú)test_series_constructor_scalar_with_index)r=   r!   r   )r>   r   r   rF       s    z:TestConstructors.test_series_constructor_scalar_with_index)r7   r8   r9   r"   Úmarkr#   rD   r@   rE   rF   rA   r   r   )r>   r   rB   •   s   rB   c               @   s"   e Zd Zejjdd�dd„ ƒZdS )Ú	TestDtypezIncorrect expected.)rC   c             C   s   d S )Nr   )r=   r!   r   r   r   Útest_check_dtype§   s    zTestDtype.test_check_dtypeN)r7   r8   r9   r"   rG   r#   rI   r   r   r   r   rH   ¦   s   rH   c                   s<   e Zd Ze‡ fdd„ƒZe‡ fdd„ƒZ‡ fdd„Z‡  ZS )ÚTestGetitemc                s   t ƒ j|ƒ d S )N)r;   Útest_getitem_scalar)r=   r!   )r>   r   r   rK   ®   s    zTestGetitem.test_getitem_scalarc                s   t ƒ j|ƒ d S )N)r;   Útest_take_series)r=   r!   )r>   r   r   rL   ³   s    zTestGetitem.test_take_seriesc                sD   |j j}|tks|tjkr4tjjdd�}|jj	|ƒ t
ƒ j|ƒ d S )Nz,GH#33125 astype doesn't recognize data.dtype)rC   )r   r   r   r
   Úfloat64r"   rG   ÚxfailÚnodeÚ
add_markerr;   Ú test_loc_iloc_frame_single_dtype)r=   r!   r   ZnpdtyperG   )r>   r   r   rQ   ¸   s    z,TestGetitem.test_loc_iloc_frame_single_dtype)r7   r8   r9   r@   rK   rL   rQ   rA   r   r   )r>   r   rJ   ­   s   rJ   c                   s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚTestGroupbyc                sN   d}||ƒ|k}|j jtjkr<|r<tjjdd�}|jj|ƒ t	ƒ j
||ƒ d S )Nr(   z,GH#33125 astype doesn't recognize data.dtype)rC   )r   r   r
   rM   r"   rG   rN   rO   rP   r;   Útest_groupby_extension_apply)r=   r4   Zgroupby_apply_opr   r(   Zis_identityrG   )r>   r   r   rS   Ä   s    z(TestGroupby.test_groupby_extension_apply)r7   r8   r9   r@   rS   rA   r   r   )r>   r   rR   Ã   s   rR   c                   s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚTestInterfacec                s   t ƒ j|ƒ d S )N)r;   Útest_array_interface)r=   r!   )r>   r   r   rU   Ô   s    z"TestInterface.test_array_interface)r7   r8   r9   r@   rU   rA   r   r   )r>   r   rT   Ó   s   rT   c            	       sz  e Zd Zejjdd�dd„ ƒZejjdd�‡ fdd„ƒZejjdd�‡ fd	d
„ƒZ	e
‡ fdd„ƒZe
‡ fdd„ƒZe
ejjdejdd„ gƒejjddd„ ejgƒ‡ fdd„ƒƒƒZe
‡ fdd„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZe
ejjd d!d"d#d"d#d$ggƒ‡ fd%d&„ƒƒZejjd'd�‡ fd(d)„ƒZe
ejjdejejejgƒ‡ fd*d+„ƒƒZ‡  ZS ),ÚTestMethodszTODO: remove?)rC   c             C   s   d S )Nr   )r=   Zall_dataZdropnar   r   r   Útest_value_countsÛ   s    zTestMethods.test_value_countsz&not working. will be covered by #32028c                s   t ƒ j|ƒS )N)r;   Ú test_value_counts_with_normalize)r=   r!   )r>   r   r   rX   ß   s    z,TestMethods.test_value_counts_with_normalizezIncorrect expectedc                s   t ƒ j|ƒ d S )N)r;   Útest_combine_le)r=   Údata_repeated)r>   r   r   rY   ã   s    zTestMethods.test_combine_lec                s   t ƒ j|ƒ d S )N)r;   Útest_combine_add)r=   rZ   )r>   r   r   r[   é   s    zTestMethods.test_combine_addc                s   t ƒ j|ƒ d S )N)r;   Útest_shift_fill_value)r=   r!   )r>   r   r   r\   î   s    z!TestMethods.test_shift_fill_valueÚboxc             C   s   | S )Nr   )Úxr   r   r   Ú<lambda>ô   s    zTestMethods.<lambda>Úmethodc             C   s   | j ƒ S )N)Úunique)r^   r   r   r   r_   õ   s    c                s   t ƒ j|||ƒ d S )N)r;   Útest_unique)r=   r!   r]   r`   )r>   r   r   rb   ó   s    zTestMethods.test_uniquec                s   t ƒ j|ƒ d S )N)r;   Útest_fillna_copy_frame)r=   r%   )r>   r   r   rc   ú   s    z"TestMethods.test_fillna_copy_framec                s   t ƒ j|ƒ d S )N)r;   Útest_fillna_copy_series)r=   r%   )r>   r   r   rd   ÿ   s    z#TestMethods.test_fillna_copy_seriesc                s   t ƒ j||ƒ d S )N)r;   Útest_hash_pandas_object_works)r=   r!   Úas_frame)r>   r   r   re     s    z)TestMethods.test_hash_pandas_object_worksc                s   t ƒ j||ƒ d S )N)r;   Útest_searchsorted)r=   r.   Ú	as_series)r>   r   r   rg   	  s    zTestMethods.test_searchsortedc                s   t ƒ j|||ƒ d S )N)r;   Útest_where_series)r=   r!   r&   rf   )r>   r   r   ri     s    zTestMethods.test_where_seriesÚrepeatsr   r   r,   r-   c                s   t ƒ j||||ƒ d S )N)r;   Útest_repeat)r=   r!   rj   rh   Z	use_numpy)r>   r   r   rk     s    zTestMethods.test_repeatz"PandasArray.diff may fail on dtypec                s   t ƒ j||ƒS )N)r;   Ú	test_diff)r=   r!   Zperiods)r>   r   r   rl     s    zTestMethods.test_diffc                s   t ƒ j||||ƒ d S )N)r;   Útest_equals)r=   r!   r&   rh   r]   )r>   r   r   rm     s    zTestMethods.test_equals)r7   r8   r9   r"   rG   r#   rW   rN   rX   rY   r@   r[   r\   Úparametrizer   r   ra   rb   rc   rd   re   rg   ri   rk   rl   r   Z	DataFramerm   rA   r   r   )r>   r   rV   Ú   s$   (*rV   c                   sT   e Zd ZdZdZdZdZdd„ Zej	j
dƒdd„ ƒZ‡ fdd„Z‡ fd	d
„Z‡  ZS )ÚTestArithmeticsNc             C   s    t j|ƒ}| j|t|d d� d S )N)Úexc)r   r   Z_check_divmod_opÚdivmod)r=   r!   Úsr   r   r   Útest_divmod_series_array+  s    
z(TestArithmetics.test_divmod_series_arrayzWe implement opsc             C   s   d S )Nr   )r=   r!   Úall_arithmetic_operatorsr   r   r   Ú
test_error/  s    zTestArithmetics.test_errorc                s   t ƒ j||ƒ d S )N)r;   Útest_arith_series_with_scalar)r=   r!   rt   )r>   r   r   rv   3  s    z-TestArithmetics.test_arith_series_with_scalarc                s   t ƒ j||ƒ d S )N)r;   Útest_arith_series_with_array)r=   r!   rt   )r>   r   r   rw   6  s    z,TestArithmetics.test_arith_series_with_array)r7   r8   r9   Z
divmod_excZseries_scalar_excZframe_scalar_excZseries_array_excrs   r"   rG   r#   ru   rv   rw   rA   r   r   )r>   r   ro   $  s   ro   c                   s*   e Zd Zejjdd�‡ fdd„ƒZ‡  ZS )ÚTestPrintingz:GH#33125 PandasArray.astype does not recognize PandasDtype)rC   c                s   t ƒ j|ƒ d S )N)r;   Útest_series_repr)r=   r!   )r>   r   r   ry   ;  s    zTestPrinting.test_series_repr)r7   r8   r9   r"   rG   rN   ry   rA   r   r   )r>   r   rx   :  s   rx   c               @   s   e Zd Zdd„ ZdS )ÚTestNumericReducec             C   s:   t ||ƒ|d�}t |j|jjƒ|ƒ|d�}tj||ƒ d S )N)Úskipna)ÚgetattrZastyper   r    ÚtmZassert_almost_equal)r=   rr   Zop_namer{   ÚresultÚexpectedr   r   r   Úcheck_reduceD  s    zTestNumericReduce.check_reduceN)r7   r8   r9   r€   r   r   r   r   rz   B  s   rz   c               @   s   e Zd ZdS )ÚTestBooleanReduceN)r7   r8   r9   r   r   r   r   r�   K  s   r�   c                   sh   e Zd Ze‡ fdd„ƒZe‡ fdd„ƒZe‡ fdd„ƒZe‡ fdd„ƒZej	j
d	ƒ‡ fd
d„ƒZ‡  ZS )ÚTestMissingc                s   t ƒ j|ƒ d S )N)r;   Útest_fillna_scalar)r=   r%   )r>   r   r   rƒ   Q  s    zTestMissing.test_fillna_scalarc                s   t ƒ j||ƒ d S )N)r;   Útest_fillna_series_method)r=   r%   Zfillna_method)r>   r   r   r„   V  s    z%TestMissing.test_fillna_series_methodc                s   t ƒ j|ƒ d S )N)r;   Útest_fillna_series)r=   r%   )r>   r   r   r…   [  s    zTestMissing.test_fillna_seriesc                s   t ƒ j|ƒ d S )N)r;   Útest_fillna_frame)r=   r%   )r>   r   r   r†   `  s    zTestMissing.test_fillna_framezInvalid testc                s   t ƒ jtƒ d S )N)r;   Útest_fillna_fill_otherr%   )r=   r!   )r>   r   r   r‡   e  s    z"TestMissing.test_fillna_fill_other)r7   r8   r9   r@   rƒ   r„   r…   r†   r"   rG   r#   r‡   rA   r   r   )r>   r   r‚   P  s
   r‚   c                   sœ   e Zd Zejjdƒ‡ fdd„ƒZejjdd�‡ fdd„ƒZejjdd�‡ fdd	„ƒZ	e
‡ fd
d„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZe
‡ fdd„ƒZ‡  ZS )ÚTestReshapingzIncorrect parent testc                s   t ƒ j|ƒ d S )N)r;   Útest_concat_mixed_dtypes)r=   r!   )r>   r   r   r‰   m  s    z&TestReshaping.test_concat_mixed_dtypesz:GH#33125 PandasArray.astype does not recognize PandasDtype)rC   c                s   t ƒ j||ƒ d S )N)r;   Útest_concat)r=   r!   Úin_frame)r>   r   r   rŠ   r  s    zTestReshaping.test_concatc                s   t ƒ j||ƒ d S )N)r;   Útest_concat_all_na_block)r=   r%   r‹   )r>   r   r   rŒ   x  s    z&TestReshaping.test_concat_all_na_blockc                s   t ƒ j||ƒ d S )N)r;   Ú
test_merge)r=   r!   r&   )r>   r   r   r�   ~  s    zTestReshaping.test_mergec                s   t ƒ j|ƒ d S )N)r;   Útest_merge_on_extension_array)r=   r!   )r>   r   r   rŽ   ƒ  s    z+TestReshaping.test_merge_on_extension_arrayc                s   t ƒ j|ƒ d S )N)r;   Ú(test_merge_on_extension_array_duplicates)r=   r!   )r>   r   r   r�   ˆ  s    z6TestReshaping.test_merge_on_extension_array_duplicatesc                s   t ƒ j|ƒ d S )N)r;   Útest_transpose)r=   r!   )r>   r   r   r�   �  s    zTestReshaping.test_transpose)r7   r8   r9   r"   rG   r#   r‰   rN   rŠ   rŒ   r@   r�   rŽ   r�   r�   rA   r   r   )r>   r   rˆ   l  s   rˆ   c                   s  e Zd Ze‡ fdd„ƒZe‡ fdd„ƒZe‡ fdd„ƒZe‡ fdd„ƒZe‡ fd	d
„ƒZe‡ fdd„ƒZ	e‡ fdd„ƒZ
e‡ fdd„ƒZeejjdddgƒ‡ fdd„ƒƒZe‡ fdd„ƒZeejjdejdddddgƒejdddddgdd�gddgd�‡ fd d!„ƒƒZe‡ fd"d#„ƒZeejjd$d%d&d'gejd%d&d'gd(d�ejd%d&d'gƒgd)d*dgd�‡ fd+d,„ƒƒZeejjd-d%d&d'ejgdfejd%d&d'ejgdejjd.�ejd%d&d'ejgd(d�dfejd%d&d'ejgd(d�dfgd/d0d1d2gd�‡ fd3d4„ƒƒZe‡ fd5d6„ƒZe‡ fd7d8„ƒZ‡  ZS )9ÚTestSetitemc                s   t ƒ j||ƒ d S )N)r;   Útest_setitem_scalar_series)r=   r!   Úbox_in_series)r>   r   r   r’   “  s    z&TestSetitem.test_setitem_scalar_seriesc                s   t ƒ j||ƒ d S )N)r;   Útest_setitem_sequence)r=   r!   r“   )r>   r   r   r”   ˜  s    z!TestSetitem.test_setitem_sequencec                s   t ƒ j||ƒ d S )N)r;   Ú.test_setitem_sequence_mismatched_length_raises)r=   r!   Zas_array)r>   r   r   r•   ž  s    z:TestSetitem.test_setitem_sequence_mismatched_length_raisesc                s   t ƒ j||ƒ d S )N)r;   Ú test_setitem_sequence_broadcasts)r=   r!   r“   )r>   r   r   r–   £  s    z,TestSetitem.test_setitem_sequence_broadcastsc                s   t ƒ j|ƒ d S )N)r;   Útest_setitem_loc_scalar_mixed)r=   r!   )r>   r   r   r—   ©  s    z)TestSetitem.test_setitem_loc_scalar_mixedc                s   t ƒ j|ƒ d S )N)r;   Ú,test_setitem_loc_scalar_multiple_homogoneous)r=   r!   )r>   r   r   r˜   ®  s    z8TestSetitem.test_setitem_loc_scalar_multiple_homogoneousc                s   t ƒ j|ƒ d S )N)r;   Útest_setitem_iloc_scalar_mixed)r=   r!   )r>   r   r   r™   ³  s    z*TestSetitem.test_setitem_iloc_scalar_mixedc                s   t ƒ j|ƒ d S )N)r;   Ú-test_setitem_iloc_scalar_multiple_homogoneous)r=   r!   )r>   r   r   rš   ¸  s    z9TestSetitem.test_setitem_iloc_scalar_multiple_homogoneousÚsetterÚlocNc                s   t ƒ j||ƒ d S )N)r;   Útest_setitem_mask_broadcast)r=   r!   r›   )r>   r   r   r�   ½  s    z'TestSetitem.test_setitem_mask_broadcastc                s   t ƒ j|ƒ d S )N)r;   Ú&test_setitem_scalar_key_sequence_raise)r=   r!   )r>   r   r   rž   Ä  s    z2TestSetitem.test_setitem_scalar_key_sequence_raiseÚmaskTFÚboolean)r   znumpy-arrayzboolean-array)Úidsc                s   t ƒ j|||ƒ d S )N)r;   Útest_setitem_mask)r=   r!   rŸ   r“   )r>   r   r   r¢   Ì  s    
zTestSetitem.test_setitem_maskc                s   t ƒ j||ƒ d S )N)r;   Útest_setitem_mask_raises)r=   r!   r“   )r>   r   r   r£   Ø  s    z$TestSetitem.test_setitem_mask_raisesÚidxr   r   r,   ZInt64Úlistzinteger-arrayc                s   t ƒ j|||ƒ d S )N)r;   Útest_setitem_integer_array)r=   r!   r¤   r“   )r>   r   r   r¦   Ü  s    z&TestSetitem.test_setitem_integer_arrayzidx, box_in_series)Zmarksz
list-Falsez	list-Truezinteger-array-Falsezinteger-array-Truec                s   t ƒ j|||ƒ d S )N)r;   Ú(test_setitem_integer_with_missing_raises)r=   r!   r¤   r“   )r>   r   r   r§   å  s    z4TestSetitem.test_setitem_integer_with_missing_raisesc                s   t ƒ j||ƒ d S )N)r;   Útest_setitem_slice)r=   r!   r“   )r>   r   r   r¨   ó  s    zTestSetitem.test_setitem_slicec                s   t ƒ j|ƒ d S )N)r;   Útest_setitem_loc_iloc_slice)r=   r!   )r>   r   r   r©   ÷  s    z'TestSetitem.test_setitem_loc_iloc_slice)r7   r8   r9   r@   r’   r”   r•   r–   r—   r˜   r™   rš   r"   rG   rn   r�   rž   r
   r   r   r¢   r£   r¦   ZNAr   rN   r§   r¨   r©   rA   r   r   )r>   r   r‘   ’  sB    *r‘   c               @   s   e Zd ZdS )ÚTestParsingN)r7   r8   r9   r   r   r   r   rª   ü  s   rª   )<Znumpyr
   r"   Zpandas.compat.numpyr   Zpandasr   Zpandas._testingZ_testingr}   Zpandas.core.arrays.numpy_r   r   Ú r   Zfixturer   r   r!   r%   r&   r+   r.   r/   r4   r5   rG   Zusefixturesr@   r6   ZBaseCastingTestsr:   ZBaseConstructorsTestsrB   ZBaseDtypeTestsrH   ZBaseGetitemTestsrJ   ZBaseGroupbyTestsrR   ZBaseInterfaceTestsrT   ZBaseMethodsTestsrV   ZBaseArithmeticOpsTestsro   ZBasePrintingTestsrx   ZBaseNumericReduceTestsrz   ZBaseBooleanReduceTestsr�   ZBaseMissingTestsr‚   ZBaseReshapingTestsrˆ   ZBaseSetitemTestsr‘   ZBaseParsingTestsrª   r   r   r   r   Ú<module>   sJ   
J&j