You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find it necessary to specify an explicit date parser when reading certain CSV files because read_csv(..., error_bad_lines=True) does not recognize errors that fall within the index column; it falls back to string-indexing instead. I've dealt with this by specifying coerce=True, but that method is deprecated since #10653 combined the coerce and errors keywords. Now, neither method appears to work for me.
K:\temp.py:24: FutureWarning: the coerce=True keyword is deprecated, use errors='coerce' instead
coerce=True),
Traceback (most recent call last):
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2276, in converter
date_parser(*date_cols), errors='ignore')
File "K:\temp.py", line 24, in <lambda>
coerce=True),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
TypeError: to_datetime() got multiple values for argument 'errors'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2285, in converter
dayfirst=dayfirst),
File "pandas\src\inference.pyx", line 841, in pandas.lib.try_parse_dates (pandas\lib.c:57884)
File "pandas\src\inference.pyx", line 838, in pandas.lib.try_parse_dates (pandas\lib.c:57802)
File "K:\temp.py", line 24, in <lambda>
coerce=True),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
TypeError: to_datetime() got multiple values for argument 'errors'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "K:\temp.py", line 28, in <module>
keep_default_na=False)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 562, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 325, in _read
return parser.read()
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 815, in read
ret = self._engine.read(nrows)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1387, in read
index, names = self._make_index(data, alldata, names)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1030, in _make_index
index = self._agg_index(index)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1111, in _agg_index
arr = self._date_conv(arr)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2288, in converter
return generic_parser(date_parser, *date_cols)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\date_converters.py", line 38, in generic_parser
results[i] = parse_func(*args)
File "K:\temp.py", line 24, in <lambda>
coerce=True),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
TypeError: to_datetime() got multiple values for argument 'errors'
Neither does removing bothcoerce and errors arguments:
Traceback (most recent call last):
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2276, in converter
date_parser(*date_cols), errors='ignore')
File "K:\temp.py", line 23, in <lambda>
date_parser=lambda ts: pd.to_datetime(ts, '%Y-%m-%d %H:%M:%S'),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 291, in to_datetime
unit=unit, infer_datetime_format=infer_datetime_format)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 427, in _to_datetime
return _convert_listlike(arg, box, format)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 398, in _convert_listlike
require_iso8601=require_iso8601
File "pandas\tslib.pyx", line 2134, in pandas.tslib.array_to_datetime (pandas\tslib.c:41972)
File "pandas\tslib.pyx", line 2150, in pandas.tslib.array_to_datetime (pandas\tslib.c:38535)
AssertionError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2285, in converter
dayfirst=dayfirst),
File "pandas\src\inference.pyx", line 841, in pandas.lib.try_parse_dates (pandas\lib.c:57884)
File "pandas\src\inference.pyx", line 838, in pandas.lib.try_parse_dates (pandas\lib.c:57802)
File "K:\temp.py", line 23, in <lambda>
date_parser=lambda ts: pd.to_datetime(ts, '%Y-%m-%d %H:%M:%S'),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 291, in to_datetime
unit=unit, infer_datetime_format=infer_datetime_format)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 429, in _to_datetime
return _convert_listlike(np.array([arg]), box, format)[0]
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 398, in _convert_listlike
require_iso8601=require_iso8601
File "pandas\tslib.pyx", line 2134, in pandas.tslib.array_to_datetime (pandas\tslib.c:41972)
File "pandas\tslib.pyx", line 2150, in pandas.tslib.array_to_datetime (pandas\tslib.c:38535)
AssertionError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "K:\temp.py", line 28, in <module>
keep_default_na=False)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 562, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 325, in _read
return parser.read()
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 815, in read
ret = self._engine.read(nrows)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1387, in read
index, names = self._make_index(data, alldata, names)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1030, in _make_index
index = self._agg_index(index)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1111, in _agg_index
arr = self._date_conv(arr)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2288, in converter
return generic_parser(date_parser, *date_cols)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\date_converters.py", line 38, in generic_parser
results[i] = parse_func(*args)
File "K:\temp.py", line 23, in <lambda>
date_parser=lambda ts: pd.to_datetime(ts, '%Y-%m-%d %H:%M:%S'),
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\util\decorators.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 291, in to_datetime
unit=unit, infer_datetime_format=infer_datetime_format)
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 429, in _to_datetime
return _convert_listlike(np.array([arg]), box, format)[0]
File "C:\Users\pokeeffe\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\tseries\tools.py", line 398, in _convert_listlike
require_iso8601=require_iso8601
File "pandas\tslib.pyx", line 2134, in pandas.tslib.array_to_datetime (pandas\tslib.c:41972)
File "pandas\tslib.pyx", line 2150, in pandas.tslib.array_to_datetime (pandas\tslib.c:38535)
AssertionError
To be clear, I can still use coerce=True in older versions of pandas. For example, in 0.15.2, both of these work fine:
You need to specify format as a keyword argument - errors is the first positional argument. The error message is a little weird because to_datetime has a decorator that handles deprecated arguments, not sure if anything can be done about that.
Perfect thank you! Looks like I've only been explicit with the format= keyword about half the time so I expect I'll be running into this a lot. The tracebacks were sending me the wrong direction but I can't think of a much better error message.
I find it necessary to specify an explicit date parser when reading certain CSV files because
read_csv(..., error_bad_lines=True)
does not recognize errors that fall within the index column; it falls back to string-indexing instead. I've dealt with this by specifyingcoerce=True
, but that method is deprecated since #10653 combined thecoerce
anderrors
keywords. Now, neither method appears to work for me.Here is the test snippet:
Machine 1
Here's the traceback I received on my Linux Mint box (before reducing to MWE):
using pandas 0.18.1 (freshly updated) with Python 2.7 (Sorry, I don't have
pd.show_versions()
output...)Machine 2
When I run the same snippet on Windows 7 with pandas 0.18.1, Python 3.5.1:
Machine 2 (again)
Strangely, I get the same error using a different (older) distribution on the same Win7 machine:
Machine 3
Different physical hardware, same test snippet and same environment (Anaconda3-4.1.0-Windows-x86_64)...
...produced the same traceback.
The Hang-Up
I would have just ignored the deprecation warning and continued to use
coerce=True
, except now I can't get back into a working state...Reverting to
coerce=True
does not halt the "multiple values for argument 'errors' traceback:produces
Neither does removing both
coerce
anderrors
arguments:produces
To be clear, I can still use
coerce=True
in older versions of pandas. For example, in 0.15.2, both of these work fine:Whew! I know that was a lot of scrolling sorry
The text was updated successfully, but these errors were encountered: