HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/io/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/io/__pycache__/parsers.cpython-36.pyc
3

���h��1@s
UdZddlmZmZddlZddlZddlmZmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZmZmZddlZddlZddljjZddljjZddljj Z ddlm!Z!ddl"m#Z#dd	l$m%Z%m&Z&dd
l'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/dd
l0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLmMZMmNZNmOZOddlPmQZQddlRmSZTddlUmVZVmWZWmXZXmYZYddlZm[Z[dZ\de
dj]e^e!��ddd�dZ_dsdd �Z`d!d"�Zae%d#�d$d%�Zbddd&ejcd'd(dd)dddddddd'ddddd'ddd*d(d(d(dddd(dd(dd'd(d'd+�%Zdd(d'd'd(d'd'dd,�Zed)d-dd.�Zfd/hZgd0d1hZhiZieejefiek�Zleejle-e_jmd2d3d4d5��d6dd)dddd(dd'dddddd(ddddd'd'd(d'd(d(d(dd(d'd(dd)dd*dd&ejcd'ddddd'd'd(eed0d(df0e%ejd7�d8d2��Zne-e_jmd9d:d;d5��d<dd)dddd(dd'dddddd(ddddd'd'd(d'd(d(d(dd(d'd(dd)dd*dd&ejcd'ddddd'd'd(eed0d(df0e%ejd7�d=d9��Zodte%d#�d>d?�ZpGd@dA�dAejq�ZrdBdC�Zsduee&eteeufdD�dEdF�ZvdGdH�ZwdIdJ�ZxdKdL�ZydMdN�ZzdOdP�Z{GdQdR�dR�Z|GdSdT�dTe|�Z}dUdV�Z~dWdX�ZGdYdZ�dZe|�Z�dvd[d\�Z�dwd]d^�Z�d_d`�Z�dxdadb�Z�dcdd�Z�dydedf�Z�dgdh�Z�didj�Z�dkdl�Z�dmdn�Z�Gdodp�dpejq�Z�Gdqdr�dre��Z�dS)zzM
Module contains tools for processing files into DataFrames or other objects
�)�abc�defaultdictN)�StringIO�
TextIOWrapper)�fill)�Any�Dict�Iterable�List�Optional�Sequence�Set)�
STR_NA_VALUES)�parsing)�FilePathOrBuffer�Union)�AbstractMethodError�EmptyDataError�ParserError�
ParserWarning)�Appender)�astype_nansafe)�
ensure_object�
ensure_str�
is_bool_dtype�is_categorical_dtype�is_dict_like�is_dtype_equal�is_extension_array_dtype�is_file_like�is_float�
is_integer�is_integer_dtype�is_list_like�is_object_dtype�	is_scalar�is_string_dtype�pandas_dtype)�CategoricalDtype)�isna)�
algorithms)�Categorical)�	DataFrame)�Index�
MultiIndex�
RangeIndex�ensure_index_from_sequences)�Series)�	datetimes)�get_filepath_or_buffer�
get_handle�infer_compression�validate_header_arg)�generic_parserua�
{summary}

Also supports optionally iterating or breaking of the file
into chunks.

Additional help can be found in the online docs for
`IO Tools <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html>`_.

Parameters
----------
filepath_or_buffer : str, path object or file-like object
    Any valid string path is acceptable. The string could be a URL. Valid
    URL schemes include http, ftp, s3, gs, and file. For file URLs, a host is
    expected. A local file could be: file://localhost/path/to/table.csv.

    If you want to pass in a path object, pandas accepts any ``os.PathLike``.

    By file-like object, we refer to objects with a ``read()`` method, such as
    a file handler (e.g. via builtin ``open`` function) or ``StringIO``.
sep : str, default {_default_sep}
    Delimiter to use. If sep is None, the C engine cannot automatically detect
    the separator, but the Python parsing engine can, meaning the latter will
    be used and automatically detect the separator by Python's builtin sniffer
    tool, ``csv.Sniffer``. In addition, separators longer than 1 character and
    different from ``'\s+'`` will be interpreted as regular expressions and
    will also force the use of the Python parsing engine. Note that regex
    delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``.
delimiter : str, default ``None``
    Alias for sep.
header : int, list of int, default 'infer'
    Row number(s) to use as the column names, and the start of the
    data.  Default behavior is to infer the column names: if no names
    are passed the behavior is identical to ``header=0`` and column
    names are inferred from the first line of the file, if column
    names are passed explicitly then the behavior is identical to
    ``header=None``. Explicitly pass ``header=0`` to be able to
    replace existing names. The header can be a list of integers that
    specify row locations for a multi-index on the columns
    e.g. [0,1,3]. Intervening rows that are not specified will be
    skipped (e.g. 2 in this example is skipped). Note that this
    parameter ignores commented lines and empty lines if
    ``skip_blank_lines=True``, so ``header=0`` denotes the first line of
    data rather than the first line of the file.
names : array-like, optional
    List of column names to use. If the file contains a header row,
    then you should explicitly pass ``header=0`` to override the column names.
    Duplicates in this list are not allowed.
index_col : int, str, sequence of int / str, or False, default ``None``
  Column(s) to use as the row labels of the ``DataFrame``, either given as
  string name or column index. If a sequence of int / str is given, a
  MultiIndex is used.

  Note: ``index_col=False`` can be used to force pandas to *not* use the first
  column as the index, e.g. when you have a malformed file with delimiters at
  the end of each line.
usecols : list-like or callable, optional
    Return a subset of the columns. If list-like, all elements must either
    be positional (i.e. integer indices into the document columns) or strings
    that correspond to column names provided either by the user in `names` or
    inferred from the document header row(s). For example, a valid list-like
    `usecols` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``.
    Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``.
    To instantiate a DataFrame from ``data`` with element order preserved use
    ``pd.read_csv(data, usecols=['foo', 'bar'])[['foo', 'bar']]`` for columns
    in ``['foo', 'bar']`` order or
    ``pd.read_csv(data, usecols=['foo', 'bar'])[['bar', 'foo']]``
    for ``['bar', 'foo']`` order.

    If callable, the callable function will be evaluated against the column
    names, returning names where the callable function evaluates to True. An
    example of a valid callable argument would be ``lambda x: x.upper() in
    ['AAA', 'BBB', 'DDD']``. Using this parameter results in much faster
    parsing time and lower memory usage.
squeeze : bool, default False
    If the parsed data only contains one column then return a Series.
prefix : str, optional
    Prefix to add to column numbers when no header, e.g. 'X' for X0, X1, ...
mangle_dupe_cols : bool, default True
    Duplicate columns will be specified as 'X', 'X.1', ...'X.N', rather than
    'X'...'X'. Passing in False will cause data to be overwritten if there
    are duplicate names in the columns.
dtype : Type name or dict of column -> type, optional
    Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32,
    'c': 'Int64'}}
    Use `str` or `object` together with suitable `na_values` settings
    to preserve and not interpret dtype.
    If converters are specified, they will be applied INSTEAD
    of dtype conversion.
engine : {{'c', 'python'}}, optional
    Parser engine to use. The C engine is faster while the python engine is
    currently more feature-complete.
converters : dict, optional
    Dict of functions for converting values in certain columns. Keys can either
    be integers or column labels.
true_values : list, optional
    Values to consider as True.
false_values : list, optional
    Values to consider as False.
skipinitialspace : bool, default False
    Skip spaces after delimiter.
skiprows : list-like, int or callable, optional
    Line numbers to skip (0-indexed) or number of lines to skip (int)
    at the start of the file.

    If callable, the callable function will be evaluated against the row
    indices, returning True if the row should be skipped and False otherwise.
    An example of a valid callable argument would be ``lambda x: x in [0, 2]``.
skipfooter : int, default 0
    Number of lines at bottom of file to skip (Unsupported with engine='c').
nrows : int, optional
    Number of rows of file to read. Useful for reading pieces of large files.
na_values : scalar, str, list-like, or dict, optional
    Additional strings to recognize as NA/NaN. If dict passed, specific
    per-column NA values.  By default the following values are interpreted as
    NaN: 'z', '�Fz    )�subsequent_indenta"'.
keep_default_na : bool, default True
    Whether or not to include the default NaN values when parsing the data.
    Depending on whether `na_values` is passed in, the behavior is as follows:

    * If `keep_default_na` is True, and `na_values` are specified, `na_values`
      is appended to the default NaN values used for parsing.
    * If `keep_default_na` is True, and `na_values` are not specified, only
      the default NaN values are used for parsing.
    * If `keep_default_na` is False, and `na_values` are specified, only
      the NaN values specified `na_values` are used for parsing.
    * If `keep_default_na` is False, and `na_values` are not specified, no
      strings will be parsed as NaN.

    Note that if `na_filter` is passed in as False, the `keep_default_na` and
    `na_values` parameters will be ignored.
na_filter : bool, default True
    Detect missing value markers (empty strings and the value of na_values). In
    data without any NAs, passing na_filter=False can improve the performance
    of reading a large file.
verbose : bool, default False
    Indicate number of NA values placed in non-numeric columns.
skip_blank_lines : bool, default True
    If True, skip over blank lines rather than interpreting as NaN values.
parse_dates : bool or list of int or names or list of lists or dict, default False
    The behavior is as follows:

    * boolean. If True -> try parsing the index.
    * list of int or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3
      each as a separate date column.
    * list of lists. e.g.  If [[1, 3]] -> combine columns 1 and 3 and parse as
      a single date column.
    * dict, e.g. {{'foo' : [1, 3]}} -> parse columns 1, 3 as date and call
      result 'foo'

    If a column or index cannot be represented as an array of datetimes,
    say because of an unparseable value or a mixture of timezones, the column
    or index will be returned unaltered as an object data type. For
    non-standard datetime parsing, use ``pd.to_datetime`` after
    ``pd.read_csv``. To parse an index or column with a mixture of timezones,
    specify ``date_parser`` to be a partially-applied
    :func:`pandas.to_datetime` with ``utc=True``. See
    :ref:`io.csv.mixed_timezones` for more.

    Note: A fast-path exists for iso8601-formatted dates.
infer_datetime_format : bool, default False
    If True and `parse_dates` is enabled, pandas will attempt to infer the
    format of the datetime strings in the columns, and if it can be inferred,
    switch to a faster method of parsing them. In some cases this can increase
    the parsing speed by 5-10x.
keep_date_col : bool, default False
    If True and `parse_dates` specifies combining multiple columns then
    keep the original columns.
