
    tf                       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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	 	 	 	 	 d-dZ4d Z5	 	 	 	 	 d.dZ6d Z7d Z8d Z9d Z: e:       Z;	 	 	 	 	 	 	 	 	 d/dZ<dZ=d  Z>  e'j~                  d!d"#       e>ej                  d"d$            Z@ e>ej                  d%d&      ZA e>ej                  d'd(      ZBdd)d*ZC	 	 	 	 	 	 	 	 	 	 d0d+ZDd d,lEmFZF eDj                  eFj                  _G        y# e$ r dZY Ew xY w)1    )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                  2    e Zd ZdZd Zed        Zd Zd Zy)CSVFunctionWrapperzg
    CSV Function-Wrapper Class
    Reads CSV data from disk to produce a partition (given a key).
    c
                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y N)	full_columns_columnscolnameheadheaderreaderdtypesenforcekwargs)
selfr!   columnsr#   r$   r%   r&   r'   r(   r)   s
             _/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/dask/dataframe/io/csv.py__init__zCSVFunctionWrapper.__init__-   sD     )	    c                    | j                   | j                  S | j                  r| j                   | j                  gz   S | j                   S r    )r"   r!   r#   )r*   s    r,   r+   zCSVFunctionWrapper.columnsC   s>    == $$$<<==DLL>11}}r.   c                   | j                   j                  D cg c]	  }||v s| }}|| j                  k(  r| S | j                  r,| j                  |vr| j                   || j                  gz      }n| j                   |   }t        | j                  || j                  || j
                  | j                  |D ci c]  }|| j                  |    c}| j                  | j                  	      S c c}w c c}w )zUReturn a new CSVFunctionWrapper object with
        a sub-column projection.
        )
r$   r+   r#   r   r!   r%   r&   r'   r(   r)   )r*   r+   cr$   s       r,   project_columnsz"CSVFunctionWrapper.project_columnsK   s    
 #ii//@1<1@@dll"K<<DLL7 99W~56D99W%D!LLKKKK(/01QA0LLKK

 
	
 A  1s   	C,C,8C1c                   |\  }}}}|M| j                   |t        t        | j                  | j                      j                  j
                              f}nd }d}| j                  j                         }|sJ|j                  dd       d}|j                  dd        |j                  dd      |j                  dd        |s|j                  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   sU   )-&tXw tDIIdll377BBCDI I kk&&(w-5#OOJ-x+7$/OOL$/ ##"==${{ &*"--)0I& KKKKKKLL

 dll##	r.   N)	__name__
__module____qualname____doc__r-   propertyr+   r2   rJ    r.   r,   r   r   '   s*    
,  
46r.   r   c	                8   t               }	|r0|j                  |j                               s|	j                  |       |	j                  |       |	j	                  d        | |	fi |}
|rt        |
|       |r:|r8t        |
j                        t        |      k7  rt        d|
j                  |      |rf|\  }}}|j                  |      } |
j                  di |t        j                  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 matchrP   )r   
startswithrstripwriteseekcoerce_dtypesr9   r+   
ValueErrorindexassignpdCategorical
from_codesnpfulllen)r&   br%   r)   r'   r+   rF   r(   rB   biorI   r#   pathscodes                 r,   r?   r?      s    @ )CALL9		&IIaLHHQK		v	Bb&!7RZZ 0DM A/WEE#u{{4 RYY 
11"''#b'42H%PQ
 Ir.   c                   g }g }g }| j                   D ]  }||v s| j                  |   ||   k7  s| j                  |   }||   }t        |      r t        |      r|j	                  |||f       ]t        |      rt        |      r|j	                  |       	 | |   j                  ||         | |<    |r|r,dj                  d t        |d       D              }	d|	z  }
d}nd}
d}t        |d	       }t        g d
|      }ddj                  d |D              z  }dj                  ||
||      }nd}|r2|rdnd}dj                  d |D              }dj                  ||      }nd}|s|r0ddz  }d|j                  t        d||g            z  }t        |      y# t        $ r2}|j	                  |||f       |j	                  ||f       Y d}~d}~ww xY w)zCoerce dataframe to dtypes safely

    Operates in place

    Parameters
    ----------
    df: Pandas DataFrame
    dtypes: dict like {'x': float}
    N
