o
    ҷhD=                     @   s  d dl mZ d dl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 d dlmZmZmZmZmZmZ d dlmZ e
jdd Zdd	 Zd
d Ze
jdg ddd Ze
jdg ddd Zdd Z e
jdg ddd Z!dd Z"dd Z#dd Z$d d! Z%d"d# Z&d$d% Z'e
jj(ed&d'd(d) Z)e
jj*e d*d'd+d, Z+e
jj(ed-d'd.d/ Z,d0d1 Z-d2d3 Z.d4d5 Z/e
jj*e d6d'd7d8 Z0d9d: Z1e
jj2d;d< Z3dS )=    )StringION)ascii_uppercase)IS64PYPY)CategoricalIndex	DataFrame
MultiIndexSeries
date_rangeoption_contextc                   C   s   t tjddg ddS )z&Dataframe with duplicate column names.   )i     )ar   br   columns)r   nprandomdefault_rngstandard_normal r   r   T/var/www/html/venv/lib/python3.10/site-packages/pandas/tests/io/formats/test_info.pyduplicate_columns_frame   s   r   c                  C   s:   t  } t }| j|d | }td}||ksJ d S )Nbufzd        <class 'pandas.core.frame.DataFrame'>
        RangeIndex: 0 entries
        Empty DataFrame
r   r   infogetvaluetextwrapdedentdfr   resultexpectedr   r   r   test_info_empty#   s   r$   c               	   C   s   d} t dtjdjd| tdi}tttd	tjdjdd| td
d	|d	< |  t }|j|d
 ||d	 dk }t }|j|d
 d S )Ni	  int64r   d   )sizedtype
abcdefghijr   
   categoryr   d)r   r   r   r   integersintr	   arraylisttakeastypeisnar   r   )nr!   r   df2r   r   r   'test_info_categorical_column_smoke_test2   s    r6   fixture_func_name)	int_framefloat_framedatetime_framer   c                 C   s<   | | }t }|j|d |  }t|dksJ d S )Nr   r*   )getfixturevaluer   r   r   
splitlineslen)r7   requestframer   r"   r   r   r   test_info_smoke_testC   s
   

r@   z&num_columns, max_info_columns, verbose))r*   r&   T)r*      T)r*   r*   T)r*   	   F)r*      Fc                 C   s   t tjdd| f}td|* t }|j|d | }t }|j||d | }||ks4J W d    d S 1 s?w   Y  d S )Nr      display.max_info_columnsr   r   verbose)	r   r   r   r   r   r   r   r   r   )num_columnsmax_info_columnsrG   r?   
io_defaultr"   io_explicitr#   r   r   r   #test_info_default_verbose_selectionT   s   "rL   c            
      C   s   t  } d}d}ttjdd|f}|jd| d |  }d}||v s'J |jd| d | d | 	 }t
|dks?J t|D ]!\}}||  krS|| k rdn qCd	||  d	}	||	sdJ qCd S )
N  rD   r      T)rG   r   z- #     Column  Dtype  
---    ------  -----  r    )r   r   r   r   r   r   r   r   seek	readlinesr=   	enumerate
startswith)
r   r'   startr?   resheaderlinesilineline_nrr   r   r   -test_info_verbose_check_header_separator_bodyl   s$   
r[   z>size, header_exp, separator_exp, first_line_exp, last_line_exp))r   $ #   Column  Non-Null Count  Dtype  $---  ------  --------------  -----  $ 0   0       3 non-null      float64z$ 3   3       3 non-null      float64)rA   r\   r]   r^   z$ 10  10      3 non-null      float64)e   z% #    Column  Non-Null Count  Dtype  z%---   ------  --------------  -----  z% 0    0       3 non-null      float64z% 100  100     3 non-null      float64)rM   z& #     Column  Non-Null Count  Dtype  z&---    ------  --------------  -----  z& 0     0       3 non-null      float64z& 1000  1000    3 non-null      float64)i'  z' #      Column  Non-Null Count  Dtype  z'---     ------  --------------  -----  z' 0      0       3 non-null      float64z' 10000  10000   3 non-null      float64c                 C   s   t tjdd| f}t }|jdd|d |  }W d   n1 s)w   Y  |dd }|^}	}
}}}|	|ksBJ |
|ksHJ ||ksNJ ||ksTJ dS )zETest header column, spacer, first line and last line in verbose mode.r   rN   T)rG   show_countsr   N)	r   r   r   r   r   r   r   r   r<   )r'   
header_expseparator_expfirst_line_explast_line_expr?   r   	all_linestablerV   	separator
first_linerest	last_liner   r   r   %test_info_verbose_with_counts_spacing   s   ,rl   c                  C   sd   t dtddgddi} t }| j|d | }t|   }t	d| d}||ks0J d S )	Nr   rC   r   i8)r(   r   a      <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 2 entries, 0 to 1
    Data columns (total 1 columns):
     #   Column  Non-Null Count  Dtype
    ---  ------  --------------  -----
     0   a       2 non-null      int64
    dtypes: int64(1)
    memory usage: z bytes
    )