date_parser : function, optional
    Function to use for converting a sequence of string columns to an array of
    datetime instances. The default uses ``dateutil.parser.parser`` to do the
    conversion. Pandas will try to call `date_parser` in three different ways,
    advancing to the next if an exception occurs: 1) Pass one or more arrays
    (as defined by `parse_dates`) as arguments; 2) concatenate (row-wise) the
    string values from the columns defined by `parse_dates` into a single array
    and pass that; and 3) call `date_parser` once for each row using one or
    more strings (corresponding to the columns defined by `parse_dates`) as
    arguments.
dayfirst : bool, default False
    DD/MM format dates, international and European format.
cache_dates : bool, default True
    If True, use a cache of unique, converted dates to apply the datetime
    conversion. May produce significant speed-up when parsing duplicate
    date strings, especially ones with timezone offsets.

    .. versionadded:: 0.25.0
iterator : bool, default False
    Return TextFileReader object for iteration or getting chunks with
    ``get_chunk()``.
chunksize : int, optional
    Return TextFileReader object for iteration.
    See the `IO Tools docs
    <https://pandas.pydata.org/pandas-docs/stable/io.html#io-chunking>`_
    for more information on ``iterator`` and ``chunksize``.
compression : {{'infer', 'gzip', 'bz2', 'zip', 'xz', None}}, default 'infer'
    For on-the-fly decompression of on-disk data. If 'infer' and
    `filepath_or_buffer` is path-like, then detect compression from the
    following extensions: '.gz', '.bz2', '.zip', or '.xz' (otherwise no
    decompression). If using 'zip', the ZIP file must contain only one data
    file to be read in. Set to None for no decompression.
thousands : str, optional
    Thousands separator.
decimal : str, default '.'
    Character to recognize as decimal point (e.g. use ',' for European data).
lineterminator : str (length 1), optional
    Character to break file into lines. Only valid with C parser.
quotechar : str (length 1), optional
    The character used to denote the start and end of a quoted item. Quoted
    items can include the delimiter and it will be ignored.
quoting : int or csv.QUOTE_* instance, default 0
    Control field quoting behavior per ``csv.QUOTE_*`` constants. Use one of
    QUOTE_MINIMAL (0), QUOTE_ALL (1), QUOTE_NONNUMERIC (2) or QUOTE_NONE (3).
doublequote : bool, default ``True``
   When quotechar is specified and quoting is not ``QUOTE_NONE``, indicate
   whether or not to interpret two consecutive quotechar elements INSIDE a
   field as a single ``quotechar`` element.
escapechar : str (length 1), optional
    One-character string used to escape other characters.
comment : str, optional
    Indicates remainder of line should not be parsed. If found at the beginning
    of a line, the line will be ignored altogether. This parameter must be a
    single character. Like empty lines (as long as ``skip_blank_lines=True``),
    fully commented lines are ignored by the parameter `header` but not by
    `skiprows`. For example, if ``comment='#'``, parsing
    ``#empty\na,b,c\n1,2,3`` with ``header=0`` will result in 'a,b,c' being
    treated as the header.
encoding : str, optional
    Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python
    standard encodings
    <https://docs.python.org/3/library/codecs.html#standard-encodings>`_ .
dialect : str or csv.Dialect, optional
    If provided, this parameter will override values (default or not) for the
    following parameters: `delimiter`, `doublequote`, `escapechar`,
    `skipinitialspace`, `quotechar`, and `quoting`. If it is necessary to
    override values, a ParserWarning will be issued. See csv.Dialect
    documentation for more details.
error_bad_lines : bool, default True
    Lines with too many fields (e.g. a csv line with too many commas) will by
    default cause an exception to be raised, and no DataFrame will be returned.
    If False, then these "bad lines" will dropped from the DataFrame that is
    returned.
warn_bad_lines : bool, default True
    If error_bad_lines is False, and warn_bad_lines is True, a warning for each
    "bad line" will be output.
delim_whitespace : bool, default False
    Specifies whether or not whitespace (e.g. ``' '`` or ``'	'``) will be
    used as the sep. Equivalent to setting ``sep='\s+'``. If this option
    is set to True, nothing should be passed in for the ``delimiter``
    parameter.
low_memory : bool, default True
    Internally process the file in chunks, resulting in lower memory use
    while parsing, but possibly mixed type inference.  To ensure no mixed
    types either set False, or specify the type with the `dtype` parameter.
    Note that the entire file is read into a single DataFrame regardless,
    use the `chunksize` or `iterator` parameter to return the data in chunks.
    (Only valid with C parser).
memory_map : bool, default False
    If a filepath is provided for `filepath_or_buffer`, map the file object
    directly onto memory and access the data directly from there. Using this
    option can improve performance because there is no longer any I/O overhead.
float_precision : str, optional
    Specifies which converter the C engine should use for floating-point
    values. The options are `None` for the ordinary converter,
    `high` for the high-precision converter, and `round_trip` for the
    round-trip converter.

Returns
-------
DataFrame or TextParser
    A comma-separated values (csv) file is returned as two-dimensional
    data structure with labeled axes.

See Also
--------
DataFrame.to_csv : Write DataFrame to a comma-separated values (csv) file.
read_csv : Read a comma-separated values (csv) file into DataFrame.
read_fwf : Read a table of fixed-width formatted lines into DataFrame.

Examples
--------
>>> pd.{func_name}('data.csv')  # doctest: +SKIP
cCs^d|d�d|d��}|dk	rZt|�rBt|�|kr8t|��t|�}nt|�oP||ksZt|��|S)a�
    Checks whether the 'name' parameter for parsing is either
    an integer OR float that can SAFELY be cast to an integer
    without losing accuracy. Raises a ValueError if that is
    not the case.

    Parameters
    ----------
    name : string
        Parameter name (used for error reporting)
    val : int or float
        The value to check
    min_val : int
        Minimum allowed value (val < min_val will result in a ValueError)
    �'�sz' must be an integer >=�dN)r �int�
ValueErrorr!)�name�valZmin_val�msg�rB�3/tmp/pip-build-5_djhm0z/pandas/pandas/io/parsers.py�_validate_integerqs
rDcCsH|dk	rDt|�tt|��kr$td��t|dd�p:t|tj�sDtd��dS)aZ
    Raise ValueError if the `names` parameter contains duplicates or has an
    invalid data type.

    Parameters
    ----------
    names : array-like or None
        An array containing a list of the names used for the output DataFrame.

    Raises
    ------
    ValueError
        If names are not unique or are not ordered (e.g. set).
    Nz Duplicate names are not allowed.F)Z
allow_setsz&Names should be an ordered collection.)�len�setr>r#�
isinstancer�KeysView)�namesrBrBrC�_validate_names�s
rJ)�filepath_or_buffercCs"|jdd�}|dk	r.tjdd|�j�}||d<|jdd�}t||�}t|||�\}}}}||d<|jdd�dk	r�t|dt�r�d	|d<|jd
d�}td|jdd�d
�}|jdd�}	t	|jdd��t
|f|�}
|s�|r�|
Sz|
j|	�}Wd|
j�X|�ry|j�Wnt
k
�rYnX|S)zGeneric reader of line files.�encodingN�_�-�compression�infer�date_parser�parse_datesT�iteratorF�	chunksize��nrowsrI)�get�re�sub�lowerr5r3rG�boolrDrJ�TextFileReader�read�closer>)rK�kwdsrLrOZ	fp_or_bufrMZshould_closerSrTrV�parser�datarBrBrC�_read�s8

rb�"TFrP�.)%�	delimiter�
escapechar�	quotechar�quoting�doublequote�skipinitialspace�lineterminator�header�	index_colrI�prefix�skiprows�
skipfooterrV�	na_values�keep_default_na�true_values�false_values�
converters�dtype�cache_dates�	thousands�comment�decimalrR�
keep_date_col�dayfirstrQ�usecolsrT�verboserL�squeezerO�mangle_dupe_cols�infer_datetime_format�skip_blank_lines)�delim_whitespace�	na_filter�
low_memory�
memory_map�error_bad_lines�warn_bad_lines�float_precision�d)�colspecs�infer_nrows�widthsrpr�r��read_csvz8Read a comma-separated values (csv) file into DataFrame.z',')�	func_name�summaryZ_default_sep�,)rKrzc152Cs�d}1|*dk	r(|dko||1k}2t|2d�}3nt�}3|dkr:|}|-rN||1krNtd��|dk	r\d}4nd}d}4|3j|||*| |4|&|'|$|%||#||||||||
|||!|(|"||||||||||
|||)||/|0||-|,|+|.|	||d�0t||3�S)Nr�)�sep_overridezXSpecified a delimiter with both sep and delim_whitespace=True; you can only specify one.T�cF)0re�engine�dialectrO�engine_specifiedrirfrgrhrjrkrlrmrIrnrorprqrsrtrrrxryrzrRr{r|rQrwrVrSrTrurvr}r~rLrr�r�r�r�r�r�r�r�r�r�)�dictr>�updaterb)5rK�seprerlrIrmr}rrnr�rvr�rursrtrjrorprVrqrrr�r~r�rRr�r{rQr|rwrSrTrOrxrzrkrgrhrirfryrLr�r�r�r�r�r�r�Zdefault_sepr�r_r�rBrBrCr�s�N�
read_tablez+Read general delimited file into DataFrame.z'\\t' (tab-stop)�	c11Cs0|-r|dk	s|dkrtd��|-r$d}tft��S)Nr�zXSpecified a delimiter with both sep and delim_whitespace=True; you can only specify one.r�)r>r��locals)1rKr�rerlrIrmr}rrnr�rvr�rursrtrjrorprVrqrrr�r~r�rRr�r{rQr|rwrSrTrOrxrzrkrgrhrirfryrLr�r�r�r�r�r�r�rBrBrCr��sCcKs�|dkr|dkrtd��n|d
kr2|dk	r2td��|dk	rlgd}}x&|D]}|j|||f�||7}qJW||d<||d<d|d	<t||�S)aX
    Read a table of fixed-width formatted lines into DataFrame.

    Also supports optionally iterating or breaking of the file
    into chunks.

    Additional help can be found in the `online docs for IO Tools
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html>`_.

    Parameters
    ----------
    filepath_or_buffer : str, path object or file-like object
        Any valid string path is acceptable. The string could be a URL. Valid
        URL schemes include http, ftp, s3, and file. For file URLs, a host is
        expected. A local file could be:
        ``file://localhost/path/to/table.csv``.

        If you want to pass in a path object, pandas accepts any
        ``os.PathLike``.

        By file-like object, we refer to objects with a ``read()`` method,
        such as a file handler (e.g. via builtin ``open`` function)
        or ``StringIO``.
    colspecs : list of tuple (int, int) or 'infer'. optional
        A list of tuples giving the extents of the fixed-width
        fields of each line as half-open intervals (i.e.,  [from, to[ ).
        String value 'infer' can be used to instruct the parser to try
        detecting the column specifications from the first 100 rows of
        the data which are not being skipped via skiprows (default='infer').
    widths : list of int, optional
        A list of field widths which can be used instead of 'colspecs' if
        the intervals are contiguous.
    infer_nrows : int, default 100
        The number of rows to consider when letting the parser determine the
        `colspecs`.

        .. versionadded:: 0.24.0
    **kwds : optional
        Optional keyword arguments can be passed to ``TextFileReader``.

    Returns
    -------
    DataFrame or TextParser
        A comma-separated values (csv) file is returned as two-dimensional
        data structure with labeled axes.

    See Also
    --------
    DataFrame.to_csv : Write DataFrame to a comma-separated values (csv) file.
    read_csv : Read a comma-separated values (csv) file into DataFrame.

    Examples
    --------
    >>> pd.read_fwf('data.csv')  # doctest: +SKIP
    Nz&Must specify either colspecs or widthsrPz4You must specify only one of 'widths' and 'colspecs'rr�r�z
python-fwfr�)NrP)r>�appendrb)rKr�r�r�r_�col�wrBrBrC�read_fwfs?


