
    Eg                         d 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
mZ ddlmZ e	j                            d          Ze	j        j        e	j        j        gZed             Zd	 Zed
             ZdS )zd
Tests multithreading behaviour for reading and
parsing files for each parser defined in parsers.py
    )	ExitStack)BytesIO)
ThreadPoolN)	DataFramepyarrow_xfailc                 v  	
 | }d	d}	fdt          |          D             }t                      5 

fd|D             }
                    t          d                    }|                    |j        |          }|d         }|D ]}t          j        ||           	 d d d            d S # 1 swxY w Y   d S )Nd   
   c              3      K   | ]B}d                      d t                    D                                                       V  CdS )
c                 (    g | ]}|d d|d d|d S )d, ).0is     ]/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/tests/io/parser/test_multi_thread.py
<listcomp>zBtest_multi_thread_string_io_read_csv.<locals>.<genexpr>.<listcomp>"   s7    FFFAa'''A'''!'''FFF    N)joinrangeencode)r   _max_row_ranges     r   	<genexpr>z7test_multi_thread_string_io_read_csv.<locals>.<genexpr>!   sf         			FF}1E1EFFFGGNNPP     r   c                 T    g | ]$}                     t          |                    %S r   )enter_contextr   )r   bstacks     r   r   z8test_multi_thread_string_io_read_csv.<locals>.<listcomp>(   s-    FFFQ$$WQZZ00FFFr      r   )r   r   r   r   mapread_csvtmassert_frame_equal)all_parsersparser	num_filesbytes_to_dffilespoolresultsfirst_resultresultr   r   s            @@r   $test_multi_thread_string_io_read_csvr.      s,    FMI   y!!  K 
 	8FFFF+FFF"":a==11((6?E22qz 	8 	8F!,7777	8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   A.B..B25B2c                 8     fd}fdt                    D             }t                    5 }|                    ||          }ddd           n# 1 swxY w Y   |d         j        }|dd         D ]	}	||	_        
t	          j        |          }
|
S )a  
    Generate a DataFrame via multi-thread.

    Parameters
    ----------
    parser : BaseParser
        The parser object to use for reading the data.
    path : str
        The location of the CSV file to read.
    num_rows : int
        The number of rows to read per task.
    num_tasks : int
        The number of tasks to use for reading this DataFrame.

    Returns
    -------
    df : DataFrame
    c                     | \  }}|s                     dd|dg          S                      ddt          |          dz   |dg          S )aj  
        Create a reader for part of the CSV.

        Parameters
        ----------
        arg : tuple
            A tuple of the following:

            * start : int
                The starting row to start for parsing CSV
            * nrows : int
                The number of rows to read.

        Returns
        -------
        df : DataFrame
        r   date)	index_colheadernrowsparse_datesN   	   )r2   r3   skiprowsr4   r5   )r"   int)argstartr4   r&   paths      r   readerz0_generate_multi_thread_dataframe.<locals>.readerG   sy    $ u 	??!5vh #    ZZ!^  
 
 	
r   c                 *    g | ]}|z  z  z  fS r   r   )r   r   num_rows	num_taskss     r   r   z4_generate_multi_thread_dataframe.<locals>.<listcomp>i   s9       ?@A	"H	$9:  r   )	processesNr   r6   )r   r   r!   columnspdconcat)r&   r<   r?   r@   r=   tasksr*   r+   r3   rfinal_dataframes   ````       r    _generate_multi_thread_dataframerH   3   s   ( 
  
  
  
  
  
D    DI)DTDT  E 
i	(	(	( *D((65))* * * * * * * * * * * * * * * QZFQRR[  		i((Os   AA!Ac                 f   d}d}| }d}t          t          j                            d                              |          t          j                            d                              |          t          j                            d                              |          t          j                            d                              |          t          j                            d                              |          dg|z  dg|z  dg|z  t	          j        d|d	
          t          j        |d          d
          }t          j        |          5 }|	                    |           t          ||||          }t          j        ||           d d d            d S # 1 swxY w Y   d S )N   0   z__thread_pool_reader__.csv   foobarbazz20000101 09:00:00s)periodsfreqint64)dtype)
ar   cr   erM   rN   rO   r1   r9   )r   nprandomdefault_rngrC   
date_rangearanger#   ensure_cleanto_csvrH   r$   )r%   r@   r?   r&   	file_namedfr<   rG   s           r   )test_multi_thread_path_multipart_read_csvra   y   s    IHF,I	&&q))00::&&q))00::&&q))00::&&q))00::&&q))00::7X%7X%7X%M"5xcRRR9XW555	
 	

 
B 
	#	# 3t
		$:D(I
 
 	b/2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   =F&&F*-F*)__doc__
contextlibr   ior   multiprocessing.poolr   numpyrX   pytestpandasrC   r   pandas._testing_testingr#   markusefixturesxfail_pyarrow
single_cpuslow
pytestmarkr.   rH   ra   r   r   r   <module>rq      s    !                 + + + + + +                     ''88
 K
K
 8 8 80C C CL 3 3 3 3 3r   