c              3  2   K   | ]  \  }}d | d|  yw)z- z
  NrP   ).0r1   es      r,   	<genexpr>z coerce_dtypes.<locals>.<genexpr>   s&      &*a"QCtA5!s   c                    t        | d         S Nr   strxs    r,   <lambda>zcoerce_dtypes.<locals>.<lambda>   s    3qQRt9 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 rk   rl   rn   s    r,   rp   zcoerce_dtypes.<locals>.<lambda>  s    c!A$i r.   )ColumnFoundExpectedz
dtype={%s}z	,
       c              3  4   K   | ]  \  }}}|d | d  yw)z: ''NrP   )rg   kv_s       r,   ri   z coerce_dtypes.<locals>.<genexpr>  s'      4
 )Aqqe3qcO4
s   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    yw)z- %sNrP   )rg   r1   s     r,   ri   z coerce_dtypes.<locals>.<genexpr>  s     7!7s   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joinr8   r   formatfilterrW   )rI   r'   
bad_dtypes	bad_dateserrorsr1   actualdesiredrh   exr}   r   r|   r~   	dtype_msgr   r   date_msgrulemsgs                       r,   rV   rV      s-    JIFZZ *;299Q<6!94YYq\FQiGf%*:7*C!!1fg"67 (-DW-M
   #*qELL3BqE*&  .4VAT.U B(J EJ=  J,?@
:JG,"3"3 4
-74
 #
 

 &uhe&
T 	 	%x3yy7Y77& &d&
& 	 Yx(OIIfTIx#89:
 o o ! *%%q&'&:;MM1a&))*s   F##	G,'GGc
                |   |j                   j                         }
|j                  dg      j                  }t	        |t
              r[|D cg c]>  }t	        |j                  |      t              r|j                  |      j                  |@ }}|j                  |      }n|}|D ]  }d|
|<   	 t        |j                        }t        t        |            }t        t        |            }t        t        |            }|r|\  }}|D cg c]  }|d   j                   }}|r|D cg c]
  } ||       }} |j                   di |t"        j$                  j'                  t)        j*                  t-        |      t.              t1        |            i}||f}t-        |      rt3        ||      }g }|xs d\  }}t5        t-        |            D ]'  }|j7                  ||   |r||   nd||   ||   g       ) t9        t;        |d|||| |
||	      ||dt=        | |	||||      d	d
      S c c}w c c}w c c}w )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)includeN   )dtype)r   )NNzread-csvFT)metalabeltokenenforce_metadataproduces_tasksrP   )r'   to_dictselect_dtypesr+   
isinstancer   r=   r   r;   
differencer9   tupler   
block_maskblock_mask_lastrB   rY   rZ   r[   r\   r]   zerosr_   intsetr   ranger   r   r   r   )r&   block_listsr%   r$   r)   r(   specified_dtypesrB   	blocksizeurlpathr'   categoricalsry   known_categoricalsunknown_categoricalsr+   blocksrC   rD   r#   path_converterr`   rb   ppartsis                             r,   text_blocks_to_pandasr   -  se   L [[  "F %%zl%;CCL"G, "
*..q13CD $$Q'22> 
 
  ,667IJ+ " q	 4<< G7;'(FZ,-HOK01G"&$*+q1++0561^A&6E6t{{ 
22HHSYc2CJ
 
 %d1EF E)\NGU3v; XfQiUqhqk7ST:VWX 
	
 	vw$	J# [
. ,6s   AH/H4+H9c              #  T   K   | D ]  }|sd d |dd D        E d{     y7 w)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   ywFNrP   rg   r{   s     r,   ri   zblock_mask.<locals>.<genexpr>  s     -aE-   r   NrP   r   rA   s     r,   r   r     s;       .
-59---	. 	.s   (&(c              #  T   K   | D ]  }|sd |dd D        E d{    d  y7 w)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   ywr   rP   r   s     r,   ri   z"block_mask_last.<locals>.<genexpr>  s     .aE.r   NTrP   r   s     r,   r   r     s;       .5":...
	 	/s   (&(c                R    d}t        | |z  |z        }t        |t        d            S )N
   g    A)r   min)total_memory	cpu_countmemory_factorr   s       r,   auto_blocksizer     s,    MLI-=>Iy#d)$$r.   c                     d} t         et               5  t        dt               t        j                         j
                  }t        j                         }d d d        rrt        ||      S | S # 1 sw Y   xY w)Ni   ignore)psutilr   r   RuntimeWarningvirtual_memorytotalr   r   )defaultmemcpus      r,   _infer_block_sizer     sm    G 	%>2'')//C""$C	%
 3!#s++N	% 	%s   AA00A9c                <   | j                   }|t        |      dk(  r||d<   nd}d|v r9|j                  |d         }dj                  |d         }|r|t        |      d  }n|j                         }|