r�c@speZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�Zddd�Zdd�Z
ddd�ZdS)r\zF

    Passed dialect overrides any of the related parser options

    NcKs:||_|dk	rd}nd}d}|jd|�|_|jd�dk	�r6|d}|tj�krXtj|�}x�d"D]�}yt||�}Wn8tk
r�}ztd|d�d
��|�WYdd}~XnXt	|}	|j||	�}
g}|
|	ko�|
|k�rd|�d|
�d|�d�}|dk�o|j
dd��s|j|�|�r*tj
dj|�tdd�|||<q^W|jd��rv|jd��sZ|jd��rbtd��|jd��rvtd��|jdd�dk�r�|jd�dk�r�dnd|d<||_||_d|_d|_|j|�}
|
j
dd�|_|
j
dd�|_|
j
d d�|_|j||�|_|j|
|�\|_|_d!|k�r*|d!|jd!<|j|j�dS)#NT�pythonFr�r�rerirfrjrgrhzInvalid dialect z	 providedzConflicting values for 'z': 'z+' was provided, but the dialect specifies 'z%'. Using the dialect-specified value.r�z

�)�
stacklevelrprSrTz*'skipfooter' not supported for 'iteration'rVz''skipfooter' not supported with 'nrows'rlrPrIrr�has_index_names)rerirfrjrgrh)�frW�_engine_specified�csv�
list_dialects�get_dialect�getattr�AttributeErrorr>�_parser_defaults�popr��warnings�warn�joinr�orig_optionsr��_engine�_currow�_get_options_with_defaultsrTrVr�_check_file_or_buffer�_clean_options�options�_make_engine)�selfr�r�r_r�r��paramZdialect_val�err�parser_default�providedZ
conflict_msgsrAr�rBrBrC�__init__Zsl



zTextFileReader.__init__cCs|jj�dS)N)r�r^)r�rBrBrCr^�szTextFileReader.closecCs|j}i}x@tj�D]4\}}|j||�}|dkr@|r@td��q|||<qWx�tj�D]�\}}||kr�||}|dkr�||kr�d|kr�|tkr�q�|tj||�kr�q�tdt|��dt|��d���ntj||�}|||<qVW|dk�r
x$t	j�D]\}}|j||�||<q�W|S)	Nr�z3Setting mangle_dupe_cols=False is not supported yetr�r�zThe z" option is not supported with the z enginez
python-fwf)
r�r��itemsrWr>�_c_parser_defaults�_python_unsupported�_deprecated_defaults�repr�
_fwf_defaults)r�r�r_r�Zargname�default�valuerBrBrCr��s.

z)TextFileReader._get_options_with_defaultscCs0t|�r,d}|dkr,t||�r,d}t|��|S)N�__next__r�z<The 'python' engine cannot iterate through this file buffer.)r�hasattrr>)r�r�r�Z	next_attrrArBrBrCr��sz$TextFileReader._check_file_or_buffercCs�|j�}|j}d}|d}|d}|dkr>|ddkr>d}d}tj�pHd}|dkrj|rj|dkrhd	}d}n�|dk	r�t|�d
kr�|dkr�|dkr�d|d<|d=n|d*kr�d}d}n||r�d|kr�d|d<nf|dk	�r,d}	yt|j|��d
kr�d}	Wntk
�rd}	YnX|	�r,|d+k�r,d|�d�}d}|d}
|
dk	�r|t|
tt	f��r|t|
�d
k�r|t
|
�dk�r||d,k�r|d}d}|�r�|�r�t|��|dk�r�xtD]}||=�q�Wd|k�rxFt
D]>}|�r�||t|k�r�td|�dt|��d���||=�q�W|�r tjd|�d�tdd�|d}|d}
|d}|d}|d}t|d �d!}xVtD]N}t|}t|}d"t|��d#�}|j||�|k�r�||d$7}n|||<�q^W|d!k�r�tj|td%d�|dk�r�td&��t|��rt|tttjf��s|g}||d<|
dk	�rt|
�n|
}
|dk	�rJt|t��sNtd't|�j ����ni}|d(}t!||�\}}|dk�r�t"|��r�tt#|��}|dk�r�t$�}nt%|��s�t$|�}|
|d<||d<||d<||d)<||d<||fS)-Nrer�r�rprz*the 'c' engine does not support skipfooterr�zutf-8zDthe 'c' engine does not support sep=None with delim_whitespace=FalserUz\s+T�
python-fwfzxthe 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex)Fzthe separator encoded in zF is > 1 char long, and the 'c' engine does not support such separatorsrg�zxord(quotechar) > 127, meaning the quotechar is larger than one byte, and the 'c' engine does not support such quotecharsz,Falling back to the 'python' engine because z, but this causes z= to be ignored as it is not supported by the 'python' engine.z;; you can avoid this warning by specifying engine='python'.�)r�rmrIrurqrorl�zThe zF argument has been deprecated and will be removed in a future version.z

r�z)The value of index_col couldn't be 'True'z8Type converters must be a dict or subclass, input was a rr�
na_fvalues)r�r�)r�r�)r�r�)&�copyr��sys�getfilesystemencodingrE�encode�UnicodeDecodeErrorrG�str�bytes�ordr>�_c_unsupportedr�r�r�r�r�rr6�_deprecated_argsr�rW�
FutureWarning�
_is_index_col�list�tuple�np�ndarrayr��	TypeError�type�__name__�_clean_na_valuesr!�rangerF�callable)r�r�r��resultr�Zfallback_reasonr�r�rLZ
encodeablerg�argrmrIrurqroZdepr_warningr�Zdepr_defaultrArrr�rBrBrCr��s�

















zTextFileReader._clean_optionscCs,y|j�Stk
r&|j��YnXdS)N)�	get_chunk�
StopIterationr^)r�rBrBrCr��s
zTextFileReader.__next__r�cCs^|dkrt|jf|j�|_n>|dkr*t}n|dkr8t}ntd|�d���||jf|j�|_dS)Nr�r�z
python-fwfzUnknown engine: z3 (valid options are "c", "python", or "python-fwf"))�CParserWrapperr�r�r��PythonParser�FixedWidthFieldParserr>)r�r��klassrBrBrCr��szTextFileReader._make_enginecCst|��dS)N)r)r�rBrBrC�_failover_to_python�sz"TextFileReader._failover_to_pythoncCs�td|�}|jj|�}|j|�\}}}|dkr`|rZttt|j����}t|j	|j	|�}qhd}nt|�}t
|||d�}|j	|7_	|jr�t|j�dkr�||jdj
�S|S)NrVr)�columns�indexrU)rDr�r]�
_create_indexrE�next�iter�valuesr/r�r,rr�r�)r�rV�retr�r��col_dict�new_rowsZdfrBrBrCr]�s
zTextFileReader.readcCs|\}}}|||fS)NrB)r�r�r�r�r�rBrBrCr��s
zTextFileReader._create_indexcCsF|dkr|j}|jdk	r:|j|jkr(t�t||j|j�}|j|d�S)N)rV)rTrVr�r��minr])r��sizerBrBrCr��s
zTextFileReader.get_chunk)N)r�)N)N)r��
__module__�__qualname__�__doc__r�r^r�r�r�r�r�r�r]r�r�rBrBrBrCr\Ss
\&%

r\cCs|dk	o|dk	S)NFrB)r�rBrBrCr��sr�)rmcs@�dkst�t�rg�t|�o>t|t�o>t�fdd�|D��S)a�
    Check whether or not the `columns` parameter
    could be converted into a MultiIndex.

    Parameters
    ----------
    columns : array-like
        Object which may or may not be convertible into a MultiIndex
    index_col : None, bool or list, optional
        Column or columns to use as the (possibly hierarchical) index

    Returns
    -------
    boolean : Whether or not columns could become a MultiIndex
    Nc3s$|]}|t��krt|t�VqdS)N)r�rGr�)�.0r�)rmrBrC�	<genexpr>�sz,_is_potential_multi_index.<locals>.<genexpr>)rGr[rEr.�all)r�rmrB)rmrC�_is_potential_multi_index�s
r�cs"t��r�fdd�t|�D�S�S)z�
    Check whether or not the 'usecols' parameter
    is a callable.  If so, enumerates the 'names'
    parameter and returns a set of indices for
    each entry in 'names' that evaluates to True.
    If not a callable, returns 'usecols'.
    csh|]\}}�|�r|�qSrBrB)r��ir?)r}rBrC�	<setcomp>�sz$_evaluate_usecols.<locals>.<setcomp>)r��	enumerate)r}rIrB)r}rC�_evaluate_usecols�srcs0�fdd�|D�}t|�dkr,td|����|S)a%
    Validates that all usecols are present in a given
    list of names. If not, raise a ValueError that
    shows what usecols are missing.

    Parameters
    ----------
    usecols : iterable of usecols
        The columns to validate are present in names.
    names : iterable of names
        The column names to check against.

    Returns
    -------
    usecols : iterable of usecols
        The `usecols` parameter if the validation succeeds.

    Raises
    ------
    ValueError : Columns were missing. Error message will list them.
    csg|]}|�kr|�qSrBrB)r�r�)rIrBrC�
