feat(rust, python): add encoding
parameter to write_csv
#10326
Closed
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.
Motivation
In some circumstances, a CSV file should have an encoding other than
utf-8
. An example use case is a CSV file that is used to bulk-insert data into SQL Server where a more efficient single-byte encoding (e.g. Windows-1252) allows for smaller columns.Changes
encoding
parameter towrite_csv
which allows for all values thatencoding_rs
supportsTranscodingWriter
which implements theWrite
trait and allows to transcode a UTF-8 stream into another character encodingBenchmark
Encoding to anything but UTF-8 is rather slow. Transcoding itself incurs a performance penalty of ~50% (i.e. if explicitly transcoding from UTF-8 to UTF-8). Encoding to Windows-1252 takes 8x longer than encoding to UTF-8.