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

Specified two-column csv file #78

Merged
merged 10 commits into from
Apr 16, 2024
Merged

Specified two-column csv file #78

merged 10 commits into from
Apr 16, 2024

Conversation

JayHuLBL
Copy link
Contributor

This closes #76.

@JayHuLBL JayHuLBL self-assigned this Mar 27, 2024
Copy link
Collaborator

@AntoineGautier AntoineGautier left a comment

Choose a reason for hiding this comment

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

Please see my inline comments.

@@ -89,6 +89,8 @@
data[s] = dict(x=[], y=[])
with open(vars(args)[s]) as csvfile:
spamreader = csv.reader(csvfile)
if (len(next(spamreader)) != 2):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe that if you use next here, the next iteration on the iterator (for loop below) starts at index 1 and not 0, i.e., the first row is skipped.
Why not test len(spamreader[0])? Or each line within the for loop: len(row)?

@@ -89,6 +89,8 @@
data[s] = dict(x=[], y=[])
with open(vars(args)[s]) as csvfile:
spamreader = csv.reader(csvfile)
if (len(next(spamreader)) != 2):
raise RuntimeError("The {} CSV file must have exactly two columns.".format(s))
Copy link
Collaborator

@AntoineGautier AntoineGautier Apr 3, 2024

Choose a reason for hiding this comment

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

Shouldn't this rather be an IOError?

@JayHuLBL
Copy link
Contributor Author

@AntoineGautier Please see the updated one.

@AntoineGautier
Copy link
Collaborator

AntoineGautier commented Apr 15, 2024

@JayHuLBL In d067463 I propose to keep the iterable object (rather than casting it into a list which is potentially less memory-efficient) and check the length of each row. My thinking is that, if the CSV is corrupted with, e.g., an element missing at row 10000, the user will have better error information this way. If you want to revert back to checking only the first row, maybe keeping the iterable object and checking len(list(spamreader)[0]) would be best.

@JayHuLBL JayHuLBL merged commit 0e6812f into master Apr 16, 2024
6 checks passed
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.

Better documentation and error handling on two-column CSV file limitation
3 participants