
    >ie                       d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 	 d dlZn# e$ r dZY nw xY wd dlZd dlZd dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZmZmZ d dl m!Z! d dl"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2  G d de+          Z3	 	 	 	 	 d5dZ4d Z5	 	 	 	 	 d6dZ6d Z7d Z8d Z9d Z: e:            Z;	 	 	 	 	 	 	 	 	 d7d$Z<d%Z=d& Z>  e'j?        d'd()           e>ej@        d(d*                    Z@ e>ejA        d+d,          ZA e>ejB        d-d.          ZBdd/d0ZC	 	 	 	 	 	 	 	 	 	 d8d3ZDd d4lEmFZF eDjG        eFjD        _G        dS )9    )annotationsN)Mapping)BytesIO)catch_warningssimplefilterwarn)compr)get_fs_token_paths)open)
open_files)infer_compression)CategoricalDtypeis_datetime64_any_dtypeis_float_dtypeis_integer_dtypeis_object_dtype)tokenize)
read_bytes)flatten)dataframe_creation_dispatch)from_map)DataFrameIOFunction)clear_known_categories)delayed)
asciitableparse_bytesc                  :    e Zd ZdZd Zed             Zd Zd ZdS )CSVFunctionWrapperzg
    CSV Function-Wrapper Class
    Reads CSV data from disk to produce a partition (given a key).
    c
                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        d S N)	full_columns_columnscolnameheadheaderreaderdtypesenforcekwargs)
selfr!   columnsr#   r$   r%   r&   r'   r(   r)   s
             5lib/python3.11/site-packages/dask/dataframe/io/csv.py__init__zCSVFunctionWrapper.__init__-   sH     )	    c                Z    | j         | j        S | j        r| j         | j        gz   S | j         S r    )r"   r!   r#   )r*   s    r,   r+   zCSVFunctionWrapper.columnsC   s6    = $$< 	2=DL>11}r.   c                :    fd j         j        D              j        k    r S  j        r  j        vr j          j        gz            }n j                  }t           j         j        | j         j         fdD              j         j        	  	        S )zUReturn a new CSVFunctionWrapper object with
        a sub-column projection.
        c                    g | ]}|v |	S  r2   ).0cr+   s     r,   
