Skip to content

Commit e03bfcd

Browse files
committed
revert skip_footer API change. use nrows instead
1 parent b3af89b commit e03bfcd

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

doc/source/io.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ data into a DataFrame object. They can take a number of arguments:
7676
Defaults to 0 (first row); specify None if there is no header row.
7777
- ``skiprows``: A collection of numbers for rows in the file to skip. Can
7878
also be an integer to skip the first ``n`` rows
79-
- ``skip_footer``: Lines at bottom of file to skip. If >0 then indicates the
80-
row to start skipping. If <0 then skips the specified number of rows from
81-
the end.
8279
- ``index_col``: column number, column name, or list of column numbers/names,
8380
to use as the ``index`` (row labels) of the resulting DataFrame. By default,
8481
it will number the rows without using any column, unless there is one more
@@ -119,6 +116,7 @@ data into a DataFrame object. They can take a number of arguments:
119116
- ``chunksize``: An number of rows to be used to "chunk" a file into
120117
pieces. Will cause an ``TextParser`` object to be returned. More on this
121118
below in the section on :ref:`iterating and chunking <io.chunking>`
119+
- ``skip_footer``: number of lines to skip at bottom of file (default 0)
122120
- ``converters``: a dictionary of functions for converting values in certain
123121
columns, where keys are either integers or column labels
124122
- ``encoding``: a string representing the encoding to use if the contents are

pandas/io/parsers.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class DateConversionError(Exception):
4747
skiprows : list-like or integer
4848
Row numbers to skip (0-indexed) or number of rows to skip (int)
4949
at the start of the file
50-
skip_footer : int, default 0
51-
Lines at bottom of file to skip. If >0 then indicates the row to start
52-
skipping. If <0 then skips the specified number of rows from the end.
5350
index_col : int or sequence, default None
5451
Column to use as the row labels of the DataFrame. If a sequence is
5552
given, a MultiIndex is used.
@@ -85,6 +82,8 @@ class DateConversionError(Exception):
8582
Return TextParser object
8683
chunksize : int, default None
8784
Return TextParser object for iteration
85+
skip_footer : int, default 0
86+
Number of line at bottom of file to skip
8887
converters : dict. optional
8988
Dict of functions for converting values in certain columns. Keys can either
9089
be integers or column labels
@@ -478,7 +477,7 @@ def __init__(self, f, delimiter=None, dialect=None, names=None, header=0,
478477
else:
479478
self.converters = {}
480479

481-
#assert(self.skip_footer >= 0)
480+
assert(self.skip_footer >= 0)
482481

483482
self.keep_default_na = keep_default_na
484483
if na_values is None and keep_default_na:
@@ -783,10 +782,8 @@ def _rows_to_cols(self, content):
783782
footers = 0
784783
if self.skip_footer:
785784
footers = self.skip_footer
786-
if footers > 0:
787-
footers = footers - self.pos
788-
row_num = self.pos - (len(content) - i - footers)
789785

786+
row_num = self.pos - (len(content) - i + footers)
790787
msg = ('Expecting %d columns, got %d in row %d' %
791788
(col_len, zip_len, row_num))
792789
raise ValueError(msg)
@@ -1108,7 +1105,7 @@ def _get_lines(self, rows=None):
11081105
self.buf = []
11091106

11101107
if self.skip_footer:
1111-
lines = lines[:self.skip_footer]
1108+
lines = lines[:-self.skip_footer]
11121109

11131110
lines = self._check_comments(lines)
11141111
return self._check_thousands(lines)

pandas/io/tests/test_parsers.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def test_malformed(self):
437437

438438
try:
439439
df = read_table(StringIO(data), sep=',', header=1, comment='#',
440-
skip_footer=-1)
440+
skip_footer=1)
441441
self.assert_(False)
442442
except ValueError, inst:
443443
self.assert_('Expecting 3 columns, got 5 in row 3' in str(inst))
@@ -1114,15 +1114,15 @@ def test_skip_footer(self):
11141114
7,8,9
11151115
want to skip this
11161116
also also skip this
1117-
and this
11181117
"""
1119-
result = read_csv(StringIO(data), skip_footer=-3)
1120-
no_footer = '\n'.join(data.split('\n')[:-4])
1118+
result = read_csv(StringIO(data), skip_footer=2)
1119+
no_footer = '\n'.join(data.split('\n')[:-3])
11211120
expected = read_csv(StringIO(no_footer))
11221121

11231122
assert_frame_equal(result, expected)
11241123

1125-
result = read_csv(StringIO(data), skip_footer=3)
1124+
# equivalent to nrows
1125+
result = read_csv(StringIO(data), nrows=3)
11261126
assert_frame_equal(result, expected)
11271127

11281128
def test_no_unnamed_index(self):

0 commit comments

Comments
 (0)