rt        |
t              rd}
d|v sd|v r|j                  d      d	urt        d
      dD ]  }||v st        | d|        |j                  dd       rt        dj                  |            t        |j                  d      t              r|j                  d      x}}np|j                  d      dx}}nZt        |j                  d            }t        |      }t        t        t        t        |      dz               t        |      z
        }t        |j                  d      t              rt        d|       t        |j                  d      t              r$|
r"|j                  d      j                  |
d       }nd }|dk(  r;t!        |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t1        d|z        |r|r||k  r|dk7  rt-        d       |}t3        |f|||||
d|	xs i }|
r|\  }}}|
|f}n|\  }}d }t        |d   t4        t        f      s|g}|d	u r$t        |d         r|d   d   j7                         }|j                  dd       }|j                  d|dnd       }|dnd}t        |t              r||z  }|j                  d      rg }|j9                  |      D ]  }|j;                         j9                  |j                  d            }t        |      dkD  rBt        |d         dkD  rB|j=                  |d   j?                         j                                n|j=                  |       t        |      |kD  s n$ n"|j9                  |t        ||z   ||z               }|sdnt        |      t        |d           z
  }|d	ur!|||z   k  rt        |      |k\  rt        d!      |d"n||   |z   }|jA                         } | jC                  d#d        | j                  d$      d%k(  rd&| d$<   	  | tE        |      fd|i| }!|
r|
|!jL                  v rt        d)|
z        |j                  d*i       }#|#i }#|rZt        |#t              rJ|!jL                  D ];  }$tO        |!|$   jP                        s|$|#vs!|!|$   jS                  tT              |!|$<   = |D %&cg c]3  }%|%D &cg c]%  }&t        |&jV                  jY                               ' c}&5 }}%}&t[        | |||!|||#|||+
      S # tF        jH                  jJ                  $ r}"d't)        |"      v rt        d(      |" d }"~"ww xY wc c}&w c c}&}%w ),Nr   lineterminatorre   encodingrr   rB   rX   	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)`r5   r   r%   z)List of header rows not supported for dd.
convertersinfer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_pathr4   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.   r6   enginepyarrowr1   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   )r(   r   rB   r   r   ).rK   r_   encoder   boolr=   rW   r   r   r   maxr   r   r9   	TypeErrordictr
   OSErrorr   AUTO_BLOCKSIZErm   r   r   r	   NotImplementedErrorr   r   computesplitdecoder   stripr<   r>   r   rZ   r   ParserErrorr+   r   r   r   floatdaskvaluesr   )'r&   r   r   r   r   r   sample_rowsr(   assume_missingr   include_path_columnr)   reader_nameb_lineterminator
