Cache input data read during init_separators to avoid seek/rewind. #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a basic patch that avoids calling seek or rewind after row_sep autodetection (#44) by saving the sample data and wrapping it in a StringIO object for re-reading. It passes all existing tests.
It could also be a good idea to add some new tests, e.g. using a dummy IO wrapper like in my online demonstration, to verify that the new implementation works properly with non-seekable input streams, but I have not done that yet in this patch.
Note that this patch also removes several special cases from init_separators. In particular, row_sep autodetection should now work when reading from a pipe or from ARGF or STDIN. This should probably also have some tests added for it.
I have not run any benchmarks to compare this new implementation with the previous one, but I suspect that they should be pretty close. In some cases the new code might even be faster, e.g. if (re)reading the input data is really slow for some reason.