r   r	   r   r   r   floatmemory_usagesumr   r   )r!   r   r"   bytesr#   r   r   r   test_info_memory   s   rr   c                  C   s   t  } ttjdd}|j| d t  } |j| dd |  }t|	 dks,J |}t
dd t  } |j| d |  }||ksGJ W d    d S 1 sRw   Y  d S )Nr   )rD   r_   r   r_   r   max_colsr&   rE   )r   r   r   r   r   r   r   r   r=   r<   r   )ior!   r"   r#   r   r   r   test_info_wide   s   "rv   c                  C   sZ   t  } tddggddgd}|j| d |  d}d|d ks#J d	|d
 ks+J d S )NrC   g       @r   r   r   Tz% 0   a       1 non-null      int64  
rD   z% 1   a       1 non-null      float64
   )r   r   r   r   r<   )ru   r?   rW   r   r   r   0test_info_duplicate_columns_shows_correct_dtypes   s   rx   c            
   	   C   s   g d} i }d}t | D ]\}}tjdjd|d|||< qt|}t }|j|d |	 }d}||v s:J t | D ]\}}d|dd	|dd
|dd| }	|	|v sYJ q>d S )Nr%   float64zdatetime64[ns]ztimedelta64[ns]
complex128objectboolr*   r   r'   r   zY #   Column  Non-Null Count  Dtype          
---  ------  --------------  -----          rO   r,   z   z       z non-null     )
rR   r   r   r   r-   r2   r   r   r   r   )
dtypesdatar4   rX   r(   r!   r   rU   rV   namer   r   r   test_info_shows_column_dtypes   s    	""r   c               	   C   s  t tjdd} dD ]4\}}tdd# t }| j||d | }t	|
 d|ks2J W d    n1 s<w   Y  qdD ]4\}}tdd	# t }| j||d | }t	|
 d|ksiJ W d    n1 ssw   Y  qDd
D ]d\}}tdd# t }| j||d | }t	|
 d|ksJ W d    n1 sw   Y  tdd	# t }| j||d | }t	|
 d|ksJ W d    n1 sw   Y  q{d S )Nr   )r*   rD   ))rD   NrD   F   TrI   r   rF   
))r   Nr   r   rD   ))r   rD   )rD   r   rs   )r   r   r   r   r   r   r   r   r   r=   stripsplit)r!   len_rG   r   rU   rt   r   r   r   test_info_max_cols
  s@   r   c                  C   s  g d} i }d}t | D ]\}}tjdjd|d|||< qt|}t }|j|dd |	 
 }d|d v s=J |j|d	d |	 
 }d|d vsRJ |j|dd |	 
 }td
|d siJ |jd d d df j|dd |	 
 }td
|d rJ g d} i }d}t | D ]\}}tjdjd|d|||< qt|}| |_tddgidgd}|j|dd |	 
 }td
|d sJ |j|dd |	 
 }td|d sJ |  }	t| | d |jj }
|	|
ksJ t|jjd }|t| ksJ |  |jdd ks(J tddgdgdjdd tddgdgdjj tdtdgtdgdgd}|jj |jdd |jjj |jdd }|dksnJ d S )Nry   r*   r   r~   T)r   ro   zmemory usage: Fzmemory usage: [^+]+\+rD   )r%   r%   r%   rz   r&   r   rC   fooindexdeepzmemory usage: [^+]+$   r   Ar   r     r   r   r   r   )rR   r   r   r   r-   r2   r   r   r   r   r<   rematchilocr   ro   rp   r=   r   nbytesr'   valuesr   from_productrange)r   r   r4   rX   r(   r!   r   rU   df_with_object_indexdf_sizeexp_sizesize_dfmemr   r   r   test_info_memory_usage,  sb   	" ""
r   z'on PyPy deep=True doesn't change result)reasonc                  C   sl   t ddgidgd} | jddd | jdd ksJ t ddgi}|jdd |  ks4J d S Nr   rC   r   r   T)r   r   r   r   ro   rp   r   	df_objectr   r   r   $test_info_memory_usage_deep_not_pypy     $r   z(on PyPy deep=True does not change resultc                  C   sl   t ddgidgd} | jddd | jdd ksJ t ddgi}|jdd |  ks4J d S r   r   r   r   r   r    test_info_memory_usage_deep_pypy  r   r   z PyPy getsizeof() fails by designc                  C   sR   t dtdgtdgdgd} | jdd }|t|  }t|dk s'J d S )	NrC   r   r   r   r   Tr   r&   )	r   r   r   r   ro   rp   sys	getsizeofabs)r!   r   diffr   r   r   test_usage_via_getsizeof  s   r   c                  C   s   t  } tdtdg dd}|j| d d|  vsJ t  } tdtdtdd}|j| d d|  v s8J t  } tdtdttdtdgd}|j| d d|  vs[J t  } tdtdttdd	d
ggd}|j| d d|  v s~J d S )NrC   ab)rC   r   rN   )r   r   r   +ABCrN   r   bar)r   r   r0   r   r   r   r   r   )r   r!   r   r   r    test_info_memory_usage_qualified  s(   r   c                  C   s   dd } d}t t}tjtttd|dgddgd}td	tj	d

|| i|d}|d}|jj|jjks;J | || |ksEJ | || | dk sQJ d S )Nc                 S   s   | j dd S )NTr   )ro   rp   )fr   r   r   ro     s   z>test_info_memory_usage_bug_on_multiindex.<locals>.memory_usager&   20160101)periodsiddate)namesvaluer   r   i  )r=   	uppercaser   r   r0   r
   r   r   r   r   r   unstackr   r   )ro   NMr   r!   	unstackedr   r   r   (test_info_memory_usage_bug_on_multiindex  s   
r   c                  C   s6   t ddg} ttd| | d}t }|j|d d S )Nr   r   )r   r   r   r   )r   r   r   zerosr   r   )idxr!   r   r   r   r   test_info_categorical  s   r   zGH 36579: fail on 32-bit systemc                  C   sT   t ddgddgdddgd} t }| jd|d	 | }td
}||ks(J d S )NrC   r   rN   )rC   r   r   Br   T)r`   r   af          <class 'pandas.core.frame.DataFrame'>
        Index: 2 entries, A to B
        Data columns (total 2 columns):
         #   Column  Non-Null Count  Dtype
        ---  ------  --------------  -----
         0   1       2 non-null      int64
         1   2       2 non-null      int64
        dtypes: int64(2)
        memory usage: 48.0+ bytes
        r   r    r   r   r   test_info_int_columns  s   r   c                  C   sf   t ddgd} td  |  }W d    n1 sw   Y  ttr%dnddgd}t|| d S )Nr   r   r      r   Index)r   tmassert_produces_warningro   r	   r   assert_series_equal)r!   r"   r#   r   r   r   "test_memory_usage_empty_no_warning  s   
r   c                  C   s   t d tddgddgg} tdd t }|   | }W d    n1 s*w   Y  t }|   | }||ks@J d S )NnumbarC   r   rN   r   zcompute.use_numbaT)pytestimportorskipr   r   r   r   r   r    r   r   r   test_info_compute_numba  s   

r   )4ru   r   r   stringr   r   r   r   numpyr   r   pandas.compatr   r   pandasr   r   r   r	   r
   r   pandas._testing_testingr   fixturer   r$   r6   markparametrizer@   rL   r[   rl   rr   rv   rx   r   r   r   skipifr   xfailr   r   r   r   r   r   r   
single_cpur   r   r   r   r   <module>   sd     

	


(
"U


	
	