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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2867,14 +2867,20 @@ def get_func(name, item, func): | |
'print': 'print_', | ||
} | ||
|
||
def get_converters(reader): | ||
def get_converters(reader, comments): | ||
|
||
converters = None | ||
for i, row in enumerate(reader): | ||
i = 0 | ||
for row in reader: | ||
if (len(row) and comments is not None and | ||
row[0].startswith(comments)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, we are only checking a single character, so maybe it might make more sense to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do rows come out stripped? Do we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the same test is used in the main loop of |
||
continue | ||
if i == 0: | ||
converters = [mybool]*len(row) | ||
if checkrows and i > checkrows: | ||
break | ||
i += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a blank line after this for readability? |
||
|
||
for j, (name, item) in enumerate(zip(names, row)): | ||
func = converterd.get(j) | ||
if func is None: | ||
|
@@ -2925,7 +2931,7 @@ def get_converters(reader): | |
names = [n.strip() for n in names.split(',')] | ||
|
||
# get the converter functions by inspecting checkrows | ||
converters = get_converters(reader) | ||
converters = get_converters(reader, comments) | ||
if converters is None: | ||
raise ValueError('Could not find any valid data in CSV file') | ||
|
||
|
There was a problem hiding this comment.
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 coercescomments
into a tuple sincestartswith()
does not accept a list.There was a problem hiding this comment.
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 wholecsv2rec
function.There was a problem hiding this comment.
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.