Skip to content

ERR: Fail-fast with incompatible skipfooter combos #23711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
- Bug in :func:`DataFrame.to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`)
- Bug in :func:`DataFrame.to_csv` where a single level MultiIndex incorrectly wrote a tuple. Now just the value of the index is written (:issue:`19589`).
- Bug in :meth:`HDFStore.append` when appending a :class:`DataFrame` with an empty string column and ``min_itemsize`` < 8 (:issue:`12242`)
- Bug in :func:`read_csv()` in which incorrect error messages were being raised when ``skipfooter`` was passed in along with ``nrows``, ``iterator``, or ``chunksize`` (:issue:`23711`)
- Bug in :meth:`read_csv()` in which :class:`MultiIndex` index names were being improperly handled in the cases when they were not provided (:issue:`23484`)
- Bug in :meth:`read_html()` in which the error message was not displaying the valid flavors when an invalid one was provided (:issue:`23549`)
- Bug in :meth:`read_excel()` in which ``index_col=None`` was not being respected and parsing index columns anyway (:issue:`20480`)
Expand Down
11 changes: 6 additions & 5 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,12 @@ def __init__(self, f, engine=None, **kwds):
stacklevel=2)
kwds[param] = dialect_val

if kwds.get("skipfooter"):
if kwds.get("iterator") or kwds.get("chunksize"):
raise ValueError("'skipfooter' not supported for 'iteration'")
if kwds.get("nrows"):
raise ValueError("'skipfooter' not supported with 'nrows'")

if kwds.get('header', 'infer') == 'infer':
kwds['header'] = 0 if kwds.get('names') is None else None

Expand Down Expand Up @@ -1054,11 +1060,6 @@ def _failover_to_python(self):

def read(self, nrows=None):
nrows = _validate_integer('nrows', nrows)

if nrows is not None:
if self.options.get('skipfooter'):
raise ValueError('skipfooter not supported for iteration')

ret = self._engine.read(nrows)

# May alter columns / col_dict
Expand Down
21 changes: 15 additions & 6 deletions pandas/tests/io/parser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,21 @@ def test_iterator(self):
assert len(result) == 3
tm.assert_frame_equal(pd.concat(result), expected)

# skipfooter is not supported with the C parser yet
if self.engine == 'python':
# test bad parameter (skipfooter)
reader = self.read_csv(StringIO(self.data1), index_col=0,
iterator=True, skipfooter=1)
pytest.raises(ValueError, reader.read, 3)
@pytest.mark.parametrize("kwargs", [
dict(iterator=True,
chunksize=1),
dict(iterator=True),
dict(chunksize=1)
])
def test_iterator_skipfooter_errors(self, kwargs):
msg = "'skipfooter' not supported for 'iteration'"
with pytest.raises(ValueError, match=msg):
self.read_csv(StringIO(self.data1), skipfooter=1, **kwargs)

def test_nrows_skipfooter_errors(self):
msg = "'skipfooter' not supported with 'nrows'"
with pytest.raises(ValueError, match=msg):
self.read_csv(StringIO(self.data1), skipfooter=1, nrows=5)

def test_pass_names_with_index(self):
lines = self.data1.split('\n')
Expand Down