Skip to content

read_csv newline fix #10023

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 1 commit into from
May 8, 2015
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.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Bug Fixes
- Bug ``GroupBy.size`` doesn't attach index name properly if grouped by ``TimeGrouper`` (:issue:`9925`)
- Bug causing an exception in slice assignments because ``length_of_indexer`` returns wrong results (:issue:`9995`)
- Bug in csv parser causing lines with initial whitespace plus one non-space character to be skipped. (:issue:`9710`)
- Bug in C csv parser causing spurious NaNs when data started with newline followed by whitespace. (:issue:`10022`)



Expand Down
6 changes: 6 additions & 0 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,12 @@ def test_single_char_leading_whitespace(self):
result = self.read_csv(StringIO(data), skipinitialspace=True)
tm.assert_frame_equal(result, expected)

def test_chunk_begins_with_newline_whitespace(self):
# GH 10022
data = '\n hello\nworld\n'
result = self.read_csv(StringIO(data), header=None)
self.assertEqual(len(result), 2)


class TestPythonParser(ParserTests, tm.TestCase):
def test_negative_skipfooter_raises(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ int tokenize_delimited(parser_t *self, size_t line_limit)
--i;
} while (i + 1 > self->datapos && *buf != '\n');

if (i + 1 > self->datapos) // reached a newline rather than the beginning
if (*buf == '\n') // reached a newline rather than the beginning
{
++buf; // move pointer to first char after newline
++i;
Expand Down Expand Up @@ -1172,7 +1172,7 @@ int tokenize_delim_customterm(parser_t *self, size_t line_limit)
--i;
} while (i + 1 > self->datapos && *buf != self->lineterminator);

if (i + 1 > self->datapos) // reached a newline rather than the beginning
if (*buf == self->lineterminator) // reached a newline rather than the beginning
{
++buf; // move pointer to first char after newline
++i;
Expand Down