<listcomp>sz+_validate_usecols_names.<locals>.<listcomp>rz>Usecols do not match columns, columns expected but not found: )rEr>)r}rI�missingrB)rIrC�_validate_usecols_namess
rcCs$t|�std��|dkr td��|S)a�
    Validate the 'skipfooter' parameter.

    Checks whether 'skipfooter' is a non-negative integer.
    Raises a ValueError if that is not the case.

    Parameters
    ----------
    skipfooter : non-negative integer
        The number of rows to skip at the end of the file.

    Returns
    -------
    validated_skipfooter : non-negative integer
        The original input if the validation succeeds.

    Raises
    ------
    ValueError : 'skipfooter' was not a non-negative integer.
    zskipfooter must be an integerrzskipfooter cannot be negative)r!r>)rprBrBrC�_validate_skipfooter_args
rcCsbd}|dk	rZt|�r|dfSt|�s,t|��tj|dd�}|dkrJt|��t|�}||fS|dfS)	a+
    Validate the 'usecols' parameter.

    Checks whether or not the 'usecols' parameter contains all integers
    (column selection by index), strings (column by name) or is a callable.
    Raises a ValueError if that is not the case.

    Parameters
    ----------
    usecols : list-like, callable, or None
        List of columns to use when parsing or a callable that can be used
        to filter a list of table columns.

    Returns
    -------
    usecols_tuple : tuple
        A tuple of (verified_usecols, usecols_dtype).

        'verified_usecols' is either a set if an array-like is passed in or
        'usecols' if a callable or None is passed in.

        'usecols_dtype` is the inferred dtype of 'usecols' if an array-like
        is passed in or None if a callable or None is passed in.
    z['usecols' must either be list-like of all strings, all unicode, all integers or a callable.NF)�skipna�empty�integer�string)rr	r
)r�r#r>�libZinfer_dtyperF)r}rA�
usecols_dtyperBrBrC�_validate_usecols_arg=sr
cCsBd}|dk	r>t|�r(tj|�s>t|��nt|ttf�s>t|��|S)z�
    Check whether or not the 'parse_dates' parameter
    is a non-boolean scalar. Raises a ValueError if
    that is the case.
    zSOnly booleans, lists, and dictionaries are accepted for the 'parse_dates' parameterN)r%rZis_boolr�rGr�r�)rRrArBrBrC�_validate_parse_dates_argos

rc@s�eZdZdd�Zeedd�dd�Zdd�Zed	d
��Z	dd�Z
d%dd�Zdd�Zd&dd�Z
d'dd�Zd
Zdd�Zdd�Zd(dd�Zd)dd�Zd*dd �Zd!d"�Zd#d$�ZdS)+�
ParserBasecCs@|jd�|_d|_|jdd�|_|jdd�|_t�|_d|_d|_	t
|jdd��|_|jdd�|_|jdd�|_
|jdd�|_|jd	�|_|jd
�|_|jdd�|_|jdd
�|_|jd�|_|jd�|_|jdd
�|_|jdd�|_|jdd
�|_t|j|j
|j|jd�|_|jd�|_t|jtttjf��r�t t!t"|j���sJt#d��t$dd�|jD���rht#d��|jd��r|t#d��|jd��r�t#d��|jdk	�r*t|jtttjf�}|�r�t t!t"|j���p�t"|j��s*t#d��nL|jdk	�r*|jdk	�rt#d��n*t"|j��st#d��n|jdk�r*t#d��d|_%d
|_&g|_'dS) NrIrnrmrRFrQr|r{rqr�r�rrTrsrtr�r�rw)rQr|r�rwrlz*header must be integer or list of integerscss|]}|dkVqdS)rNrB)r�r�rBrBrCr��sz&ParserBase.__init__.<locals>.<genexpr>z8cannot specify multi-index header with negative integersr}z;cannot specify usecols when specifying a multi-index headerz9cannot specify names when specifying a multi-index headerzLindex_col must only contain row numbers when specifying a multi-index headerz;Argument prefix must be None if argument header is not NonerzUPassing negative integer to header is invalid. For no header, use header=None instead)(rWrI�
orig_namesr�rnrmrF�unnamed_cols�index_names�	col_namesrrRrQr|r{rqr�r�rrrsrtr�r�rw�_make_date_converter�
_date_convrlrGr�r�r�r�r��mapr!r>�any�_name_processed�_first_chunk�handles)r�r_Zis_sequencerBrBrCr��sr
zParserBase.__init__N)r��returncsxt|j�rtj|jj��}n(t|j�r@tjjdd�|jD��}ng}djt�fdd�|D���}|rtt	d|�d���dS)	ao
        Check if parse_dates are in columns.

        If user has provided names for parse_dates, check if those columns
        are available.

        Parameters
        ----------
        columns : list
            List of names of the dataframe.

        Raises
        ------
        ValueError
            If column to parse_date is not in dataframe.

        css |]}t|�r|n|gVqdS)N)r#)r�r�rBrBrCr��sz<ParserBase._validate_parse_dates_presence.<locals>.<genexpr>z, cs"h|]}t|t�r|�kr|�qSrB)rGr�)r�r�)r�rBrCrsz<ParserBase._validate_parse_dates_presence.<locals>.<setcomp>z+Missing column provided to 'parse_dates': 'r:N)
rrR�	itertools�chainr�r#�
from_iterabler��sortedr>)r�r�Zcols_neededZmissing_colsrB)r�rC�_validate_parse_dates_presence�s


z)ParserBase._validate_parse_dates_presencecCsx|jD]}|j�qWdS)N)rr^)r�r�rBrBrCr^
szParserBase.closecCs6t|jt�p4t|jt�o4t|j�dko4t|jdt�S)Nr)rGrRr�r�rE)r�rBrBrC�_has_complex_date_colsz ParserBase._has_complex_date_colcCs|t|jt�r|jS|jdk	r(|j|}nd}|j|}t|j�r\||jkpZ|dk	oZ||jkS||jkpv|dk	ov||jkSdS)N)rGrRr[rrmr%)r�r�r?�jrBrBrC�_should_parse_datess




zParserBase._should_parse_datesFc	s>t|�dkr|d|||fS�j}|dkr.g}t|tttjf�sF|g}t|��|jd�}t	|�j�j
�\}}}t|d����fdd��tt�fdd�|D���}||}xVtt|d��D]B�t
��fd	d�|D��r�d
jdd��jD��}td|�d
���q�Wt|��r �fdd�|D�}ndgt|�}d}||||fS)z�
        extract and return the names, index_names, col_names
        header is a list-of-lists returned from the parsers
        r�rNrUcst��fdd�t��D��S)Nc3s|]}|�kr�|VqdS)NrB)r�r�)�r�sicrBrCr�KszMParserBase._extract_multi_indexer_columns.<locals>.extract.<locals>.<genexpr>)r�r�)r$)�field_countr%)r$rC�extractJsz:ParserBase._extract_multi_indexer_columns.<locals>.extractc3s|]}�|�VqdS)NrB)r�r$)r'rBrCr�Msz<ParserBase._extract_multi_indexer_columns.<locals>.<genexpr>c3s |]}t|���jkVqdS)N)rr)r�r�)�nr�rBrCr�Ssr�css|]}t|�VqdS)N)r�)r��xrBrBrCr�TszPassed header=[z3] are too many rows for this multi_index of columnscs2g|]*}|ddk	r*|d�jkr*|dnd�qS)rN)r)r�r$)r�rBrCr]sz=ParserBase._extract_multi_indexer_columns.<locals>.<listcomp>T���)rErmrGr�r�r�r�rFr��_clean_index_namesr�zipr�r�r�rlr)	r�rlrr�passed_names�icrIrmr�rB)r'r&r(r�r%rC�_extract_multi_indexer_columns,s4



z)ParserBase._extract_multi_indexer_columnscCs�|jr�t|�}tt�}t||j�}x�t|�D]z\}}||}xT|dkr�|d||<|rx|dd�|d�d|��f}n|�d|��}||}q>W|||<|d||<q,W|S)NrrUrdr*r*)r�r�rr=r�rmr)r�rI�countsZis_potential_mir�r��	cur_countrBrBrC�_maybe_dedup_namesgs
"zParserBase._maybe_dedup_namescCst|�rtj||d�}|S)N)rI)r�r.�from_tuples)r�r�rrBrBrC�_maybe_make_multi_index_columns�sz*ParserBase._maybe_make_multi_index_columnscCs�t|j�s|jrd}nh|js8|j||�}|j|�}nJ|jr�|jshtt|�|j|j�\|_	}|_d|_|j
||�}|j|dd�}|r�t|�t|�}|j|d|��}|j
||j�}||fS)NTF)�try_parse_dates)r�rmr!�_get_simple_index�
_agg_indexrr+r�rr�_get_complex_date_indexrEZ	set_namesr4r)r�ra�alldatar��indexnamerowr�rMZcoffsetrBrBrC�_make_index�s"zParserBase._make_indexcCstdd�}g}g}x.|jD]$}||�}|j|�|j||�qWx.t|dd�D]}|j|�|jsN|j|�qNW|S)NcSs"t|t�s|Std|�d���dS)NzIndex z invalid)rGr�r>)r�rBrBrC�ix�s
z(ParserBase._get_simple_index.<locals>.ixT)�reverse)rmr�rr��_implicit_index)r�rar�r<�	to_remover��idxr�rBrBrCr6�s

zParserBase._get_simple_indexc	sr�fdd�}g}g}x.|jD]$}||�}|j|�|j||�qWx(t|dd�D]}|j|��j|�qRW|S)NcsLt|t�r|S�dkr&td|�d���x t��D]\}}||kr0|Sq0WdS)Nz Must supply column order to use z	 as index)rGr�r>r)Zicolr�r�)rrBrC�	_get_name�s
z5ParserBase._get_complex_date_index.<locals>._get_nameT)r=)rmr�rr��remove)	r�rarrAr?r�r@r?r�rB)rrCr8�s

z"ParserBase._get_complex_date_indexTcCs�g}x�t|�D]�\}}|r.|j|�r.|j|�}|jrB|j}|j}nt�}t�}t|jt�r�|j	|}|dk	r�t
||j|j|j�\}}|j|||B�\}}	|j
|�qW|j	}
t||
�}|S)N)rr#rr�rqr�rFrGr�r�_get_na_valuesrr�_infer_typesr�r0)r�r�r5�arraysr�Zarr�
col_na_values�col_na_fvalues�col_namerMrIrBrBrCr7�s&


zParserBase._agg_indexcCs�i}�x�|j�D�]�\}}	|dkr&dn
|j|d�}
t|t�rJ|j|d�}n|}|jrjt||||j�\}}
nt�t�}}
|
dk	�r|dk	r�tj	d|�d�t
dd�ytj|	|
�}	Wn:t
k
r�tj|	t|��jtj�}tj|	|
|�}	YnX|j|	t|�|
Bdd�\}}n�t|��pt|�}|�o&|}|j|	t|�|
B|�\}}|�r�t||��sbt|��r�y2t|��r�t|��r�|dk�r�t
d|����Wnttfk
�r�YnX|j|||�}|||<|r|rtd	|�d
|���qW|S)Nz5Both a converter and dtype were specified for column z" - only the converter will be used�)r�F)�try_num_boolrz$Bool column has NA values in column zFilled z NA values in column )r�rWrGr�r�rCrrrFr�r�rrZ	map_inferr>r*�isinr��viewr�Zuint8Zmap_infer_maskrDr&rrrrr�r��_cast_types�print)r��dctrqr�r~ruZdtypesr�r�r�Zconv_f�	cast_typerFrG�maskZcvals�na_countZis_str_or_ea_dtyperJrBrBrC�_convert_to_ndarrays�sX





zParserBase._convert_to_ndarraysc
Csd}t|jjtjtjf�rftj|t|��}|j	�}|dkr^t
|�rN|jtj�}tj
||tj�||fS|r�t|j�r�ytj||d�}Wn*ttfk
r�|}tj||d�}Yq�Xt|�j	�}n|}|jtjkr�tj||d�}|jtjko�|�r
tjtj|�|j|jd�}||fS)aU
        Infer types of values, possibly casting

        Parameters
        ----------
        values : ndarray
        na_values : set
        try_num_bool : bool, default try
           try to cast values to numeric (first preference) or boolean

        Returns
        -------
        converted : ndarray
        na_count : int
        rF)rsrt)�
issubclassrvr�r��numberZbool_r*rKr��sumr"ZastypeZfloat64Zputmask�nanr$rZmaybe_convert_numericr>r��parsersZsanitize_objectsr)Zobject_�libopsZmaybe_convert_boolZasarrayrsrt)r�r�rqrJrRrQr�rBrBrCrD?s2
zParserBase._infer_typescCst|�rbt|t�o|jdk	}t|�r6|r6t|t�}t|�j�j	�}t
j||j|�||j
d�}n�t|�r�t|�}|j�}y|j||d�Stk
r�}ztd|�d��|�WYdd}~XnXnPyt||ddd�}Wn:tk
�r}ztd|�d	|���|�WYdd}~XnX|S)
aF
        Cast values to specified type

        Parameters
        ----------
        values : ndarray
        cast_type : string or np.dtype
           dtype to cast values to
        column : string
            column name - used only for error reporting

        Returns
        -------
        converted : ndarray
        N)rs)rvzExtension Array: zO must implement _from_sequence_of_strings in order to be used in parser methodsT)r�rzUnable to convert column z	 to type )rrGr(�
categoriesr$rr�r-�uniqueZdropnar+Z_from_inferred_categoriesZget_indexerrsrr'Zconstruct_array_typeZ_from_sequence_of_strings�NotImplementedErrorr>)r�r�rP�columnZ
known_catsZcatsZ
array_typer�rBrBrCrMrs0


zParserBase._cast_typesc	Cs6|jdk	r.t||j|j|j|j||jd�\}}||fS)N)r{)rR�_process_date_conversionrrmrr{)r�rIrarBrBrC�_do_date_conversions�s
zParserBase._do_date_conversions)F)N)F)T)FNN)T)r�r�r�r�r
r�r r^�propertyr!r#r/r2r4r;r>r6r8r7rSrDrMr_rBrBrBrCr�s"W0
:



J
37rc@sTeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
ddd�Zd
S)r�z

    cs�|�_|j�}tj�|�|jd�}|jd�dkr�|r�t|t�rVt|d�}�jj	|�t
|d�rzt
|d�rzt||dd�}d|d<�jdk	|d	<t
|d
�\�_�_�j|d
<tj|f|��_�jj�_�jdk}�jjdkr�d�_nLt�jj�dk�r �j�jj�j�j|�\�_�_�_}nt�jjd��_�jdk�rv�j�rd�fd
d�t�jj�D��_ntt�jj���_�jdd��_�j�rt�j�j���jdk�r�t ��j!�j��r�t"��j�t�j�t��k�r��fdd�t#�j�D��_t�j�t��k�rt"��j��j$�j��j%��j�_�j&�s��jj'dk�r�t(�j��r�d�_)t*�j�j�j�\}�_�_�jdk�r�|�_�jjdk�r�|�r�dgt�j��_�jj'dk�_+dS)NrLrO�rbr]r�)rL�newlinezutf-8FZallow_leading_colsr}rUrcsg|]}�j�|���qSrB)rn)r�r�)r�rBrCr�sz+CParserWrapper.__init__.<locals>.<listcomp>r
cs$g|]\}}|�ks|�kr|�qSrBrB)r�r�r()r}rBrCrsT),r_r�rr�rWrGr��openrr�r�rrmr
r}rrXZ
TextReader�_readerrrIrlrEr/rrr�rnr�Ztable_widthrrrF�issubsetrrr �_set_noconvert_columnsr!�leading_colsr�rr+r>)r��srcr_rLr-rrB)r�r}rCr��sf





$

zCParserWrapper.__init__cCs@x|jD]}|j�qWy|jj�Wntk
r:YnXdS)N)rr^rdr>)r�r�rBrBrCr^)szCParserWrapper.closecs<�j��jdkr$t�j���j�n(t�j�s8�jdkrH�jdd��nd����fdd�}t�jt�r�xΈjD].}t|t�r�x|D]}||�q�Wqp||�qpWn�t�jt	�r�x��jj
�D].}t|t�r�x|D]}||�q�Wq�||�q�WnH�j�r8t�jt��r"x0�jD]}||��qWn�jdk	�r8|�j�dS)z�
        Set the columns that should not undergo dtype conversions.

        Currently, any column that is involved with date parsing will not
        undergo such conversions.
        r	rNcs:�dk	rt|�r�|}t|�s*�j|�}�jj|�dS)N)r!r�rdZ
set_noconvert)r))rIr�r}rBrC�_setHs

z3CParserWrapper._set_noconvert_columns.<locals>._set)rN)rrr�r}�sortr�rIrGrRr�r�rm)r�rir@�krB)rIr�r}rCrf3s4


	



z%CParserWrapper._set_noconvert_columnscCs|jjt|��dS)N)rd�set_error_bad_linesr=)r��statusrBrBrCrlhsz"CParserWrapper.set_error_bad_linesNc
sy|jj|�}Wn�tk
r�|jr�d|_|j|j�}t||j|j|j	j
d�d�\}�}|j�|j��|j
dk	r||j���tt�fdd�|j���}|�|fS�YnXd|_|j}|jj�r�|jr�td��g}xTt|jj�D]D}|jdkr�|j|�}n|j|j|�}|j||dd�}|j|�q�Wt|�}|j
dk	�rD|j|�}|j|�}t|j��}d	d
�t||�D�}|j||�\}}nzt|j��}t|j�}|j|�}|j
dk	�r�|j|�}dd�|D�}	d
d
�t||�D�}|j||�\}}|j||	|�\}}|j||j�}|||fS)NFrv)rvcs|d�kS)NrrB)�item)r�rBrC�<lambda>~sz%CParserWrapper.read.<locals>.<lambda>z file structure not yet supportedT)r5cSsi|]\}\}}||�qSrBrB)r�rkr��vrBrBrC�
<dictcomp>�sz'CParserWrapper.read.<locals>.<dictcomp>cSsg|]}|d�qS)rUrB)r�r)rBrBrCr�sz'CParserWrapper.read.<locals>.<listcomp>cSsi|]\}\}}||�qSrBrB)r�rkr�rprBrBrCrq�s) rdr]r�rr2r�_get_empty_metarmrr_rWr4rr}�_filter_usecolsr��filterr�rIrgr!r\r�r��_maybe_parse_datesr�r0rr,r_r�r;)
r�rVrarIr�r�rEr�r�r9rB)r�rCr]ks`









zCParserWrapper.readcs>t|j|���dk	r:t|�t��kr:�fdd�t|�D�}|S)Ncs$g|]\}}|�ks|�kr|�qSrBrB)r�r�r?)r}rBrCr�sz2CParserWrapper._filter_usecols.<locals>.<listcomp>)rr}rEr)r�rIrB)r}rCrs�szCParserWrapper._filter_usecolscCsJt|jjd�}d}|jjdkrB|jdk	rBt||j|j�\}}|_||fS)Nr)r�rdrlrgrmr+r)r�rIZ	idx_namesrBrBrC�_get_index_names�szCParserWrapper._get_index_namesTcCs|r|j|�r|j|�}|S)N)r#r)r�r�r�r5rBrBrCru�s
z!CParserWrapper._maybe_parse_dates)N)T)r�r�r�r�r�r^rfrlr]rsrvrurBrBrBrCr��sj
5
U	r�cOsd|d<t||�S)a6	
    Converts lists of lists/tuples into DataFrames with proper type inference
    and optional (e.g. string to datetime) conversion. Also enables iterating
    lazily over chunks of large files

    Parameters
    ----------
    data : file-like object or list
    delimiter : separator character to use
    dialect : str or csv.Dialect instance, optional
        Ignored if delimiter is longer than 1 character
    names : sequence, default
    header : int, default 0
        Row to use to parse column labels. Defaults to the first row. Prior
        rows will be discarded
    index_col : int or list, optional
        Column or columns to use as the (possibly hierarchical) index
    has_index_names: bool, default False
        True if the cols defined in index_col have an index name and are
        not in the header.
    na_values : scalar, str, list-like, or dict, optional
        Additional strings to recognize as NA/NaN.
    keep_default_na : bool, default True
    thousands : str, optional
        Thousands separator
    comment : str, optional
        Comment out remainder of line
    parse_dates : bool, default False
    keep_date_col : bool, default False
    date_parser : function, optional
    skiprows : list of integers
        Row numbers to skip
    skipfooter : int
        Number of line at bottom of file to skip
    converters : dict, optional
        Dict of functions for converting values in certain columns. Keys can
        either be integers or column labels, values are functions that take one
        input argument, the cell (not column) content, and return the
        transformed content.
    encoding : str, optional
        Encoding to use for UTF when reading/writing (ex. 'utf-8')
    squeeze : bool, default False
        returns Series if only one column.
    infer_datetime_format: bool, default False
        If True and `parse_dates` is True for a column, try to infer the
        datetime format based on the first datetime string. If the format
        can be inferred, there often will be a large parsing speed-up.
    float_precision : str, optional
        Specifies which converter the C engine should use for floating-point
        values. The options are None for the ordinary converter,
        'high' for the high-precision converter, and 'round_trip' for the
        round-trip converter.
    r�r�)r\)�argsr_rBrBrC�
TextParser�s6rxcCstdd�|D��S)Ncss"|]}|dks|dkrdVqdS)r�NrUrB)r�rprBrBrCr�	sz#count_empty_vals.<locals>.<genexpr>)rV)�valsrBrBrC�count_empty_vals	srzc@s�eZdZdd�Zdd�Zdd�Zd3dd	�Zd
d�Zd4dd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,Zd-d.�Zd/d0�Zd5d1d2�ZdS)6r�cstj�|�d�_g�_d�_d�_|d�_|d�_|d�_|d�_	t
�j	�r`�j	�_n�fdd��_t|d	��_
|d
�_|d�_t�jt�r�t�j��_|d�_|d
�_|d�_|d�_|d�_t|d�\�_}|d�_|d�_|d�_|d�pd�_d�_d|k�r4|d�_|d�_|d�_|d�_ |d�_!|d�_"|d�_#g�_$t%|d�j�j�jd�\}}�j&j'|�t(|d ��r��j)|�n|�_d�_*y�j+�\�_,�_-�_.Wn$t/t0fk
�r��j1��YnXt2�j,�d!k�r@�j3�j,�j4�j5�\�_,�_4�_5}t2�j,��_-n�j,d�_,t6�j,��_7�j8�s��j9�j,�\}�_7�_,d"�_:�j4dk�r�|�_4�j;�j,��j<�r��j=��_>nd�_>t2�j"�d!k�r�t0d#���j!dk�r�t?j@d$�j"�d%���_Ant?j@d$�j!�d&�j"�d%���_AdS)'zN
        Workhorse function for processing nested list into DataFrame
        NrrLrOr�rocs
|�jkS)N)ro)r))r�rBrCro,	sz'PythonParser.__init__.<locals>.<lambda>rprergrfrirjrkrhr}r�r�r�rIFr�r~rurvrxrzryr$)rLrOr��readlinerUTz'Only length-1 decimal markers supportedz[^-^0-9^z]+�^)Brr�ra�buf�pos�line_posrLrOr�ror��skipfuncrrprergrGr�rfrirjrkrhr
r}r�r�r�Znames_passedr�r~rurvrxrzryZ_comment_linesr4r�extendr��_make_reader�_col_indices�_infer_columnsr��num_original_columnsrr�r>r^rEr/rrr�rr!�_get_index_namerr rR�_set_no_thousands_columns�_no_thousands_columnsrX�compile�nonnum)r�r�r_rMrrrB)r�rCr�	s�























zPythonParser.__init__cs�t����fdd�}t�jt�r\xƈjD].}t|t�rNx|D]}||�q<Wq(||�q(Wn�t�jt�r�x~�jj�D].}t|t�r�x|D]}||�q�Wqt||�qtWn@�jr�t�jt�r�x,�jD]}||�q�Wn�jdk	r�|�j��S)Ncs*t|�r�j|�n�j�jj|��dS)N)r!�addr�r�)r))�noconvert_columnsr�rBrCri�	sz4PythonParser._set_no_thousands_columns.<locals>._set)rFrGrRr�r�r�rm)r�rir@rkrB)r�r�rCr��	s*





z&PythonParser._set_no_thousands_columnsc
s:�j��dkst��dk�r�jr*td��G�fdd�dtj�}|}�dk	rT�|_n��j�}�j|gg�d}x>�j�j	�s�|r��j	d7_	�j�}�j|gg�d}qpW|d}�j	d7_	�j
d7_
tj�j|�}|j|_tj
t|�|d�}�jjt|��tj
�|dd�}n��fd	d
�}	|	�}|�_dS)NrUz<Custom line terminators not supported in python parser (yet)cs4eZdZ�jZ�jZ�jZ�jZ�jZ�jZdZ	dS)z,PythonParser._make_reader.<locals>.MyDialect�
N)
r�r�r�rergrfrirjrhrkrB)r�rBrC�	MyDialect�	sr�r)r�T)r��strictc3sD�j�}tj��}|j|j��Vx�D]}|j|j��Vq(WdS)N)r{rXr��split�strip)�line�pat)r�r�rBrCrb�	s


z(PythonParser._make_reader.<locals>._read)rerErkr>r��Dialectr{�_check_commentsr�r~r�Sniffer�sniff�readerrr}r�r�ra)
r�r�r�Zdiar��lines�sniffedZline_rdrr�rbrB)r�r�r�rCr��	s4		zPythonParser._make_readerNc
Csy|j|�}Wn"tk
r0|jr*g}n�YnXd|_t|j�}t|�s�|j|j�}t||j|j	|j
�\}}}|j||j�}|||fSt
|d�}d}|jr�|t|�kr�|d}|dd�}|j|�}	|j|	�}
|j|j�}|j||
�\}}
|j|
�}
|j|
|	||�\}}|||
fS)NFrrU)�
_get_linesr�rr�rrEr2rrrmrrvr4rrzr��
_rows_to_cols�_exclude_implicit_indexr�r_�
_convert_datar;)r��rows�contentr�rIr�r�Zcount_empty_content_valsr:r9rarBrBrCr]�	s4




zPythonParser.readcCsz|j|j�}|jrb|j}i}d}xTt|�D]2\}}x|||krJ|d7}q4W|||||<q*Wndd�t||�D�}|S)NrrUcSsi|]\}}||�qSrBrB)r�rkrprBrBrCrq1
sz8PythonParser._exclude_implicit_index.<locals>.<dictcomp>)r2rr>rmrr,)r�r9rIZexcl_indicesra�offsetr�r�rBrBrCr�$
sz$PythonParser._exclude_implicit_indexcCs|dkr|j}|j|d�S)N)r�)rTr])r�r�rBrBrCr�6
szPythonParser.get_chunkc
s��fdd�}|�j�}t�jt�s*�j}n
|�j�}i}i}t�jt�r�x^�jD]F}�j|}�j|}	t|t�r�|�jkr��j|}|||<|	||<qPWn�j}�j}�j|||�j	||�S)NcsDi}x:|j�D].\}}t|t�r4|�jkr4�j|}|||<qW|S)zconverts col numbers to names)r�rGr=r)�mapping�cleanr�rp)r�rBrC�_clean_mapping=
s
z2PythonParser._convert_data.<locals>._clean_mapping)
rurGrvr�rqr�r=rrSr~)
r�rar�Z
clean_convZclean_dtypesZclean_na_valuesZclean_na_fvaluesr�Zna_valueZ	na_fvaluerB)r�rCr�;
s0	




