Skip to content

Commit

Permalink
fix newline windows issue in generate_csv (#675)
Browse files Browse the repository at this point in the history
Summary:
Fixes #674

### Changes

updated tutorial in documentation to specify the newline explitly
`writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w", newline=''), fieldnames=fieldnames)`

instead of:
`writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w"), fieldnames=fieldnames)`

## Testing
- tested by running the generate_csv function before and after on a windows machine, before was creating newlines between lines and throwing errors, after the created files don't have newlines and full tutorial works

Pull Request resolved: #675

Reviewed By: ejguan

Differential Revision: D38116301

Pulled By: NivekT

fbshipit-source-id: 1885c40cdc739ca70c5236e983389d88f662b2d4
  • Loading branch information
Diamond Bishop authored and facebook-github-bot committed Jul 25, 2022
1 parent e24ed5d commit 514982f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ For this example, we will first have a helper function that generates some CSV f
def generate_csv(file_label, num_rows: int = 5000, num_features: int = 20) -> None:
fieldnames = ['label'] + [f'c{i}' for i in range(num_features)]
writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w"), fieldnames=fieldnames)
writer = csv.DictWriter(open(f"sample_data{file_label}.csv", "w", newline=''), fieldnames=fieldnames)
writer.writeheader()
for i in range(num_rows):
row_data = {col: random.random() for col in fieldnames}
Expand Down

0 comments on commit 514982f

Please sign in to comment.