From e7d3b090fc31f77d71b5ffd189eabfb8cfe8ede0 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 4 Nov 2018 22:36:25 -0500 Subject: [PATCH 01/21] initial docstring fix at parsers.py --- pandas/io/parsers.py | 97 +++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index cd9d3ccb79af8..8485be724164d 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -1,6 +1,7 @@ """ Module contains tools for processing files into DataFrames or other objects """ + from __future__ import print_function from collections import defaultdict @@ -71,7 +72,7 @@ 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``. %s -delim_whitespace : boolean, default False +delim_whitespace : bool, default False Specifies whether or not whitespace (e.g. ``' '`` or ``'\t'``) 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`` @@ -101,7 +102,7 @@ Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider index_col=False to force pandas to _not_ - use the first column as the index (row names) + use the first column as the index (row names). usecols : list-like or callable, default None 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 @@ -120,11 +121,11 @@ 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 : boolean, default False - If the parsed data only contains one column then return a Series +squeeze : bool, default False + If the parsed data only contains one column then return a Series. prefix : str, default None Prefix to add to column numbers when no header, e.g. 'X' for X0, X1, ... -mangle_dupe_cols : boolean, default True +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. @@ -137,14 +138,14 @@ %s converters : dict, default None Dict of functions for converting values in certain columns. Keys can either - be integers or column labels + be integers or column labels. true_values : list, default None - Values to consider as True + Values to consider as True. false_values : list, default None - Values to consider as False -skipinitialspace : boolean, default False + Values to consider as False. +skipinitialspace : bool, default False Skip spaces after delimiter. -skiprows : list-like or integer or callable, default None +skiprows : list-like or int or callable, default None Line numbers to skip (0-indexed) or number of lines to skip (int) at the start of the file. @@ -152,9 +153,9 @@ 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') + Number of lines at bottom of file to skip (Unsupported with engine='c'). nrows : int, default None - Number of rows of file to read. Useful for reading pieces of large files + Number of rows of file to read. Useful for reading pieces of large files. na_values : scalar, str, list-like, or dict, default None Additional strings to recognize as NA/NaN. If dict passed, specific per-column NA values. By default the following values are interpreted as @@ -175,16 +176,17 @@ Note that if `na_filter` is passed in as False, the `keep_default_na` and `na_values` parameters will be ignored. -na_filter : boolean, default True +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 : boolean, default False - Indicate number of NA values placed in non-numeric columns -skip_blank_lines : boolean, default True - If True, skip over blank lines rather than interpreting as NaN values -parse_dates : boolean or list of ints or names or list of lists or dict, \ + 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 ints or names or list of lists or dict, \ default False + The behavior is as follows: * boolean. If True -> try parsing the index. * list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 @@ -199,12 +201,12 @@ datetime parsing, use ``pd.to_datetime`` after ``pd.read_csv`` Note: A fast-path exists for iso8601-formatted dates. -infer_datetime_format : boolean, default False +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 : boolean, default False +keep_date_col : bool, default False If True and `parse_dates` specifies combining multiple columns then keep the original columns. date_parser : function, default None @@ -217,9 +219,9 @@ 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 : boolean, default False - DD/MM format dates, international and European format -iterator : boolean, default False +dayfirst : bool, default False + DD/MM format dates, international and European format. +iterator : bool, default False Return TextFileReader object for iteration or getting chunks with ``get_chunk()``. chunksize : int, default None @@ -237,10 +239,10 @@ .. versionadded:: 0.18.1 support for 'zip' and 'xz' compression. thousands : str, default None - Thousands separator + Thousands separator. decimal : str, default '.' Character to recognize as decimal point (e.g. use ',' for European data). -float_precision : string, default None +float_precision : str, default None 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 @@ -253,7 +255,7 @@ 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 : boolean, default ``True`` +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. @@ -270,35 +272,35 @@ encoding : str, default None Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python standard encodings - `_ + `_ . dialect : str or csv.Dialect instance, default None 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. -tupleize_cols : boolean, default False +tupleize_cols : bool, default False .. deprecated:: 0.21.0 This argument will be removed and will always convert to MultiIndex Leave a list of tuples on columns as is (default is to convert to - a MultiIndex on the columns) -error_bad_lines : boolean, default True + a MultiIndex on the columns). +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 : boolean, default True +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. -low_memory : boolean, default True +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 : boolean, default False + (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. @@ -320,12 +322,13 @@ 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'`` + delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``. delimiter : str, default ``None`` - Alternative argument name for sep.""" + Alternative argument name for sep. + """ _read_csv_doc = """ -Read CSV (comma-separated) file into DataFrame +Read CSV (comma-separated) file into DataFrame. %s """ % (_parser_params % (_sep_doc.format(default="','"), _engine_doc)) @@ -1994,9 +1997,9 @@ def TextParser(*args, **kwds): rows will be discarded index_col : int or list, default None Column or columns to use as the (possibly hierarchical) index - has_index_names: boolean, default False + has_index_names: bool, default False True if the cols defined in index_col have an index name and are - not in the header + not in the header. na_values : scalar, str, list-like, or dict, default None Additional strings to recognize as NA/NaN. keep_default_na : bool, default True @@ -2004,8 +2007,8 @@ def TextParser(*args, **kwds): Thousands separator comment : str, default None Comment out remainder of line - parse_dates : boolean, default False - keep_date_col : boolean, default False + parse_dates : bool, default False + keep_date_col : bool, default False date_parser : function, default None skiprows : list of integers Row numbers to skip @@ -2016,15 +2019,15 @@ def TextParser(*args, **kwds): 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 : string, default None + encoding : str, default None Encoding to use for UTF when reading/writing (ex. 'utf-8') - squeeze : boolean, default False - returns Series if only one column - infer_datetime_format: boolean, default False + 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 : string, default None + float_precision : str, default None 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 From 692e67a4486d76a1442862e30e90866b288f9cb7 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 5 Nov 2018 14:01:05 -0500 Subject: [PATCH 02/21] fix pd.read_csv|read_table|read_fwf --- pandas/io/parsers.py | 55 +++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 8485be724164d..f906754e554e6 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -72,14 +72,6 @@ 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``. %s -delim_whitespace : bool, default False - Specifies whether or not whitespace (e.g. ``' '`` or ``'\t'``) 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. - - .. versionadded:: 0.18.1 support for the Python parser. - header : int or list of ints, 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 @@ -242,11 +234,6 @@ Thousands separator. decimal : str, default '.' Character to recognize as decimal point (e.g. use ',' for European data). -float_precision : str, default None - 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. lineterminator : str (length 1), default None Character to break file into lines. Only valid with C parser. quotechar : str (length 1), optional @@ -280,11 +267,11 @@ override values, a ParserWarning will be issued. See csv.Dialect documentation for more details. tupleize_cols : bool, default False + Leave a list of tuples on columns as is (default is to convert to + a MultiIndex on the columns). .. deprecated:: 0.21.0 This argument will be removed and will always convert to MultiIndex - Leave a list of tuples on columns as is (default is to convert to - a MultiIndex on the columns). 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. @@ -293,6 +280,14 @@ 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 ``'\t'``) 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. + + .. versionadded:: 0.18.1 support for the Python parser. + 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 @@ -304,11 +299,15 @@ 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, default None + 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 ------- -result : DataFrame or TextParser -""" +result : DataFrame or TextParser""" # engine is not used in read_fwf() so is factored out of the shared docstring _engine_doc = """engine : {'c', 'python'}, optional @@ -334,12 +333,11 @@ """ % (_parser_params % (_sep_doc.format(default="','"), _engine_doc)) _read_table_doc = """ +Read general delimited file into DataFrame. .. deprecated:: 0.24.0 Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary. -Read general delimited file into DataFrame - %s """ % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"), _engine_doc)) @@ -361,7 +359,7 @@ """ _read_fwf_doc = """ -Read a table of fixed-width formatted lines into DataFrame +Read a table of fixed-width formatted lines into DataFrame. %s """ % (_parser_params % (_fwf_widths, '')) @@ -471,10 +469,10 @@ def _read(filepath_or_buffer, kwds): _parser_defaults = { 'delimiter': None, - 'doublequote': True, 'escapechar': None, 'quotechar': '"', 'quoting': csv.QUOTE_MINIMAL, + 'doublequote': True, 'skipinitialspace': False, 'lineterminator': None, @@ -483,14 +481,16 @@ def _read(filepath_or_buffer, kwds): 'names': None, 'prefix': None, 'skiprows': None, + 'skipfooter': 0, + 'nrows': None, 'na_values': None, + 'keep_default_na': True, + 'true_values': None, 'false_values': None, 'converters': None, 'dtype': None, - 'skipfooter': 0, - 'keep_default_na': True, 'thousands': None, 'comment': None, 'decimal': b'.', @@ -500,10 +500,8 @@ def _read(filepath_or_buffer, kwds): 'keep_date_col': False, 'dayfirst': False, 'date_parser': None, - 'usecols': None, - 'nrows': None, # 'iterator': False, 'chunksize': None, 'verbose': False, @@ -576,6 +574,7 @@ def parser_f(filepath_or_buffer, false_values=None, skipinitialspace=False, skiprows=None, + skipfooter=0, nrows=None, # NA and Missing Data Handling @@ -603,6 +602,7 @@ def parser_f(filepath_or_buffer, lineterminator=None, quotechar='"', quoting=csv.QUOTE_MINIMAL, + doublequote=True, escapechar=None, comment=None, encoding=None, @@ -613,10 +613,7 @@ def parser_f(filepath_or_buffer, error_bad_lines=True, warn_bad_lines=True, - skipfooter=0, - # Internal - doublequote=True, delim_whitespace=False, low_memory=_c_parser_defaults['low_memory'], memory_map=False, @@ -668,6 +665,7 @@ def parser_f(filepath_or_buffer, names=names, prefix=prefix, skiprows=skiprows, + skipfooter=skipfooter, na_values=na_values, true_values=true_values, false_values=false_values, @@ -684,7 +682,6 @@ def parser_f(filepath_or_buffer, nrows=nrows, iterator=iterator, chunksize=chunksize, - skipfooter=skipfooter, converters=converters, dtype=dtype, usecols=usecols, From 18f5552d8b3141e6db8dac5889288093e3624af2 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 5 Nov 2018 15:24:42 -0500 Subject: [PATCH 03/21] Fix flake8 3.6 W650 Error --- pandas/io/parsers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index f906754e554e6..a816056ae1819 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -282,7 +282,7 @@ "bad line" will be output. delim_whitespace : bool, default False Specifies whether or not whitespace (e.g. ``' '`` or ``'\t'``) will be - used as the sep. Equivalent to setting ``sep='\s+'``. If this option + 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. From c0b7210df20c26651f412c737a5a746cba4ad087 Mon Sep 17 00:00:00 2001 From: thoo Date: Fri, 9 Nov 2018 21:21:03 -0500 Subject: [PATCH 04/21] Add See Also and Example --- pandas/io/parsers.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index a816056ae1819..b862e6f31724a 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -299,7 +299,7 @@ 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, default None +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 @@ -307,7 +307,15 @@ Returns ------- -result : DataFrame or TextParser""" +DataFrame or TextParser + +See Also +-------- +%s + +Examples +-------- +%s # doctest: +SKI""" # engine is not used in read_fwf() so is factored out of the shared docstring _engine_doc = """engine : {'c', 'python'}, optional @@ -323,14 +331,20 @@ 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`` - Alternative argument name for sep. + Alias for sep. """ +_see_also = ("to_csv : Write DataFrame to " + "a comma-separated values (csv) file.") + +_example_doc = "pd.{_api}('/tmp/data.csv')" + _read_csv_doc = """ Read CSV (comma-separated) file into DataFrame. %s -""" % (_parser_params % (_sep_doc.format(default="','"), _engine_doc)) +""" % (_parser_params % (_sep_doc.format(default="','"), _engine_doc, + _see_also, _example_doc.format(_api='read_csv'))) _read_table_doc = """ Read general delimited file into DataFrame. @@ -340,7 +354,8 @@ %s """ % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"), - _engine_doc)) + _engine_doc, _see_also, + _example_doc.format(_api='read_table'))) _fwf_widths = """\ colspecs : list of pairs (int, int) or 'infer'. optional @@ -362,7 +377,8 @@ Read a table of fixed-width formatted lines into DataFrame. %s -""" % (_parser_params % (_fwf_widths, '')) +""" % (_parser_params % (_fwf_widths, '', _see_also, + _example_doc.format(_api='read_fwf'))) def _validate_integer(name, val, min_val=0): From 5e851141e9d6f0bf1e832891fb110611de925faa Mon Sep 17 00:00:00 2001 From: thoo Date: Sat, 10 Nov 2018 22:07:50 -0500 Subject: [PATCH 05/21] Add more cross ref at see also section --- pandas/io/parsers.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index be1674efd2f2d..013c4461a7830 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -269,6 +269,7 @@ tupleize_cols : bool, default False Leave a list of tuples on columns as is (default is to convert to a MultiIndex on the columns). + .. deprecated:: 0.21.0 This argument will be removed and will always convert to MultiIndex @@ -311,6 +312,7 @@ See Also -------- +to_csv : Write DataFrame to a comma-separated values (csv) file. %s Examples @@ -334,17 +336,21 @@ Alias for sep. """ -_see_also = ("to_csv : Write DataFrame to " - "a comma-separated values (csv) file.") +_see_also_csv_doc = ('read_csv : Read a comma-separated values ' + '(csv) file into DataFrame.') + +_see_also_fwf_doc = ('read_fwf : Read a table of ' + 'fixed-width formatted lines into DataFrame.') _example_doc = "pd.{_api}('/tmp/data.csv')" _read_csv_doc = """ -Read CSV (comma-separated) file into DataFrame. +Read a comma-separated values (csv) file into DataFrame. %s -""" % (_parser_params % (_sep_doc.format(default="','"), _engine_doc, - _see_also, _example_doc.format(_api='read_csv'))) +""" % (_parser_params % (_sep_doc.format(default="','"), + _engine_doc, _see_also_fwf_doc, + _example_doc.format(_api='read_csv'))) _read_table_doc = """ Read general delimited file into DataFrame. @@ -354,7 +360,8 @@ %s """ % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"), - _engine_doc, _see_also, + _engine_doc, + '{}\n{}'.format(_see_also_csv_doc, _see_also_fwf_doc), _example_doc.format(_api='read_table'))) _fwf_widths = """\ @@ -377,7 +384,8 @@ Read a table of fixed-width formatted lines into DataFrame. %s -""" % (_parser_params % (_fwf_widths, '', _see_also, +""" % (_parser_params % (_fwf_widths, '', + _see_also_csv_doc, _example_doc.format(_api='read_fwf'))) From 3f5fbcde210ce357ed7b5d57f5039d086f32cfd7 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 22:15:41 -0500 Subject: [PATCH 06/21] Switch to .format from %s --- pandas/io/parsers.py | 95 ++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 013c4461a7830..e24064f15e6ff 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -53,7 +53,9 @@ # so we need to remove it if we see it. _BOM = u('\ufeff') -_parser_params = r"""Also supports optionally iterating or breaking of the file +_parser_params = r"""{summary} + +Also supports optionally iterating or breaking of the file into chunks. Additional help can be found in the `online docs for IO Tools @@ -71,7 +73,7 @@ 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``. -%s +{sep_doc} header : int or list of ints, 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 @@ -122,12 +124,12 @@ '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, default None - Data type for data or columns. E.g. {'a': np.float64, 'b': np.int32} + Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32}} 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. -%s +{engine_doc} converters : dict, default None Dict of functions for converting values in certain columns. Keys can either be integers or column labels. @@ -185,8 +187,8 @@ 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' + * dict, e.g. {{'foo' : [1, 3]}} -> parse columns 1, 3 as date and call + result 'foo' If a column or index contains an unparseable date, the entire column or index will be returned unaltered as an object data type. For non-standard @@ -221,7 +223,7 @@ See the `IO Tools docs `_ for more information on ``iterator`` and ``chunksize``. -compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer' +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 @@ -309,15 +311,32 @@ Returns ------- DataFrame or TextParser + A comma-separated values (csv) file is returned as two-dimensional + data structure with labeled axes. See Also -------- to_csv : Write DataFrame to a comma-separated values (csv) file. -%s +read_csv : Read a comma-separated values (csv) file into DataFrame. +read_fwf : Read a table of fixed-width formatted lines into DataFrame. Examples -------- -%s # doctest: +SKI""" +>>> pd.{func_name}('data.csv') # doctest: +SKIP +""" + +# Summary line for read_csv,read_table and read_fwf +_summary_read_csv = """ +Read a comma-separated values (csv) file into DataFrame.""" + +_summary_read_table = """ +Read general delimited file into DataFrame. + +.. deprecated:: 0.24.0 + Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary.""" + +_summary_read_fwf = """ +Read a table of fixed-width formatted lines into DataFrame.""" # engine is not used in read_fwf() so is factored out of the shared docstring _engine_doc = """engine : {'c', 'python'}, optional @@ -335,34 +354,24 @@ delimiter : str, default ``None`` Alias for sep. """ - -_see_also_csv_doc = ('read_csv : Read a comma-separated values ' - '(csv) file into DataFrame.') - -_see_also_fwf_doc = ('read_fwf : Read a table of ' - 'fixed-width formatted lines into DataFrame.') - -_example_doc = "pd.{_api}('/tmp/data.csv')" - -_read_csv_doc = """ -Read a comma-separated values (csv) file into DataFrame. - -%s -""" % (_parser_params % (_sep_doc.format(default="','"), - _engine_doc, _see_also_fwf_doc, - _example_doc.format(_api='read_csv'))) - -_read_table_doc = """ -Read general delimited file into DataFrame. - -.. deprecated:: 0.24.0 - Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary. - -%s -""" % (_parser_params % (_sep_doc.format(default="\\t (tab-stop)"), - _engine_doc, - '{}\n{}'.format(_see_also_csv_doc, _see_also_fwf_doc), - _example_doc.format(_api='read_table'))) +# _read_csv_doc = """ +# Read a comma-separated values (csv) file into DataFrame. + +# %s +# """ % (_parser_params % (_sep_doc.format(default="','"), +# _engine_doc, +# _example_doc.format(_api='read_csv'))) +_read_csv_doc = (_parser_params + .format(summary=_summary_read_csv, + sep_doc=_sep_doc.format(default="','"), + engine_doc=_engine_doc, + func_name='read_csv')) + +_read_table_doc = (_parser_params + .format(summary=_summary_read_table, + sep_doc=_sep_doc.format(default="\\t (tab-stop)"), + engine_doc=_engine_doc, + func_name='read_table')) _fwf_widths = """\ colspecs : list of pairs (int, int) or 'infer'. optional @@ -380,13 +389,11 @@ if it is not spaces (e.g., '~'). """ -_read_fwf_doc = """ -Read a table of fixed-width formatted lines into DataFrame. - -%s -""" % (_parser_params % (_fwf_widths, '', - _see_also_csv_doc, - _example_doc.format(_api='read_fwf'))) +_read_fwf_doc = (_parser_params + .format(summary=_summary_read_fwf, + sep_doc='', + engine_doc='', + func_name='read_fwf')) def _validate_integer(name, val, min_val=0): From d2be9b949f8e8a4dd8a23513ec3caafd53cb6e98 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 22:41:25 -0500 Subject: [PATCH 07/21] Remove comments --- pandas/io/parsers.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index e24064f15e6ff..a9b54aeeef2bd 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -354,13 +354,7 @@ delimiter : str, default ``None`` Alias for sep. """ -# _read_csv_doc = """ -# Read a comma-separated values (csv) file into DataFrame. -# %s -# """ % (_parser_params % (_sep_doc.format(default="','"), -# _engine_doc, -# _example_doc.format(_api='read_csv'))) _read_csv_doc = (_parser_params .format(summary=_summary_read_csv, sep_doc=_sep_doc.format(default="','"), From 237a024468edd000129b4ecdf93fa1a5891e0ab4 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 12 Nov 2018 13:44:03 -0500 Subject: [PATCH 08/21] remove intermediate variables --- pandas/io/parsers.py | 61 ++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index a9b54aeeef2bd..cb2ee64100728 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -53,7 +53,8 @@ # so we need to remove it if we see it. _BOM = u('\ufeff') -_parser_params = r"""{summary} +_parser_params = r""" +{summary} Also supports optionally iterating or breaking of the file into chunks. @@ -325,19 +326,6 @@ >>> pd.{func_name}('data.csv') # doctest: +SKIP """ -# Summary line for read_csv,read_table and read_fwf -_summary_read_csv = """ -Read a comma-separated values (csv) file into DataFrame.""" - -_summary_read_table = """ -Read general delimited file into DataFrame. - -.. deprecated:: 0.24.0 - Use :func:`pandas.read_csv` instead, passing ``sep='\t'`` if necessary.""" - -_summary_read_fwf = """ -Read a table of fixed-width formatted lines into DataFrame.""" - # engine is not used in read_fwf() so is factored out of the shared docstring _engine_doc = """engine : {'c', 'python'}, optional Parser engine to use. The C engine is faster while the python engine is @@ -355,18 +343,6 @@ Alias for sep. """ -_read_csv_doc = (_parser_params - .format(summary=_summary_read_csv, - sep_doc=_sep_doc.format(default="','"), - engine_doc=_engine_doc, - func_name='read_csv')) - -_read_table_doc = (_parser_params - .format(summary=_summary_read_table, - sep_doc=_sep_doc.format(default="\\t (tab-stop)"), - engine_doc=_engine_doc, - func_name='read_table')) - _fwf_widths = """\ colspecs : list of pairs (int, int) or 'infer'. optional A list of pairs (tuples) giving the extents of the fixed-width @@ -383,12 +359,6 @@ if it is not spaces (e.g., '~'). """ -_read_fwf_doc = (_parser_params - .format(summary=_summary_read_fwf, - sep_doc='', - engine_doc='', - func_name='read_fwf')) - def _validate_integer(name, val, min_val=0): """ @@ -734,13 +704,32 @@ def parser_f(filepath_or_buffer, read_csv = _make_parser_function('read_csv', default_sep=',') -read_csv = Appender(_read_csv_doc)(read_csv) +read_csv = Appender(_parser_params.format( + func_name='read_csv', + summary=('Read a comma-separated values (csv) file ' + 'into DataFrame.'), + sep_doc=_sep_doc.format(default="','"), + engine_doc=_engine_doc) + )(read_csv) read_table = _make_parser_function('read_table', default_sep='\t') -read_table = Appender(_read_table_doc)(read_table) +read_table = Appender(_parser_params.format( + func_name='read_table', + summary="""Read general delimited file into DataFrame. - -@Appender(_read_fwf_doc) +.. deprecated:: 0.24.0 +Use :func:`pandas.read_csv` instead, passing ``sep='\\t'`` if necessary.""", + sep_doc=_sep_doc.format(default="\\t (tab-stop)"), + engine_doc=_engine_doc) + )(read_table) + + +@Appender(_parser_params.format( + func_name='read_fwf', + summary=('Read a table of fixed-width formatted lines ' + 'into DataFrame.'), + sep_doc='', + engine_doc='')) def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds): # Check input arguments. if colspecs is None and widths is None: From 5d7ff542b79fc1196198515abb9b2ef18fe01648 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 12 Nov 2018 14:16:58 -0500 Subject: [PATCH 09/21] remove variable which is not used --- pandas/io/parsers.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 75b2d0366b06a..61e27d65e9fd8 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -343,22 +343,6 @@ Alias for sep. """ -_fwf_widths = """\ -colspecs : list of pairs (int, int) or 'infer'. optional - A list of pairs (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 ints. optional - A list of field widths which can be used instead of 'colspecs' if - the intervals are contiguous. -delimiter : str, default ``'\t' + ' '`` - Characters to consider as filler characters in the fixed-width file. - Can be used to specify the filler character of the fields - if it is not spaces (e.g., '~'). -""" - def _validate_integer(name, val, min_val=0): """ From 3a0a82a02c088da4b3434f321095c86fed9f7c57 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 12 Nov 2018 15:23:28 -0500 Subject: [PATCH 10/21] Retrigger circleci which had build error From bffda5583027fd0b2011b45a84a7abcb5af283d9 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 12 Nov 2018 22:28:51 -0500 Subject: [PATCH 11/21] Fix read_fwf missing parameters in docstring --- pandas/io/parsers.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 61e27d65e9fd8..6182e7e983b76 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -343,6 +343,22 @@ Alias for sep. """ +_fwf_widths = r""" +colspecs : list of pairs (int, int) or 'infer'. optional + A list of pairs (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 ints. optional + A list of field widths which can be used instead of 'colspecs' if + the intervals are contiguous. +delimiter : str, default ``'\t' + ' '`` + Characters to consider as filler characters in the fixed-width file. + Can be used to specify the filler character of the fields + if it is not spaces (e.g., '~'). +""" + def _validate_integer(name, val, min_val=0): """ @@ -712,7 +728,7 @@ def parser_f(filepath_or_buffer, func_name='read_fwf', summary=('Read a table of fixed-width formatted lines ' 'into DataFrame.'), - sep_doc='', + sep_doc=_fwf_widths, engine_doc='')) def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds): # Check input arguments. From 84b8db96b5bbd06c8abfeb842085dcd1a954c952 Mon Sep 17 00:00:00 2001 From: thoo Date: Wed, 14 Nov 2018 20:47:44 -0500 Subject: [PATCH 12/21] Add doc for **kwds and clean up docstrings --- pandas/io/parsers.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 6182e7e983b76..1208dc9933df8 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -87,24 +87,24 @@ 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 + ``skip_blank_lines=True``, so ``header=0`` denotes the first line of data rather than the first line of the file. names : array-like, default None List of column names to use. If file contains no header row, then you - should explicitly pass header=None. Duplicates in this list will cause + should explicitly pass ``header=None``. Duplicates in this list will cause a ``UserWarning`` to be issued. index_col : int or sequence or False, default None Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end - of each line, you might consider index_col=False to force pandas to _not_ - use the first column as the index (row names). + of each line, you might consider ``index_col=False`` to force pandas to + not use the first column as the index (row names). usecols : list-like or callable, default None 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]``. + `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 @@ -357,6 +357,8 @@ Characters to consider as filler characters in the fixed-width file. Can be used to specify the filler character of the fields if it is not spaces (e.g., '~'). +**kwds : optional + All the following keyword arguments can be passed. """ From 5a955003335c813a2d3bb69601c2ab36da6abc67 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 12:48:15 -0500 Subject: [PATCH 13/21] Change docstrings for read_fwf --- pandas/io/parsers.py | 84 +++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 1208dc9933df8..3ea4bf9dd5ee4 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -343,24 +343,6 @@ Alias for sep. """ -_fwf_widths = r""" -colspecs : list of pairs (int, int) or 'infer'. optional - A list of pairs (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 ints. optional - A list of field widths which can be used instead of 'colspecs' if - the intervals are contiguous. -delimiter : str, default ``'\t' + ' '`` - Characters to consider as filler characters in the fixed-width file. - Can be used to specify the filler character of the fields - if it is not spaces (e.g., '~'). -**kwds : optional - All the following keyword arguments can be passed. -""" - def _validate_integer(name, val, min_val=0): """ @@ -726,13 +708,64 @@ def parser_f(filepath_or_buffer, )(read_table) -@Appender(_parser_params.format( - func_name='read_fwf', - summary=('Read a table of fixed-width formatted lines ' - 'into DataFrame.'), - sep_doc=_fwf_widths, - engine_doc='')) -def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds): +def read_fwf(filepath_or_buffer, delimiter='\t' + ' ', + colspecs='infer', widths=None, **kwds): + + r""" + 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 + `_. + + 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 either + ``pathlib.Path`` or ``py._path.local.LocalPath``. + + 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``. + delimiter : str, default ``'\t'+' '`` + Characters to consider as filler characters in the fixed-width file. + Can be used to specify the filler character of the fields + if it is not spaces (e.g., '~'). + colspecs : list of pairs (int, int) or 'infer'. optional + A list of pairs (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 ints. optional + A list of field widths which can be used instead of 'colspecs' if + the intervals are contiguous. + **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 + -------- + 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.read_fwf('data.csv') # doctest: +SKIP + """ + # Check input arguments. if colspecs is None and widths is None: raise ValueError("Must specify either colspecs or widths") @@ -747,6 +780,7 @@ def read_fwf(filepath_or_buffer, colspecs='infer', widths=None, **kwds): colspecs.append((col, col + w)) col += w + kwds['delimiter'] = delimiter kwds['colspecs'] = colspecs kwds['engine'] = 'python-fwf' return _read(filepath_or_buffer, kwds) From e4a2bddfaa58165847753fe366448981d0f17839 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 13:38:46 -0500 Subject: [PATCH 14/21] Fix pytest error --- pandas/io/parsers.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index bd72df6864b61..86d4ab83008bf 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -726,8 +726,8 @@ def parser_f(filepath_or_buffer, )(read_table) -def read_fwf(filepath_or_buffer, delimiter='\t' + ' ', - colspecs='infer', widths=None, **kwds): +def read_fwf(filepath_or_buffer, colspecs='infer', + widths=None, **kwds): r""" Read a table of fixed-width formatted lines into DataFrame. @@ -751,10 +751,6 @@ def read_fwf(filepath_or_buffer, delimiter='\t' + ' ', 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``. - delimiter : str, default ``'\t'+' '`` - Characters to consider as filler characters in the fixed-width file. - Can be used to specify the filler character of the fields - if it is not spaces (e.g., '~'). colspecs : list of pairs (int, int) or 'infer'. optional A list of pairs (tuples) giving the extents of the fixed-width fields of each line as half-open intervals (i.e., [from, to[ ). @@ -798,7 +794,6 @@ def read_fwf(filepath_or_buffer, delimiter='\t' + ' ', colspecs.append((col, col + w)) col += w - kwds['delimiter'] = delimiter kwds['colspecs'] = colspecs kwds['engine'] = 'python-fwf' return _read(filepath_or_buffer, kwds) From 689a395bc0439caf7c688cb1ac06eac1eee8e161 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 15:03:19 -0500 Subject: [PATCH 15/21] Retrigger travis:gw1 crashed From 233e4ef877df8996c3d56ad9e83589d9cc47854a Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 16:06:32 -0500 Subject: [PATCH 16/21] modify _parser_params --- pandas/io/parsers.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 86d4ab83008bf..51c700a3531c1 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -74,7 +74,16 @@ 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_doc} +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 or list of ints, 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 @@ -130,7 +139,9 @@ to preserve and not interpret dtype. If converters are specified, they will be applied INSTEAD of dtype conversion. -{engine_doc} +engine : {{'c', 'python'}}, optional + Parser engine to use. The C engine is faster while the python engine is + currently more feature-complete. converters : dict, default None Dict of functions for converting values in certain columns. Keys can either be integers or column labels. @@ -326,23 +337,6 @@ >>> pd.{func_name}('data.csv') # doctest: +SKIP """ -# engine is not used in read_fwf() so is factored out of the shared docstring -_engine_doc = """engine : {'c', 'python'}, optional - Parser engine to use. The C engine is faster while the python engine is - currently more feature-complete.""" - -_sep_doc = r"""sep : str, default {default} - 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. - """ - def _validate_integer(name, val, min_val=0): """ @@ -710,8 +704,7 @@ def parser_f(filepath_or_buffer, func_name='read_csv', summary=('Read a comma-separated values (csv) file ' 'into DataFrame.'), - sep_doc=_sep_doc.format(default="','"), - engine_doc=_engine_doc) + _default_sep="','") )(read_csv) read_table = _make_parser_function('read_table', default_sep='\t') @@ -721,8 +714,7 @@ def parser_f(filepath_or_buffer, .. deprecated:: 0.24.0 Use :func:`pandas.read_csv` instead, passing ``sep='\\t'`` if necessary.""", - sep_doc=_sep_doc.format(default="\\t (tab-stop)"), - engine_doc=_engine_doc) + _default_sep=r'\\t (tab-stop)') )(read_table) From 0720c8ba8dc0e4d86b589bb42ec474bd9d499dfe Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 19:30:27 -0500 Subject: [PATCH 17/21] Retrigger travis:gw1 crashed From b19002bb8c8a3ac7a88c12cd105d816d0f34ea87 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 19 Nov 2018 19:56:48 -0500 Subject: [PATCH 18/21] change var name from _parser_params --- pandas/io/parsers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 51c700a3531c1..b73a81fcedb48 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -53,7 +53,7 @@ # so we need to remove it if we see it. _BOM = u('\ufeff') -_parser_params = r""" +_doc_read_csv_and_table = r""" {summary} Also supports optionally iterating or breaking of the file @@ -700,7 +700,7 @@ def parser_f(filepath_or_buffer, read_csv = _make_parser_function('read_csv', default_sep=',') -read_csv = Appender(_parser_params.format( +read_csv = Appender(_doc_read_csv_and_table.format( func_name='read_csv', summary=('Read a comma-separated values (csv) file ' 'into DataFrame.'), @@ -708,13 +708,13 @@ def parser_f(filepath_or_buffer, )(read_csv) read_table = _make_parser_function('read_table', default_sep='\t') -read_table = Appender(_parser_params.format( +read_table = Appender(_doc_read_csv_and_table.format( func_name='read_table', summary="""Read general delimited file into DataFrame. .. deprecated:: 0.24.0 Use :func:`pandas.read_csv` instead, passing ``sep='\\t'`` if necessary.""", - _default_sep=r'\\t (tab-stop)') + _default_sep=r"'\\t' (tab-stop)") )(read_table) From 5c8a3aae6f82871e0359910d08a48fca4e9bb151 Mon Sep 17 00:00:00 2001 From: thoo Date: Tue, 20 Nov 2018 11:31:14 -0500 Subject: [PATCH 19/21] Fix docstrings --- pandas/io/parsers.py | 69 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index b73a81fcedb48..acb9bca2545c0 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -84,7 +84,7 @@ delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``. delimiter : str, default ``None`` Alias for sep. -header : int or list of ints, default 'infer' +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 @@ -98,16 +98,16 @@ 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, default None +names : array-like, optional List of column names to use. If file contains no header row, then you should explicitly pass ``header=None``. Duplicates in this list will cause a ``UserWarning`` to be issued. -index_col : int or sequence or False, default None +index_col : int, sequence or bool, optional Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider ``index_col=False`` to force pandas to not use the first column as the index (row names). -usecols : list-like or callable, default None +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 @@ -127,13 +127,13 @@ parsing time and lower memory usage. squeeze : bool, default False If the parsed data only contains one column then return a Series. -prefix : str, default None +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, default None +dtype : Type name or dict of column -> type, optional Data type for data or columns. E.g. {{'a': np.float64, 'b': np.int32}} Use `str` or `object` together with suitable `na_values` settings to preserve and not interpret dtype. @@ -142,16 +142,16 @@ engine : {{'c', 'python'}}, optional Parser engine to use. The C engine is faster while the python engine is currently more feature-complete. -converters : dict, default None +converters : dict, optional Dict of functions for converting values in certain columns. Keys can either be integers or column labels. -true_values : list, default None +true_values : list, optional Values to consider as True. -false_values : list, default None +false_values : list, optional Values to consider as False. skipinitialspace : bool, default False Skip spaces after delimiter. -skiprows : list-like or int or callable, default None +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. @@ -160,9 +160,9 @@ 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, default None +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, default None +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: '""" + fill("', '".join(sorted(_NA_VALUES)), @@ -190,12 +190,12 @@ 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 ints or names or list of lists or dict, \ +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 ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 + * 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. @@ -215,7 +215,7 @@ keep_date_col : bool, default False If True and `parse_dates` specifies combining multiple columns then keep the original columns. -date_parser : function, default None +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, @@ -230,7 +230,7 @@ iterator : bool, default False Return TextFileReader object for iteration or getting chunks with ``get_chunk()``. -chunksize : int, default None +chunksize : int, optional Return TextFileReader object for iteration. See the `IO Tools docs `_ @@ -244,11 +244,11 @@ .. versionadded:: 0.18.1 support for 'zip' and 'xz' compression. -thousands : str, default None +thousands : str, optional Thousands separator. decimal : str, default '.' Character to recognize as decimal point (e.g. use ',' for European data). -lineterminator : str (length 1), default None +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 @@ -260,9 +260,9 @@ 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), default None +escapechar : str (length 1), optional One-character string used to escape delimiter when quoting is QUOTE_NONE. -comment : str, default None +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``), @@ -270,11 +270,11 @@ `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, default None +encoding : str, optional Encoding to use for UTF when reading/writing (ex. 'utf-8'). `List of Python standard encodings `_ . -dialect : str or csv.Dialect instance, default None +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 @@ -743,13 +743,13 @@ def read_fwf(filepath_or_buffer, colspecs='infer', 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 pairs (int, int) or 'infer'. optional - A list of pairs (tuples) giving the extents of the fixed-width + 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 ints. optional + widths : list of int, optional A list of field widths which can be used instead of 'colspecs' if the intervals are contiguous. **kwds : optional @@ -765,7 +765,6 @@ def read_fwf(filepath_or_buffer, colspecs='infer', -------- 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 -------- @@ -2055,37 +2054,37 @@ def TextParser(*args, **kwds): ---------- data : file-like object or list delimiter : separator character to use - dialect : str or csv.Dialect instance, default None + 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, default None + 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, default None + na_values : scalar, str, list-like, or dict, optional Additional strings to recognize as NA/NaN. keep_default_na : bool, default True - thousands : str, default None + thousands : str, optional Thousands separator - comment : str, default None + comment : str, optional Comment out remainder of line parse_dates : bool, default False keep_date_col : bool, default False - date_parser : function, default None + 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, default None + 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, default None + encoding : str, optional Encoding to use for UTF when reading/writing (ex. 'utf-8') squeeze : bool, default False returns Series if only one column. @@ -2093,7 +2092,7 @@ def TextParser(*args, **kwds): 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, default None + 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 From ef3f38a29dfe0bcd68f147eb6bb41fb43f991f74 Mon Sep 17 00:00:00 2001 From: thoo Date: Tue, 20 Nov 2018 13:17:45 -0500 Subject: [PATCH 20/21] Retrigger travis:timeout From 2bfa6ab00c0eb5cfd0aa63f7679baa67330d6068 Mon Sep 17 00:00:00 2001 From: thoo Date: Wed, 21 Nov 2018 02:19:40 -0500 Subject: [PATCH 21/21] Retrigger circleci:Falsified on the first call