Skip to content
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

Fix csv2rec for passing in both names and comments. #4455

Merged
merged 3 commits into from May 22, 2015

Conversation

gatagat
Copy link
Contributor

@gatagat gatagat commented May 22, 2015

Currently csv2rec fails when parsing a CSV file with a comment if one provides the column names.

For example with a file test.txt containing:

# comment
1,2,3
4,5,6

Calling csv2rec('test.txt', names=['a', 'b', 'c']) raises an IndexError.

This PR patches it by honoring the comments argument passed to csv2rec.

@@ -2867,14 +2867,19 @@ def get_func(name, item, func):
'print': 'print_',
}

def get_converters(reader):
def get_converters(reader, comments):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to make comments optional. Perhaps defaults to an empty tuple (which is non-mutable, so it is safe). Should probably also have a line that coerces comments into a tuple since startswith() does not accept a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments is not treated as a list of chars but as a string in the whole csv2rec function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I just now notice that. And I also now see that this is not a public function, so comments doesn't need to be optional.

@tacaswell
Copy link
Member

This also brings up the question of why we have this function at all. This should probably live in either numpy or pandas.

@WeatherGod
Copy link
Member

@tacaswell, indeed, much more complicated and advanced functions do exist elsewhere. I also can guarantee you that someone will have found a way to use our reader for some type of file structure that no other reader can handle, which is why there are so many CSV readers.

I do have one nitpick question. Should commented out and blank lines count towards the checkrows tally?

Assuming Travis passes, this looks good to me and fixes a legitimate bug.

tacaswell added a commit that referenced this pull request May 22, 2015
FIX: csv2rec for passing in both names and comments.
@tacaswell tacaswell merged commit f3bf9a8 into matplotlib:master May 22, 2015
@tacaswell
Copy link
Member

@WeatherGod Should we back-port this to color_overhaul

@WeatherGod
Copy link
Member

I see it as a bugfix, so, yes.

tacaswell added a commit that referenced this pull request May 22, 2015
FIX: csv2rec for passing in both names and comments.

fixed conflicts in mlab.py in favor of the incoming changes
@tacaswell
Copy link
Member

tacaswell commented May 22, 2015

Cherry-picked as 1656f00

@QuLogic QuLogic added this to the v1.5.0 milestone Oct 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants