U
    /e7                     @   s   d dl mZ d dlZd dlZd dlZd dlmZ	 d dl
mZ dZdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    )dedentNz<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
c                  C   sf   t dttdi} t| d}||j|jfD ]0}t|j	t
|ksJtt|jt
|ks0tq0d S )Nxd      )pd	DataFramelistrangeddfrom_pandasindexr   type__name__reprAssertionErrorstrnpartitions)dfddfr    r   D/tmp/pip-unpacked-wheel-dbjnr7gq/dask/dataframe/tests/test_format.py	test_repr   s
    r   c                  C   sf   t tddddddgd} tj| dd	}t|}t||ksDt|jd
|_t||ksbtd S )N   abcde)r   r      r   category)	r   r   r	   r
   r   r   r   r   astype)r   r   s1r   r   r   test_repr_meta_mutation#   s    r#   c               
   C   s   t d tdddddddd	gtd
ttdd} t| d}d}t||ksZt	t
||ksjt	d}| |ks~t	d}dj|d}| |kst	djt|d}| |kst	d S )Njinja2   r   r      r            ABCDEFGHAAABBBCCABCaS  Dask DataFrame Structure:
                   A       B                C
npartitions=3                                
0              int64  object  category[known]
3                ...     ...              ...
6                ...     ...              ...
7                ...     ...              ...
Dask Name: from_pandas, 1 graph layera                     A       B                C
npartitions=3                                
0              int64  object  category[known]
3                ...     ...              ...
6                ...     ...              ...
7                ...     ...              ...a  <table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
    </tr>
    <tr>
      <th>npartitions=3</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>int64</td>
      <td>object</td>
      <td>category[known]</td>
    </tr>
    <tr>
      <th>3</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>6</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>7</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
  </tbody>
</table>r<div><strong>Dask DataFrame Structure:</strong></div>
{exp_table}
<div>Dask Name: from_pandas, 1 graph layer</div>	exp_table<div><strong>Dask DataFrame Structure:</strong></div>
<div>
{style}{exp_table}
</div>
<div>Dask Name: from_pandas, 1 graph layer</div>styler2   pytestimportorskipr   r   r   Categoricalr
   r   r   r   r   	to_stringformatto_htmlr5   _repr_html_r   r   expr2   r   r   r   test_dataframe_format-   s2    

+ r@   c               	   C   s   t d tjdddddddd	gtd
ttddtd
d} t| d}d}t||ksbt	t
||ksrt	d}dj|d}| |kst	djt|d}| |kst	d S )Nr$   r%   r   r   r&   r   r'   r(   r)   r*   r+   r,   r   aS  Dask DataFrame Structure:
                   A       B                C
npartitions=3                                
A              int64  object  category[known]
D                ...     ...              ...
G                ...     ...              ...
H                ...     ...              ...
Dask Name: from_pandas, 1 graph layera  <table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
    </tr>
    <tr>
      <th>npartitions=3</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>A</th>
      <td>int64</td>
      <td>object</td>
      <td>category[known]</td>
    </tr>
    <tr>
      <th>D</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>G</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>H</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
  </tbody>
</table>r0   r1   r3   r4   )r7   r8   r   r   r   r9   r
   r   r   r   r   r;   r<   r5   r=   r>   r   r   r    test_dataframe_format_with_index   s.    

+ rB   c               
   C   s   t d tdddddddd	gtd
ttdd} t| d}| }|j	rXt
d}t||kslt
t||ks|t
d}| |kst
d}dj|d}| |kst
djt|d}| |kst
d S )Nr$   r%   r   r   r&   r   r'   r(   r)   r*   r+   r,   aS  Dask DataFrame Structure:
                   A       B                C
npartitions=3                                
               int64  object  category[known]
                 ...     ...              ...
                 ...     ...              ...
                 ...     ...              ...
Dask Name: from_pandas, 1 graph layera                     A       B                C
npartitions=3                                
               int64  object  category[known]
                 ...     ...              ...
                 ...     ...              ...
                 ...     ...              ...a  <table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
    </tr>
    <tr>
      <th>npartitions=3</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th></th>
      <td>int64</td>
      <td>object</td>
      <td>category[known]</td>
    </tr>
    <tr>
      <th></th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th></th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th></th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
  </tbody>
</table>r0   r1   r3   r4   )r7   r8   r   r   r   r9   r
   r   Zclear_divisionsZknown_divisionsr   r   r   r:   r;   r<   r5   r=   r>   r   r   r   'test_dataframe_format_unknown_divisions   s6    


+ rC   c               
   C   s   t d tdddddddd	gd
 tdd
 ttdd
 d} t| d
}d}t||ksft	t
||ksvt	d}| |kst	d}dj|d}| |kst	djt|d}| |kst	d S )Nr$   r%   r   r   r&   r   r'   r(   r)   
   r*   r+   r,   a  Dask DataFrame Structure:
                    A       B                C
npartitions=10                                
0               int64  object  category[known]
8                 ...     ...              ...
...               ...     ...              ...
72                ...     ...              ...
79                ...     ...              ...
Dask Name: from_pandas, 1 graph layeraH                      A       B                C
npartitions=10                                
0               int64  object  category[known]
8                 ...     ...              ...
...               ...     ...              ...
72                ...     ...              ...
79                ...     ...              ...a  <table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
      <th>C</th>
    </tr>
    <tr>
      <th>npartitions=10</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>int64</td>
      <td>object</td>
      <td>category[known]</td>
    </tr>
    <tr>
      <th>8</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>72</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>79</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
  </tbody>
</table>r0   r1   r3   r4   r6   r>   r   r   r   test_dataframe_format_longA  s2    

	1 rE   c               	   C   s   t jddddddddgtd	d
} t| d}d}t||ksBtt||ksRtd}| |ksftt jddddddddgtd	dd} t| d}d}t||kstt||kstd S )Nr%   r   r   r&   r   r'   r(   r)   r*   rA   zDask Series Structure:
npartitions=3
A    int64
D      ...
G      ...
H      ...
dtype: int64
Dask Name: from_pandas, 1 graph layerz9npartitions=3
A    int64
D      ...
G      ...
H      ...ZXXX)r   namezDask Series Structure:
npartitions=3
A    int64
D      ...
G      ...
H      ...
Name: XXX, dtype: int64
Dask Name: from_pandas, 1 graph layer	r   Seriesr   r
   r   r   r   r   r:   sZdsr?   r   r   r   test_series_format  s    "$rK   c                  C   sv   t jddddddddd	d
g
d
 tdd
 d} t| d
}d}t||ksNtt||ks^td}| |ksrtd S )Nr%   r   r   r&   r   r'   r(   r)   	   rD   Z
ABCDEFGHIJrA   zDask Series Structure:
npartitions=10
A    int64
B      ...
     ...  
J      ...
J      ...
dtype: int64
Dask Name: from_pandas, 1 graph layerzEnpartitions=10
A    int64
B      ...
     ...  
J      ...
J      ...rG   rI   r   r   r   test_series_format_long  s    .rM   c                  C   s   t jddddddddgtd	d
} t| d}d}t|j|ksDtt|j|ksVtt jddddddddgt j	ddddddddgddd
} t| d}t
d}t|j|kstt|j|kstd S )Nr%   r   r   r&   r   r'   r(   r)   r*   rA   zDask Index Structure:
npartitions=3
A    object
D       ...
G       ...
H       ...
dtype: object
Dask Name: from_pandas-index, 2 graph layersZYYY)rF   z    Dask Index Structure:
    npartitions=3
    1    category[known]
    4                ...
    7                ...
    8                ...
    Name: YYY, dtype: category
    Dask Name: from_pandas-index, 2 graph layers)r   rH   r   r
   r   r   r   r   r   ZCategoricalIndexr   rI   r   r   r   test_index_format  s    "rN   c                  C   sZ   t dddgd} tj| dd}|j }d}t||ksBtd}t||ksVtd S )	Nr   r   r   r    r%   r   zDask Series Structure:
npartitions=1
0    category[known]
2                ...
dtype: category
Dask Name: from_pandas, 1 graph layerzDask Series Structure:
npartitions=1
0    category[unknown]
2                  ...
dtype: category
Dask Name: from_pandas, 1 graph layer)	r   rH   r!   r
   r   catZ
as_unknownr   r   )rJ   Zknownunknownr?   r   r   r   test_categorical_format  s    
rQ   c                  C   s:   t jtddddd} tj| ddgd}t| d S )NrD   r   r   )r   r   )chunksr   )columns)daZ
from_arraynpZarangeZreshaper
   Zfrom_dask_arrayr   )Zarrframer   r   r   test_duplicate_columns_repr  s    rW   c                  C   sZ   t d t } tj| dd}d}t||ks4td}djt	|d}|
 |ksVtd S )Nr$   r%   r   zaEmpty Dask DataFrame Structure:
Columns: []
Divisions: [, ]
Dask Name: from_pandas, 1 graph layera  <table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
    </tr>
    <tr>
      <th>npartitions=1</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th></th>
    </tr>
    <tr>
      <th></th>
    </tr>
  </tbody>
</table>r3   r4   )r7   r8   r   r   r
   r   r   r   r;   r5   r=   r>   r   r   r   test_empty_repr  s    
 rX   )textwrapr   ZnumpyrU   Zpandasr   r7   Z
dask.arrayarrayrT   Zdask.dataframeZ	dataframer
   r5   r   r#   r@   rB   rC   rE   rK   rM   rN   rQ   rW   rX   r   r   r   r   <module>   s$   	
^Uaf#"