<listcomp>z6CSVFunctionWrapper.project_columns.<locals>.<listcomp>P   s    @@@1<<1<<<r.   c                ,    i | ]}|j         |         S r2   )r'   )r3   r4   r*   s     r,   
<dictcomp>z6CSVFunctionWrapper.project_columns.<locals>.<dictcomp>`   s!    0001QA000r.   )	r$   r+   r#   r   r!   r%   r&   r(   r)   )r*   r+   r$   s   `` r,   project_columnsz"CSVFunctionWrapper.project_columnsK   s    
 A@@@di/@@@dl""K< 	&DL77 9W~56DD9W%D!LKK0000000LK

 

 
	
r.   c                x   |\  }}}}|?| j         |t          t          | j        | j                  j        j                            f}nd }d}| j                                        }|sZ|                    dd           d}|	                    dd            |                    dd          |	                    dd            |s|	                    dd            | j
        }	d}
| j        | j        rd}
n| j        }	|	|d<   t          | j        || j        || j        |	|| j        |	  	        }|
r|| j                 S |S )	NFnamesTskiprowsr%   r   
skipfooterusecols)r#   sortedlistr$   cat
categoriesr)   copygetpopr!   r"   pandas_read_textr&   r%   r'   r(   r+   )r*   partblockpathis_firstis_last	path_infowrite_headerrest_kwargsr+   project_after_readdfs               r,   __call__zCSVFunctionWrapper.__call__e   ss   )-&tXw tDIdl37BCCDDII I k&&(( 	0w--5#OOJ---x++7$/// 	0OOL$/// #"=${ 1 &*""-)0I& KKKL

 

  	$dl##	r.   N)	__name__
__module____qualname____doc__r-   propertyr+   r8   rP   r2   r.   r,   r   r   '   sf         
  ,   X
 
 
46 6 6 6 6r.   r   TFc	                z   t                      }	|r<|                    |                                          s|	                    |           |	                    |           |	                    d            | |	fi |}
|rt          |
|           |r=|r;t          |
j                  t          |          k    rt          d|
j        |          |rh|\  }}}|	                    |          } |
j
        di |t          j                            t          j        t!          |
          |          |          i}
|
S )aa  Convert a block of bytes to a Pandas DataFrame

    Parameters
    ----------
    reader : callable
        ``pd.read_csv`` or ``pd.read_table``.
    b : bytestring
        The content to be parsed with ``reader``
    header : bytestring
        An optional header to prepend to ``b``
    kwargs : dict
        A dictionary of keyword arguments to be passed to ``reader``
    dtypes : dict
        dtypes to assign to columns
    path : tuple
        A tuple containing path column name, path to file, and an ordered list of paths.

    See Also
    --------
    dask.dataframe.csv.read_pandas_from_bytes
    r   zColumns do not matchr2   )r   
startswithrstripwriteseekcoerce_dtypesr?   r+   
ValueErrorindexassignpdCategorical
from_codesnpfulllen)r&   br%   r)   r'   r+   rL   r(   rH   biorO   r#   pathscodes                 r,   rE   rE      sE   @ ))C ALL99 		&IIaLLLHHQKKK			v		B "b&!!! F7 FRZ 0 0DMM A A/WEEE 
#u{{4  RY 
 
11"'#b''42H2H%PPQ
 
 Ir.   c                   g }g }g }| j         D ]}||v r| j        |         ||         k    r| j        |         }||         }t          |          r(t          |          r|                    |||f           kt          |          r%t          |          r|                    |           	 | |                             ||                   | |<   # t          $ r:}|                    |||f           |                    ||f           Y d}~d}~ww xY w|r|r7d	                    d t          |d           D                       }	d|	z  }
d}nd}
d}t          |d	           }t          g d
|          }dd	                    d |D                       z  }d                    ||
||          }nd}|r=|rdnd}d	                    d |D                       }d                    ||          }nd}|s|r<ddz  }d|	                    t          d||g                    z  }t          |          dS )zCoerce dataframe to dtypes safely

    Operates in place

    Parameters
    ----------
    df: Pandas DataFrame
    dtypes: dict like {'x': float}
    N
c              3  ,   K   | ]\  }}d | d|V  dS )z- z
  Nr2   )r3   r4   es      r,   	<genexpr>z coerce_dtypes.<locals>.<genexpr>   sH        &*a!Q!!A!!     r.   c                ,    t          | d                   S Nr   strxs    r,   <lambda>zcoerce_dtypes.<locals>.<lambda>   s    3qQRt99 r.   )keyzAThe following columns also raised exceptions on conversion:

%s

 zf

Alternatively, provide `assume_missing=True` to interpret
all unspecified integer columns as floats.c                ,    t          | d                   S ro   rp   rr   s    r,   rt   zcoerce_dtypes.<locals>.<lambda>  s    c!A$ii r.   )ColumnFoundExpectedz
dtype={%s}z	,
       c              3  .   K   | ]\  }}}|d | dV  dS )z: ''Nr2   )r3   kv_s       r,   rm   z coerce_dtypes.<locals>.<genexpr>  sE       4
 4
 )AqqOOqOOO4
 4
 4
 4
 4
 4
r.   z{table}

{exceptions}Usually this is due to dask's dtype inference failing, and
*may* be fixed by specifying dtypes manually by adding:

{dtype_kw}

to the call to `read_csv`/`read_table`.{extra})table
exceptionsdtype_kwextraz also  c              3      K   | ]	}d |z  V  
dS )z- %sNr2   )r3   r4   s     r,   rm   z coerce_dtypes.<locals>.<genexpr>  s&      77!777777r.   a  The following columns{also}failed to properly parse as dates:

{cols}

This is usually due to an invalid value in that column. To
diagnose and fix it's recommended to drop these columns from the
`parse_dates` keyword, and manually convert them to dates later
using `dd.to_datetime`.)alsocolsz

%s

z=-------------------------------------------------------------z=Mismatched dtypes found in `pd.read_csv`/`pd.read_table`.

%s)r+   r'   r   r   appendr   r   astype	Exceptionjoinr>   r   formatfilterr\   )rO   r'   
bad_dtypes	bad_dateserrorsr4   actualdesiredrl   exr   r   r   r   	dtype_msgr   r   date_msgrulemsgs                       r,   r[   r[      s    JIFZ * *;;29Q<6!944Yq\FQiGf%% **:7*C*C *!!1fg"67777 (( *-DW-M-M *
   ####*qELL33BqEE  * * *%%q&'&:;;;MM1a&))))))))*  # 	  .4VATAT.U.U.U    B(J EEJ=  J,?,?@@@
:::JGG,"3"3 4
 4
-74
 4
 4
 #
 #
 

 &uhe&
T
T 		 	 %.xx3yy77Y77777& &d&
&
& 	  Y x(OIIfTIx#899::
 oo s   .$C
D/DDc
                L   |j                                         }
|                    dg          j        }t	          t
                    r$fd|D             }|                    |          }n|}|D ]}d|
|<   t          |j                  }t          t          |                    }t          t          |                    }t          t          |                    }|r|\  }d |D             }rfd|D             } |j        di |t          j                            t!          j        t%          |          t&                    t)          |                    i}||f}t%          |          rt+          ||          }g }|pd\  }}t-          t%          |                    D ]7}|                    ||         |r||         nd	||         ||         g           8t1          t3          |d	|||| |
||	  	        ||d
t5          | |	||||          dd          S )a  Convert blocks of bytes to a dask.dataframe

    This accepts a list of lists of values of bytes where each list corresponds
    to one file, and the value of bytes concatenate to comprise the entire
    file, in order.

    Parameters
    ----------
    reader : callable
        ``pd.read_csv`` or ``pd.read_table``.
    block_lists : list of lists of delayed values of bytes
        The lists of bytestrings where each list corresponds to one logical file
    header : bytestring
        The header, found at the front of the first file, to be prepended to
        all blocks
    head : pd.DataFrame
        An example Pandas DataFrame to be used for metadata.
    kwargs : dict
        Keyword arguments to pass down to ``reader``
    path : tuple, optional
        A tuple containing column name for path and the path_converter if provided

    Returns
    -------
    A dask.dataframe
    category)includec                    g | ]F}t                              |          t                    r                    |          j        D|GS r    )
isinstancerC   r   rA   )r3   r}   specified_dtypess     r,   r5   z)text_blocks_to_pandas.<locals>.<listcomp>\  s`     
 
 
*..q113CDD
 !$$Q''2>  ?>>r.   c                (    g | ]}|d          j         S )   )rH   )r3   re   s     r,   r5   z)text_blocks_to_pandas.<locals>.<listcomp>s  s    +++q1+++r.   c                &    g | ]} |          S r2   r2   )r3   ppath_converters     r,   r5   z)text_blocks_to_pandas.<locals>.<listcomp>u  s#    6661^^A&&666r.   )dtype)r   )NNNzread-csvFT)metalabeltokenenforce_metadataproduces_tasksr2   )r'   to_dictselect_dtypesr+   r   r   
differencer?   tupler   
block_maskblock_mask_lastr^   r_   r`   ra   rb   zerosrd   intsetr   ranger   r   r   r   )r&   block_listsr%   r$   r)   r(   r   rH   	blocksizeurlpathr'   categoricalsknown_categoricalsunknown_categoricalsr}   r+   blocksrI   rJ   r#   rg   partsir   s         `                @r,   text_blocks_to_pandasr   -  s   L [  ""F %%zl%;;CL"G,, 	,
 
 
 
!
 
 
  ,667IJJ+ "  q		4<  G7;''((FZ,,--HOK0011G  "&++F+++ 	76666666Et{ 
 
22HSYYc222CJJ 
 
 
   G%d1EFFF E)\NGU3v;; X XfQiU!<qhqk7ST:VWWWW 
	
 
	
 	vw$	JJ#   r.   c              #  V   K   | D ]#}|sdV  d |dd         D             E d{V  $dS )z
    Yields a flat iterable of booleans to mark the zeroth elements of the
    nested input ``block_lists`` in a flattened output.

    >>> list(block_mask([[1, 2], [3, 4], [5]]))
    [True, False, True, False, True]
    Tc              3     K   | ]}d V  dS FNr2   r3   r   s     r,   rm   zblock_mask.<locals>.<genexpr>  s"      --aE------r.   r   Nr2   r   rG   s     r,   r   r     sf        . . 	