empty_blobkwlastskiprowfirstrowr5   r   rb   b_outb_sampler   rB   r4   r%   needr   r@   split_commentnpartshead_kwargsr$   rh   r   r1   rA   dsks'                                          r,   read_pandasr    s    //K!c.&9Q&>#1 V)00
1CDYYvj12
  0J0AB)002z*=tD$&v&**["9"FY
 	
 ( I<t#9+GHHI zz'4  $VK0	
 	
 &**Z(#.!'J!77h	J		'!""h
 vzz*-.(ms5X!234s8}DE&**X&-CK=QRR&**\*D16IL1556I4P g"7W

 u:?WI%:;<< (a1I"	)S!	*	[) ,77	
 	%!"G+"UVVV	F 2{a7G+	

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

90EFM=!A%}Q'(1,LLq!1!7!7!9!@!@!BCT"5zD 		 c+"4hoF

 QUceBi-.@!@FUvd(::s8}PV?VA
 	
 NSh:J(JF ++-KOOL$'x I- #H	gh'J{JkJ  3t|| C68KL
 	
 zz'2.*%5t< 	0AQ.1<L3Lq'../Q	0 GMMU%83tCHHOO%&8MFM ) 7 99   CF?H 	
 	2 9Ms0   W 	X*X7XX1X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                l     	 	 	 	 	 	 	 	 	 d fd	}t         j                  ||      |_        ||_        |S )Nc
                2    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  sD     
  )##)+ 3
 
 	
r.   )r&   	file_type	r   Nr   i  r   FFNF)READ_DOC_TEMPLATEr   rN   rK   )r&   r   r	  r  s   `   r,   make_readerr    sJ     !
8 %++;)+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        t        j                  j                  |j                        S # 1 sw Y   2xY wr    )to_csvosrB   normpath)rI   filr  r)   fs        r,   
_write_csvr  !  sH    	 		!v77CHH%% s   AAc                   |r|t        d      |
|}
n|
s|rt        d      t        d||dd|	xs i }t        t        d      }| j	                         }|rxt        |fd|i|} ||d	   |fi |}d
|v r|n|d
z   }|j                  dd      j                  dd      }t        |fd|i|}d|d<   |dd D ]  } |||fd|i|} |g}|g}nnt        |f||| j                  d|} ||d	   |d	   fi |g}|
rd|d<   |j                  t        |dd |dd       D cg c]  \  }} |||fi | c}}       |r|
t               }|t        d| dt               |E|j                  d      4|j                  d      |k7  r t        d| d|j                  d             ||j                  d      ||d<   d	dl}t         |j                   |i |      S |S c c}}w )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.rr   )r   r   newlineF)purer   r   awro   r%   r   r  )r   name_functionnumzThe '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: rP   )rW   r   r   r  
to_delayed	open_filereplacer   npartitionsextendzipr   FutureWarningr=   r   r9   r   )rI   filenamesingle_filer   r   r"  r   r   r$  r   header_first_partition_onlycompute_kwargsr)   file_optionsto_csv_chunkdfs
first_filevalueappend_modeappend_filedr   filesr  r   s                            r,   r  r  '  s   @ }0TUU"*&1#([R
 	
    b	L :E2L
--/CxCdClC
SVZ:6:!Tkdtcz!))#r2::3CK{KlK xQR 	LA KK5KFKE	L
'	

 
 s1vuQx:6:;&$F869#ab'596MNda\!Q)&)N	
 !!VN K LU+UXZ  !"";/;"";/9<''0k 2''5'9'9+'F&GI   ^%7%7%D%L*3N;'LDLL&;N;<<C Os   $G$
)_Frame)NNTFN)FNNNNr
  )
Fzutf-8wtNNTNNNN)H
__future__r   r  collections.abcr   ior   warningsr   r   r   r   ImportErrornumpyr]   r  rZ   fsspec.compressionr	   fsspec.corer
   r   r&  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   r?   rV   r   r   r   r   r   r   r  r  r  register_inplacer  r  r  r  r  dask.dataframe.corer9  rN   rP   r.   r,   <module>rP     s   " 	 #  7 7   $ * ) " *   !  ? ) 7 7   .t, tx 	1hXB 	nb.% #$ SlH VD7&77	 bkk:u-/ kB
r{{J> &* & 	 $HV ' U  Fs   E! !E,+E,