zPythonParser._convert_datacs��j}d}d}t�}�jdk	�r��j}t|tttjf�r`t|�dk}|rjt|�|ddg}n
d}|g}g}�x|t	|�D�]n\}}	y$�j
�}
x�j|	kr��j�}
q�WWn�t
k
�rR}z��j|	kr�td|	�d�jd�d��|�|o�|	dk�r"|�r�j�|jdgt|d��|||fS�j�s4td�|��jdd�}
WYdd}~XnXg�g}xbt	|
�D]V\}
}|d	k�r�|�r�d
|
�d|��}n
d
|
��}|j|
��j|�n
�j|��qfW|�rB�j�rBtt�}x�t	��D]Z\}
}||}x2|dk�r$|d||<|�d|��}||}�q�W|�|
<|d||<�q�Wnr|�r�|	|dk�r�t��}�jdk	�rtt�j�nd}t|�}||k�r�|||k�r�d}dg|��jdg�_|j��|j�fd
d�|D��t|�dkrzt��}qzW|�r��j�|dk	�r��jdk	�r&t|�t�j�k�sH�jdk�rPt|�t|d�k�rPtd��t|�dk�rftd���jdk	�r��j||�nd�_t|�}|g}n�j||d�}�ny�j
�}
Wn@t
k
�r�}z"|�s�td�|�|dd�}
WYdd}~XnXt|
�}|}|�sL�j�r,�fdd�t|�D�g}ntt|��g}�j||d�}nt�jdk�sft|�|k�r~�j|g|�}t|�}nBt�j��r�t|�t�j�k�r�td���j|g|�|g}|}|||fS)NrTrUFzPassed header=z
 but only z lines in filezNo columns to parse from filer�z	Unnamed: Z_level_rdcsh|]}�|�qSrBrB)r�r�)�this_columnsrBrCr�
sz.PythonParser._infer_columns.<locals>.<setcomp>zHNumber of passed names did not match number of header fields in the filez*Cannot pass names with multi-index columnscsg|]}�j�|���qSrB)rn)r�r�)r�rBrCr�
sz/PythonParser._infer_columns.<locals>.<listcomp>r*r*r*r*)rIrFrlrGr�r�r�r�rEr�_buffered_liner�
_next_liner�r>�
_clear_bufferr�rr�rr=rmr}r�r}r��_handle_usecolsr�rnr�r�)r�rIr�Zclear_bufferrrlZhave_mi_columnsr��level�hrr�r�Zthis_unnamed_colsr�r�rHr0r�r1�lcr.Z
unnamed_countZncolsrB)r�r�rCr�h
s�


 





 "

"zPythonParser._infer_columnscs�|jdk	r�t|j�r"t|j|��n�tdd�|jD��r�t|�dkrJtd��g�xb|jD]P}t|t�r�y�j|j	|��Wq�tk
r�t
|j|�Yq�XqV�j|�qVWn|j��fdd�|D�}�|_|S)zb
        Sets self._col_indices

        usecols_key is used if there are string usecols.
        Ncss|]}t|t�VqdS)N)rGr�)r��urBrBrCr�
sz/PythonParser._handle_usecols.<locals>.<genexpr>rUz4If using multiple headers, usecols must be integers.cs"g|]}�fdd�t|�D��qS)csg|]\}}|�kr|�qSrBrB)r�r�r()�col_indicesrBrCr sz;PythonParser._handle_usecols.<locals>.<listcomp>.<listcomp>)r)r�r])r�rBrCr sz0PythonParser._handle_usecols.<locals>.<listcomp>)r}r�rrrEr>rGr�r�r�rr�)r�r�Zusecols_keyr�rB)r�rCr�s(



zPythonParser._handle_usecolscCs$t|j�dkr|jdS|j�SdS)zH
        Return a line from buffer, filling buffer if required.
        rN)rEr}r�)r�rBrBrCr�&s
zPythonParser._buffered_linecCs�|s|St|dt�s|S|ds&|S|dd}|tkr>|S|d}t|�dkr�|d|jkr�d}|d}|dd�j|�d}|||�}t|�|dkr�|||dd�7}|g|dd�St|�dkr�|dd�gSdgSdS)a-
        Checks whether the file begins with the BOM character.
        If it does, remove it. In addition, if there is quoting
        in the field subsequent to the BOM, remove it as well
        because it technically takes place at the beginning of
        the name, not the middle of it.
        rrUr�Nr�)rGr��_BOMrErgr�)r�Z	first_rowZ	first_eltZ
first_row_bom�start�quote�end�new_rowrBrBrC�_check_for_bom/s*
zPythonParser._check_for_bomcCs|ptdd�|D��S)z�
        Check if a line is empty or not.

        Parameters
        ----------
        line : str, array-like
            The line of data to check.

        Returns
        -------
        boolean : Whether or not the line is empty.
        css|]}|VqdS)NrB)r�r)rBrBrCr�qsz.PythonParser._is_line_empty.<locals>.<genexpr>)r�)r�r�rBrBrC�_is_line_emptyds
zPythonParser._is_line_emptycCs�t|jt�r�x|j|j�r*|jd7_qWx�yp|j|j|jg�d}|jd7_|jr||j|j|jd�sx|r|Pn |jr�|j|g�}|r�|d}PWq.t	k
r�t
�Yq.Xq.Wn�x(|j|j�r�|jd7_t|j�q�Wxt|j|jdd�}|jd7_|dk	r�|j|g�d}|j�rH|j|g�}|�rZ|d}Pq�|j|��sX|r�Pq�W|jdk�rt|j
|�}|jd7_|jj|�|S)NrUr)�row_num)rGrar�r�r~r�r�r��_remove_empty_lines�
IndexErrorr�r��_next_iter_liner�rr}r�)r�r�r�Z	orig_linerBrBrCr�ssJ
zPythonParser._next_linecCs:|jrt|��n&|jr6d|�d�}tjj||d�dS)a�
        Alert a user about a malformed row.

        If `self.error_bad_lines` is True, the alert will be `ParserError`.
        If `self.warn_bad_lines` is True, the alert will be printed out.

        Parameters
        ----------
        msg : The error message to display.
        row_num : The row number where the parsing error occurred.
                  Because this row number is displayed, we 1-index,
                  even though we 0-index internally.
        zSkipping line z: r�N)r�rr�r��stderr�write)r�rAr��baserBrBrC�_alert_malformed�s

zPythonParser._alert_malformedcCs�y
t|j�Stjk
rz}zR|js*|jrlt|�}d|ksBd|krFd}|jdkr`d}|d|7}|j||�dSd}~XnXdS)aL
        Wrapper around iterating through `self.data` (CSV source).

        When a CSV error is raised, we check for specific
        error messages that allow us to customize the
        error message displayed to the user.

        Parameters
        ----------
        row_num : The row number of the line being parsed.
        z	NULL bytezline contains NULz�NULL byte detected. This byte cannot be processed in Python's native csv library at the moment, so please pass in engine='c' insteadrz�Error could possibly be due to parsing errors in the skipped footer rows (the skipfooter keyword is only applied after Python's csv library has parsed all rows).z. N)	r�rar��Errorr�r�r�rpr�)r�r��erA�reasonrBrBrCr��s

zPythonParser._next_iter_linecCs�|jdkr|Sg}xv|D]n}g}xZ|D]R}t|t�s@|j|krL|j|�q&|d|j|j��}t|�dkrv|j|�Pq&W|j|�qW|S)Nr)ryrGr�r��findrE)r�r�r��l�rlr)rBrBrCr��s



zPythonParser._check_commentscCsTg}xJ|D]B}t|�dksBt|�dkr
t|dt�sB|dj�r
|j|�q
W|S)a}
        Iterate through the lines and remove any that are
        either empty or contain only one whitespace value

        Parameters
        ----------
        lines : array-like
            The array of lines that we are to filter.

        Returns
        -------
        filtered_lines : array-like
            The same array of lines with the "empty" ones removed.
        rUr)rErGr�r�r�)r�r�r�r�rBrBrCr��s
z PythonParser._remove_empty_linescCs |jdkr|S|j||jdd�S)Nr�)r��search�replace)rx�_search_replace_num_columns)r�r�rBrBrC�_check_thousands
s
zPythonParser._check_thousandsc	Cs�g}x�|D]z}g}xft|�D]Z\}}t|t�sX||ksX|jrH||jksX|jj|j��rd|j|�q|j|j||��qW|j|�q
W|S)N)	rrGr�r�r�r�r�r�r�)	r�r�r�r�r�r�r�r�r)rBrBrCr�s
z(PythonParser._search_replace_num_columnscCs$|jtdkr|S|j||jdd�S)Nrzrd)r�r�r�)rzr�r�)r�r�rBrBrC�_check_decimal&szPythonParser._check_decimalcCs
g|_dS)N)r})r�rBrBrCr�.szPythonParser._clear_bufferFc	CsLt|�}t|�}y|j�}Wntk
r4d}YnXy|j�}Wntk
rZd}YnXd}|dk	r�|jdk	r�t|�|j}|dk	r�t|�t|�|jkr�ttt|���|_|jdd�|_xt|�D]}|j	d|�q�Wt|�}t|�|_|||fS|dk�r*d|_
|jdk�r$tt|��|_d}nt||j|j�\}}|_|||fS)a�
        Try several cases to get lines:

        0) There are headers on row 0 and row 1 and their
        total summed lengths equals the length of the next line.
        Treat row 0 as columns and row 1 as indices
        1) Look for implicit index: there are more columns
        on row 1 than row 0. If this is true, assume that row
        1 lists index columns and row 0 lists normal columns.
        2) Get index from the columns if it was listed.
        NrFrUT)
r�r�r�rmrEr�r�r}�reversed�insertr>r+r)	r�r�rr�Z	next_lineZimplicit_first_colsr�Z
index_nameZcolumns_rBrBrCr�3s>





zPythonParser._get_index_namecs��j}�jr|t�j�7}tdd�|D��}||koF�jdk	oF�jdk�rF�jrV�jnd}g}t|�}t|�}g}x`|D]X\}}	t|	�}
|
|krƈjs��j	rЈj
|||}|j||
f��jr�Pqx|j|	�qxWxp|D]h\}}
d|�d|d�d|
��}�j�r2t�j�dk�r2�j
tjk�r2d	}
|d
|
7}�j||d�q�Wttj||d�j�}�j�r��j�r��fdd
�t|�D�}n�fdd
�t|�D�}|S)Ncss|]}t|�VqdS)N)rE)r��rowrBrBrCr�ysz-PythonParser._rows_to_cols.<locals>.<genexpr>Frz	Expected z fields in line rUz, saw zXError could possibly be due to quotes being ignored when a multi-char delimiter is used.z. )Z	min_widthcs6g|].\}}|t�j�ks.|t�j��jkr|�qSrB)rErmr�)r�r��a)r�rBrCr�sz.PythonParser._rows_to_cols.<locals>.<listcomp>csg|]\}}|�jkr|�qSrB)r�)r�r�r�)r�rBrCr�s)r�r>rErm�maxr}rprr�r�r~r�rerhr��
QUOTE_NONEr�r�rZto_object_array�T)r�r�Zcol_len�max_lenZfootersZ	bad_lines�iter_contentZcontent_lenr�r�Z
actual_lenr�rAr�Zzipped_contentrB)r�rCr�ssD
zPythonParser._rows_to_colscs"�j}d}|dk	rPt�j�|krB�jd|��j|d�}�_n|t�j�8}|dk�r�t�jt�r�jt�j�krzt�|dkr��j�jd�}t�j�}n �j�j�j|�}�j|}�jrڇfdd�t|�D�}|j	|�|�_n�g}y||dk	�r,x"t
|�D]}|jt�j���qW|j	|�n>d}x8�j
�j|dd�}|d7}|dk	�r2|j|��q2WWnNtk
�r��j�r��fdd�t|�D�}|j	|�t|�dk�r��YnX�jt|�7_g�_n|}�j�r�|d�j�}�j|�}�j�r�j|�}�j|�}�j|�S)Ncs$g|]\}}�j|�j�s|�qSrB)r�r~)r�r�r�)r�rBrCr�sz+PythonParser._get_lines.<locals>.<listcomp>rrU)r�cs$g|]\}}�j|�j�s|�qSrB)r�r~)r�r�r�)r�rBrCr�s)r}rErGrar�r~r�rorr�r�r�r�r�rpr�r�r�r�r�)r�r�r�r��new_posrMr�rB)r�rCr��sb"










zPythonParser._get_lines)N)N)N)r�r�r�r�r�r�r]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r>r�r�r�rBrBrBrCr�	s6$?
(
-"	54'@Gr�cs����fdd�}|S)Ncs��dkr\tj|�}ytjt|�d�d��d�j�Stk
rXtjtj|�d��d�SXn�y,tj�|�d�d�}t|t	j	�r�t
d��|St
k
r�y tjtjtj|���d�dd�St
k
r�t�f|��SXYnXdS)	N�ignore)�utcr|�errorsr��cache)r|)r�)r�r�z
scalar parser)r`r|)r�)rZconcat_date_cols�toolsZto_datetimerZto_numpyr>r5rG�datetime�	Exceptionr7)�	date_cols�strsr�)rwrQr|r�rBrC�	converter
s:
z'_make_date_converter.<locals>.converterrB)rQr|r�rwr�rB)rwrQr|r�rCr	
s'rcs���fdd�}g}i}	|}
t|�}t�}|dks:t|t�rB||fSt|t�r�x�|D]�}t|�r�t|t�rx||krx|
|}||�r�qR|||�||<qRt||||
�\}
}}|
|kr�td|
����||	|
<|j|
�|j	|�qRWnlt|t
��rLx^|j�D]R\}
}|
|k�rtd|
�d���t||||
�\}}}||	|
<|j|
�|j	|�q�W|j	|	�|j|�|�s�x&t|�D]}|j
|�|j|��qpW||fS)Ncs$t�t�r|�kp"t�t�o"|�kS)N)rGr�)�colspec)rmrrBrC�_isindex?
sz*_process_date_conversion.<locals>._isindexz New date column already in dict zDate column z already in dict)r�rFrGr[r%r=�_try_convert_datesr>r�r�r�r�r�r�rB)�	data_dictr�Z
parse_specrmrr�r{r�Znew_colsZnew_datarr�r��new_namer�Z	old_namesrMr�rB)rmrrCr^6
sN	







r^c
s�t|�}g}xL|D]D}||kr*|j|�qt|t�rL||krL|j||�q|j|�qWdjdd�|D��}�fdd�|D�}||�}	||	|fS)NrMcss|]}t|�VqdS)N)r�)r�r)rBrBrCr��
sz%_try_convert_dates.<locals>.<genexpr>csg|]}|�kr�|�qSrBrB)r�r�)r�rBrCr�
sz&_try_convert_dates.<locals>.<listcomp>)rFr�rGr=r�)
r`r�r�r��colset�colnamesr�r�Zto_parseZnew_colrB)r�rCr�{
s
r�cCs�|dkr |rt}nt�}t�}n�t|t�r�|j�}i}x:|j�D].\}}t|�sV|g}|rft|�tB}|||<q@Wdd�|j�D�}n*t|�s�|g}t|�}|r�|tB}t|�}||fS)NcSsi|]\}}t|�|�qSrB)�_floatify_na_values)r�rkrprBrBrCrq�
sz$_clean_na_values.<locals>.<dictcomp>)	rrFrGr�r�r�r#�_stringify_na_valuesr�)rqrrr�Z
old_na_valuesrkrprBrBrCr��
s,
r�c	Cs�t|�sd||fSt|�}t|�}g}t|�}xxt|�D]l\}}t|t�r�|j|�xNt|�D]$\}}||kr^|||<|j|�Pq^Wq8||}|j|�|j|�q8Wx.t|�D]"\}}t|t�r�||kr�d||<q�W|||fS)N)r�r�rrGr�r�rB)	r�rmrZcp_colsrr�r�r"r?rBrBrCr+�
s*




r+c
s�t|�}t�t�s,�pt�t�fdd���nF�j�}tdd���x0|j�D]$\}}t|�rb||n|}|�|<qJW|dks�|dks�|dkr�tg�}nJ�fdd�|D�}	t	|	|d�}|j
�x"t|�D]\}
}|j||
�q�W�fdd	�|D�}|||fS)
Ncs�S)NrBrB)�
default_dtyperBrCro�
sz!_get_empty_meta.<locals>.<lambda>cSstS)N)�objectrBrBrBrCro�
sFcsg|]}tg�|d��qS))rv)r1)r�r?)rvrBrCr�
sz#_get_empty_meta.<locals>.<listcomp>)rIcsi|]}tg�|d�|�qS))rv)r1)r�rH)rvrBrCrq�
sz#_get_empty_meta.<locals>.<dictcomp>)
r�rGr�r�rr�r�r!r-r0rjrr�)
r�rmrrvZ_dtyperkrpr�r�rar�r(r�rB)r�rvrCrr�
s$

rrcCsTt�}xH|D]@}y t|�}tj|�s.|j|�Wqtttfk
rJYqXqW|S)N)rF�floatr��isnanr�r�r>�
OverflowError)rqr�rprBrBrCr�s


r�cCs�g}x�|D]�}|jt|��|j|�yHt|�}|t|�krbt|�}|j|�d��|jt|��|j|�Wntttfk
r�YnXy|jt|��Wq
tttfk
r�Yq
Xq
Wt|�S)z3 return a stringified and numeric for these values z.0)r�r�r�r=r�r>r�rF)rqr�r)rprBrBrCr�
s$


r�cCsJt|t�r>||kr"||||fS|r0tt�fSt�t�fSn||fSdS)a�
    Get the NaN values for a given column.

    Parameters
    ----------
    col : str
        The name of the column.
    na_values : array-like, dict
        The object listing the NaN values as strings.
    na_fvalues : array-like, dict
        The object listing the NaN values as floats.
    keep_default_na : bool
        If `na_values` is a dict, and the column is not mapped in the
        dictionary, whether to return the default NaN values or the empty set.

    Returns
    -------
    nan_tuple : A length-two tuple composed of

        1) na_values : the string NaN values for that column.
        2) na_fvalues : the float NaN values for that column.
    N)rGr�rrF)r�rqr�rrrBrBrCrC&s

rCcCsJt|�}g}x8|D]0}||kr*|j|�qt|t�r|j||�qW|S)N)rFr�rGr=)r�r�r�r�r�rBrBrC�_get_col_namesIs

r�c@s6eZdZdZddd�Zd
dd�Zddd	�Zd
d�ZdS)�FixedWidthReaderz(
    A reader of fixed-width lines.
    Nr�cCs�||_d|_|rd|nd|_||_|dkr>|j||d�|_n||_t|jttf�sht	dt
|�j����xd|jD]Z}t|ttf�o�t|�dko�t|dt
tjt
d�f�o�t|dt
tjt
d�f�spt	d	��qpWdS)
Nz
z

	 rP)r�roz;column specifications must be a list or tuple, input was a r�rrUzEEach column specification must be 2 element tuple or list of integers)r��bufferrery�detect_colspecsr�rGr�r�r�r�r�rEr=r�r	)r�r�r�reryror�r�rBrBrCr�Ys$zFixedWidthReader.__init__cCsf|dkrt�}g}g}x@t|j�D]2\}}||kr<|j|�|j|�t|�|kr"Pq"Wt|�|_|S)a�
        Read rows from self.f, skipping as specified.

        We distinguish buffer_rows (the first <= infer_nrows
        lines) from the rows returned to detect_colspecs
        because it's simpler to leave the other locations
        with skiprows logic alone than to modify them to
        deal with the fact we skipped some rows here as
        well.

        Parameters
        ----------
        infer_nrows : int
            Number of rows to read from self.f, not counting
            rows that are skipped.
        skiprows: set, optional
            Indices of rows to skip.

        Returns
        -------
        detect_rows : list of str
            A list containing the rows to read.

        N)rFrr�r�rEr�r�)r�r�roZbuffer_rowsZdetect_rowsr�r�rBrBrC�get_rowsws


zFixedWidthReader.get_rowsc
sdjdd��jD��}tjd|�d��}�j||�}|s@td��ttt|��}t	j
|dtd�}�jdk	r|�fd	d
�|D�}x4|D],}x&|j
|�D]}	d||	j�|	j��<q�Wq�Wt	j|d�}
d|
d<t	j||
Adk�d}tt|ddd�|ddd���}|S)
Nr�css|]}d|��VqdS)�\NrB)r�r)rBrBrCr��sz3FixedWidthReader.detect_colspecs.<locals>.<genexpr>z([^z]+)z(No rows from which to infer column widthrU)rvcsg|]}|j�j�d�qS)r)�	partitionry)r�r�)r�rBrCr�sz4FixedWidthReader.detect_colspecs.<locals>.<listcomp>rr�)r�rerXr�r�rr�rrEr��zerosr=ry�finditerr�r�Zroll�wherer�r,)
r�r�ro�
delimiters�patternr�r�rQr��mZshifted�edgesZ
edge_pairsrB)r�rCr��s"

"z FixedWidthReader.detect_colspecscs`�jdk	r@yt�j��WqJtk
r<d�_t�j��YqJXn
t�j����fdd��jD�S)Ncs$g|]\}}�||�j�j��qSrB)r�re)r�ZfrommZto)r�r�rBrCr�sz-FixedWidthReader.__next__.<locals>.<listcomp>)r�r�r�r�r�)r�rB)r�r�rCr��s

zFixedWidthReader.__next__)Nr�)N)r�N)r�r�r�r�r�r�r�r�rBrBrBrCr�Ts


&
r�c@s eZdZdZdd�Zdd�ZdS)r�zl
    Specialization that Converts fixed-width fields into DataFrames.
    See PythonParser for details.
    cKs,|jd�|_|jd�|_tj||f|�dS)Nr�r�)r�r�r�r�r�)r�r�r_rBrBrCr��szFixedWidthFieldParser.__init__cCs"t||j|j|j|j|j�|_dS)N)r�r�reryror�ra)r�r�rBrBrCr��sz"FixedWidthFieldParser._make_readerN)r�r�r�r�r�r�rBrBrBrCr��sr�)r)rPNr�)N)NFFT)F)T)N)�r��collectionsrrr�r��iorrrrXr��textwraprZtypingrrr	r
rrr
r�Znumpyr�Zpandas._libs.libZ_libsrZpandas._libs.ops�opsrYZpandas._libs.parsersrXrZpandas._libs.tslibsrZpandas._typingrrZ
pandas.errorsrrrrZpandas.util._decoratorsrZpandas.core.dtypes.castrZpandas.core.dtypes.commonrrrrrrrrr r!r"r#r$r%r&r'Zpandas.core.dtypes.dtypesr(Zpandas.core.dtypes.missingr)Zpandas.corer*Zpandas.core.arraysr+Zpandas.core.framer,Zpandas.core.indexes.apir-r.r/r0Zpandas.core.seriesr1Zpandas.core.toolsr2r�Zpandas.io.commonr3r4r5r6Zpandas.io.date_convertersr7r�r�rZ_doc_read_csv_and_tablerDrJrb�
QUOTE_MINIMALr�r�r�r�r�r�r�rFr��formatr�r�r��Iteratorr\r�r[r=r�rrrr
rrr�rxrzr�rr^r�r�r+rrr�r�rCr�r�r�rBrBrBrC�<module>s�$Hx(
4\M 
29":y
3
>
%!
,
#j