--59-----------	. .r.   c              #  V   K   | D ]#}|sd |dd         D             E d{V  dV  $dS )z
    Yields a flat iterable of booleans to mark the last element of the
    nested input ``block_lists`` in a flattened output.

    >>> list(block_mask_last([[1, 2], [3, 4], [5]]))
    [False, True, False, True, True]
    c              3     K   | ]}d V  dS r   r2   r   s     r,   rm   z"block_mask_last.<locals>.<genexpr>  s"      ..aE......r.   NTr2   r   s     r,   r   r     se          	..5":..........



	 r.   c                j    d}t          | |z  |z            }t          |t          d                    S )N
   g    A)r   min)total_memory	cpu_countmemory_factorr   s       r,   auto_blocksizer     s4    MLI-=>>Iy#d))$$$r.   c                    d} t           zt                      5  t          dt                     t          j                    j        }t          j                    }d d d            n# 1 swxY w Y   |r|rt          ||          S | S )Ni   ignore)psutilr   r   RuntimeWarningvirtual_memorytotalr   r   )defaultmemcpus      r,   _infer_block_sizer     s    G 	% 	%>222'))/C"$$C	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
  	,3 	,!#s+++Ns   AA%%A),A)r   infer  r   c                   | j         }|t          |          dk    r||d<   nd}|
rt          |
t                    rd}
d|v sd|v r&|                    d          durt          d          d	D ]}||v rt          | d
|           |                    dd           r"t          d                    |                    t          |                    d          t                    r|                    d          x}}n|                    d          dx}}nzt          |                    d                    }t          |          }t          t          t          t          |          dz                       t          |          z
            }t          |                    d          t                    rt          d|           t          |                    d          t                    r,|
r*|                    d                              |
d           }nd }|dk    rRt          |d|	          d         }t          |          dk    rt!          | d          t#          |d                   }|dk    rt$          }t          |t&                    rt)          |          }|r|rt+          d|z             d }|t,          vrt/          d|z            |r|r||k     r|dk    rt+          d           |}|                                }t3          |f|||||
d|	pi }|
r|\  }}}|
|f}n|\  }}d }t          |d         t4          t          f          s|g}|du r5t          |d                   r |d         d                                         }|                    dd           }|                    d|dnd           }|dnd}t          |t                    r||z  }|                    d          rg }|                    |          D ]}|                                                    |                    d                    }t          |          dk    rYt          |d                   dk    r?|                    |d                                                                                    n|                    |           t          |          |k    r nn*|                    |t          ||z   ||z                       }|sdn%t          |          t          |d                    z
  }|dur+|||z   k     r"t          |          |k    rt          d          |d n
||         |z   }|                                 }|!                    d!d            |                    d"          d#k    rd$|d"<   	  | tE          |          fd|i|} n># tF          j$        j%        $ r'}!d%t'          |!          v rt          d&          |! d }!~!ww xY w|
r|
| j&        v rt          d'|
z            |                    d(i           }"|"i }"|r`t          |"t                    rK| j&        D ]C}#tO          | |#         j(                  r'|#|"vr#| |#         )                    tT                    | |#<   Dd) |D             }tW          | ||| |||"|||*
  
        S )+Nr   lineterminatorrj   rH   r]   	index_colFzKeywords 'index' and 'index_col' not supported, except for 'index_col=False'. Use dd.{reader_name}(...).set_index('my-index') instead)iterator	chunksizez not supported for dd.nrowszThe 'nrows' keyword is not supported by `dd.{0}`. To achieve the same behavior, it's recommended to use `dd.{0}(...).head(n=nrows)`r;   r   r%   z)List of header rows not supported for dd.
convertersr   rb)modestorage_options   z resolved to no filesr   zWarning %s compression does not support breaking apart files
Please ensure that each individual file can fit in memory and
use the keyword ``blocksize=None to remove this message``
Setting ``blocksize=None``z#Compression format %s not installedz}Unexpected behavior can result from passing skiprows when
blocksize is smaller than sample size.
Setting ``sample=blocksize``)	delimiterr   samplecompressioninclude_pathr:   commentr   zSample is not large enough to include at least one row of data. Please increase the number of bytes in `sample` in the call to `read_csv`/`read_table`r.   r<   enginepyarrowr4   EOFzEOF encountered while reading header. 
Pass argument `sample_rows` and make sure the value of `sample` is large enough to accommodate that many rows of datazFiles already contain the column name: %s, so the path column cannot use this name. Please set `include_path_column` to a unique name.r   c                &    g | ]}d  |D             S )c                Z    g | ](}t          |j                                                  )S r2   )r?   daskvalues)r3   dsks     r,   r5   z*read_pandas.<locals>.<listcomp>.<listcomp>  s,    8883tCHOO%%&&888r.   r2   )r3   rG   s     r,   r5   zread_pandas.<locals>.<listcomp>  s'    MMMU88%888MMMr.   )r(   r   rH   r   r   ),rQ   rd   r   boolrC   r\   r   r   r   maxr   r   r?   	TypeErrordictr
   OSErrorr   AUTO_BLOCKSIZErq   r   r   r	   NotImplementedErrorencoder   r   computesplitdecoder   striprB   rD   r   r_   r   ParserErrorr+   r   r   r   floatr   )$r&   r   r   r   r   r   sample_rowsr(   assume_missingr   include_path_columnr)   reader_namekwlastskiprowfirstrowr;   r   rg   b_lineterminatorb_outb_sampler   rH   r:   r%   needr   rF   split_commentnpartshead_kwargsr$   rl   r   r4   s$                                       r,   read_pandasr    s     /K!c.&9&9Q&>&>#1   %z*=tDD %$&v&**["9"9"F"FY
 
 	
 ( I I<<GG+GGHHH zz'4   
 $VK00	
 
 	
 &**Z((#.. F!'J!7!77hh	J			'!""hh
 vzz*--..(mms5X!23344s8}}DEE&**X&&-- SQKQQRRR&**\**D11 6I L11556I4PP g"7WWW

 u::??W;;;<<< (a11I"	)S!! +	**	 [ ) ,77	
 	
 	
 	%!"G+"UVVV V 	F 2 2{a7G7G+	
 	
 	

 %,,.."(   b E  "'&%#^4 &fQi%//  5S^^!9Q<''))
 JJw%%EZZU]''EEF11AD&# Fzz) 
NN#344 		 		D KKMM//

90E0EFFM=!!A%%}Q'((1,,LLq!1!7!7!9!9!@!@!B!BCCCT"""5zzD   ! c+"4hoFF
 

 @QQUceBi-.@.@!@FUvd(:::s8}}PV?V?VA
 
 	
 NSSh:J(JF ++--KOOL$'''x  I-- #H	vgh''JJ{JkJJ9    CFF??H  	
 	  
 3t| C C68KL
 
 	
 zz'2.. 0*%5t<< 0 	0 	0AQ.. 01<L3L3Lq'..//QMMfMMMF )   s   W! !X5"XXa  
Read {file_type} files into a Dask.DataFrame

This parallelizes the :func:`pandas.{reader}` function in the following ways:

- It supports loading many files at once using globstrings:

    >>> df = dd.{reader}('myfiles.*.csv')  # doctest: +SKIP

- In some cases it can break up large files:

    >>> df = dd.{reader}('largefile.csv', blocksize=25e6)  # 25MB chunks  # doctest: +SKIP

- It can read CSV files from external resources (e.g. S3, HDFS) by
  providing a URL:

    >>> df = dd.{reader}('s3://bucket/myfiles.*.csv')  # doctest: +SKIP
    >>> df = dd.{reader}('hdfs:///myfiles.*.csv')  # doctest: +SKIP
    >>> df = dd.{reader}('hdfs://namenode.example.com/myfiles.*.csv')  # doctest: +SKIP

Internally ``dd.{reader}`` uses :func:`pandas.{reader}` and supports many of the
same keyword arguments with the same performance guarantees. See the docstring
for :func:`pandas.{reader}` for more information on available keyword arguments.

Parameters
----------
urlpath : string or list
    Absolute or relative filepath(s). Prefix with a protocol like ``s3://``
    to read from alternative filesystems. To read from multiple files you
    can pass a globstring or a list of paths, with the caveat that they
    must all have the same protocol.
blocksize : str, int or None, optional
    Number of bytes by which to cut up larger files. Default value is computed
    based on available physical memory and the number of cores, up to a maximum
    of 64MB. Can be a number like ``64000000`` or a string like ``"64MB"``. If
    ``None``, a single block is used for each file.
sample : int, optional
    Number of bytes to use when determining dtypes
assume_missing : bool, optional
    If True, all integer columns that aren't specified in ``dtype`` are assumed
    to contain missing values, and are converted to floats. Default is False.
storage_options : dict, optional
    Extra options that make sense for a particular storage connection, e.g.
    host, port, username, password, etc.
include_path_column : bool or str, optional
    Whether or not to include the path to each particular file. If True a new
    column is added to the dataframe called ``path``. If str, sets new column
    name. Default is False.
**kwargs
    Extra keyword arguments to forward to :func:`pandas.{reader}`.

Notes
-----
Dask dataframe tries to infer the ``dtype`` of each column by reading a sample
from the start of the file (or of the first file if it's a glob). Usually this
works fine, but if the ``dtype`` is different later in the file (or in other
files) this can cause issues. For example, if all the rows in the sample had
integer dtypes, but later on there was a ``NaN``, then this would error at
compute time. To fix this, you have a few options:

- Provide explicit dtypes for the offending columns using the ``dtype``
  keyword. This is the recommended solution.

- Use the ``assume_missing`` keyword to assume that all columns inferred as
  integers contain missing values, and convert them to floats.

- Increase the size of the sample using the ``sample`` keyword.

It should also be noted that this function may fail if a {file_type} file
includes quoted strings that contain the line terminator. To get around this
you can specify ``blocksize=None`` to not split files into multiple partitions,
at the cost of reduced parallelism.
c                v     	 	 	 	 	 	 	 	 	 d fd	}t                               ||          |_        ||_        |S )	Nr   r   r   r   Fc
                4    t          | f|||||||||	d	|
S )N)	r   r   r   r   r   r(   r   r   r   )r  )r   r   r   r   r   r   r(   r   r   r   r)   r&   s              r,   readzmake_reader.<locals>.read  sN     
  )##)+ 3
 
 
 
 	
r.   )r&   	file_type	r   Nr   r   r   FFNF)READ_DOC_TEMPLATEr   rT   rQ   )r&   r  r  r  s   `   r,   make_readerr    sf     !
 
 
 
 
 
8 %++;)+TTDLDMKr.   pandasread_csv)backendnameCSV
read_table	delimitedread_fwfzfixed-width)	depend_onc                   |5 } | j         |fi | d d d            n# 1 swxY w Y   t          j                            |j                  S r    )to_csvosrH   normpath)rO   filr  r)   fs        r,   
_write_csvr#    s    	 	!v              7CH%%%s   ""utf-8wtc           	     R   |r|t          d          |
|}
n|
s|rt          d          t          d||dd|	pi }t          t          d          |                                 }|rt          |fd|i|} |d	         |fi }d
|v r|n|d
z   }|                    dd                              dd          }t          |fd|i|}dd<   |dd         D ]} ||fd|i}|g}|g}ntt          |f||| j        d|} |d	         |d	         fi g}|
rdd<   |	                    fdt          |dd         |dd                   D                        |r|t                      }|t          d| dt                     |V|                    d          A|                    d          |k    r(t          d| d|                    d                     ||                    d          ||d<   d	dl}t           |j        |i |          S |S )a  
    Store Dask DataFrame to CSV files

    One filename per partition will be created. You can specify the
    filenames in a variety of ways.

    Use a globstring::

    >>> df.to_csv('/path/to/data/export-*.csv')  # doctest: +SKIP

    The * will be replaced by the increasing sequence 0, 1, 2, ...

    ::

        /path/to/data/export-0.csv
        /path/to/data/export-1.csv

    Use a globstring and a ``name_function=`` keyword argument.  The
    name_function function should expect an integer and produce a string.
    Strings produced by name_function must preserve the order of their
    respective partition indices.

    >>> from datetime import date, timedelta
    >>> def name(i):
    ...     return str(date(2015, 1, 1) + i * timedelta(days=1))

    >>> name(0)
    '2015-01-01'
    >>> name(15)
    '2015-01-16'

    >>> df.to_csv('/path/to/data/export-*.csv', name_function=name)  # doctest: +SKIP

    ::

        /path/to/data/export-2015-01-01.csv
        /path/to/data/export-2015-01-02.csv
        ...

    You can also provide an explicit list of paths::

    >>> paths = ['/path/to/data/alice.csv', '/path/to/data/bob.csv', ...]  # doctest: +SKIP
    >>> df.to_csv(paths) # doctest: +SKIP

    You can also provide a directory name:

    >>> df.to_csv('/path/to/data') # doctest: +SKIP

    The files will be numbered 0, 1, 2, (and so on) suffixed with '.part':

    ::

        /path/to/data/0.part
        /path/to/data/1.part

    Parameters
    ----------
    df : dask.DataFrame
        Data to save
    filename : string or list
        Absolute or relative filepath(s). Prefix with a protocol like ``s3://``
        to save to remote filesystems.
    single_file : bool, default False
        Whether to save everything into a single CSV file. Under the
        single file mode, each partition is appended at the end of the
        specified CSV file.
    encoding : string, default 'utf-8'
        A string representing the encoding to use in the output file.
    mode : str, default 'w'
        Python file mode. The default is 'w' (or 'wt'), for writing
        a new file or overwriting an existing file in text mode. 'a'
        (or 'at') will append to an existing file in text mode or
        create a new file if it does not already exist. See :py:func:`open`.
    name_function : callable, default None
        Function accepting an integer (partition index) and producing a
        string to replace the asterisk in the given filename globstring.
        Should preserve the lexicographic order of partitions. Not
        supported when ``single_file`` is True.
    compression : string, optional
        A string representing the compression to use in the output file,
        allowed values are 'gzip', 'bz2', 'xz',
        only used when the first argument is a filename.
    compute : bool, default True
        If True, immediately executes. If False, returns a set of delayed
        objects, which can be computed at a later time.
    storage_options : dict
        Parameters passed on to the backend filesystem class.
    header_first_partition_only : bool, default None
        If set to True, only write the header row in the first output
        file. By default, headers are written to all partitions under
        the multiple file mode (``single_file`` is False) and written
        only once under the single file mode (``single_file`` is True).
        It must be True under the single file mode.
    compute_kwargs : dict, optional
        Options to be passed in to the compute method
    kwargs : dict, optional
        Additional parameters to pass to :meth:`pandas.DataFrame.to_csv`.

    Returns
    -------
    The names of the file written if they were computed right away.
    If not, the delayed tasks associated with writing the files.

    Raises
    ------
    ValueError
        If ``header_first_partition_only`` is set to False or
        ``name_function`` is specified when ``single_file`` is True.

    See Also
    --------
    fsspec.open_files
    Nz9name_function is not supported under the single file modezDheader_first_partition_only cannot be False in the single file mode.rv   )r   encodingnewlineF)purer   r   awrs   r%   r   r  )r   name_functionnumc                *    g | ]\  }} ||fi S r2   r2   )r3   dr"  r)   to_csv_chunks      r,   r5   zto_csv.<locals>.<listcomp>  s1    NNNda\\!Q))&))NNNr.   zThe 'scheduler' keyword argument for `to_csv()` is deprecated andwill be removed in a future version. Please use the `compute_kwargs` argument instead. For example, df.to_csv(..., compute_kwargs={scheduler: z})	schedulerzJDiffering values for 'scheduler' have been passed in.
scheduler argument: z
via compute_kwargs: r2   )r\   r   r   r#  
to_delayed	open_filereplacer   npartitionsextendzipr   FutureWarningrC   r   r?   r   )rO   filenamesingle_filer'  r   r,  r   r   r1  r   header_first_partition_onlycompute_kwargsr)   file_optionsdfs
first_filevalueappend_modeappend_filer/  r   filesr   r0  s               `          @r,   r  r    sd   @  V}0TUUU"*&1##( 
[ 
R
 
 	
     b	 L :E222L
--//C 
xCCdClCC
SVZ::6::!Tkkddtcz!))#r22::3CCKK{KlKK xQRR 	L 	LA LKKK5KFKKEE
'	
 

 
 
 ,s1vuQx::6::;& 	%$F8NNNNNc#abb'596M6MNNN	
 	
 	
  !!VVN Z LUZ Z Z    !"";//;"";//9<<I'0I I'5'9'9+'F'FI I    ^%7%7%D%D%L*3N;'LDL&;N;;<<<r.   )_Frame)NNTFN)FNNNNr  )
Fr$  r%  NNTNNNN)H
__future__r   r  collections.abcr   ior   warningsr   r   r   r   ImportErrornumpyrb   r  r_   fsspec.compressionr	   fsspec.corer
   r   r3  r   fsspec.utilsr   pandas.api.typesr   r   r   r   r   	dask.baser   
dask.bytesr   	dask.corer   dask.dataframe.backendsr   dask.dataframe.io.ior   dask.dataframe.io.utilsr   dask.dataframe.utilsr   dask.delayedr   
dask.utilsr   r   r   rE   r[   r   r   r   r   r   r   r  r  r  register_inplacer  r  r  r#  r  dask.dataframe.corerD  rT   r2   r.   r,   <module>rZ     s   " " " " " " 				 # # # # # #       7 7 7 7 7 7 7 7 7 7MMMM   FFF         $ $ $ $ $ $ * * * * * * ) ) ) ) ) ) " " " " " " * * * * * *                    ! ! ! ! ! !       ? ? ? ? ? ? ) ) ) ) ) ) 7 7 7 7 7 7 7 7 7 7 7 7             . . . . . . . .t t t t t, t t tx 	1 1 1 1hX X XB 	n n n nb. . .  % % %   #"$$ K K K K\H V  D7&7	   +bk:u--/ / [kBB
;r{J>> &* & & & & & 	 $H H H HV ' & & & & &   s   ' 11