8000 ENH/BUG: ignore line comments in CSV files GH2685 by holocronweaver · Pull Request #4505 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH/BUG: ignore line comments in CSV files GH2685 #4505

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
TST: add test for CSV parser line comments
  • Loading branch information
Jesse Johnson committed Aug 12, 2013
commit d680f13fd41fcd8c42a5597b93be924eec0e5153
32 changes: 22 additions & 10 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,17 +1527,29 @@ def test_multiple_date_col_multiple_index(self):

def test_comment(self):
data = """A,B,C
1,2.,4.#hello world
5.,NaN,10.0
#first line comment
1,2.,4. # first end line comment
# second line comment
3,5.,7.#second end line comment
6.,NaN,10.0
"""
expected = [[1., 2., 4.],
[5., np.nan, 10.]]
df = self.read_csv(StringIO(data), comment='#')
assert_almost_equal(df.values, expected)

df = self.read_table(StringIO(data), sep=',', comment='#',
na_values=['NaN'])
assert_almost_equal(df.values, expected)
expected = {
'c': [[np.nan, np.nan, np.nan],
[1., 2., 4.],
[np.nan, np.nan, np.nan],
[3., 5., 7.],
[6., np.nan, 10.]],
'python': [[1., 2., 4.],
[3., 5., 7.],
[6., np.nan, 10.]]
}
for engine in ('c', 'python'):
df = self.read_csv(StringIO(data), comment='#', engine=engine)
assert_almost_equal(df.values, expected[engine])

df = self.read_table(StringIO(data), sep=',', comment='#',
na_values=['NaN'], engine=engine)
assert_almost_equal(df.values, expected[engine])

def test_bool_na_values(self):
data = """A,B,C
Expand Down
0