ENH: Add Polars engine to read_csv (#61813) #61983
Closed
+33
−0
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.
What does this PR do?
This PR adds support for
engine="polars"
in thepandas.read_csv()
function. It enables users to leverage the performance of the Polars DataFrame engine when reading CSV files in pandas.Why is this needed?
This enhancement addresses issue #61813. Since Polars is a high-performance DataFrame library with fast CSV parsing, adding it as an engine allows pandas users to benefit from its speed while staying within the pandas API.
What changes were made?
✅ Added Polars Support in
_read()
Function_read()
function inpandas/io/parsers/readers.py
to handleengine="polars"
polars.read_csv()
under the hood and convert the result to a pandas DataFrame using.to_pandas()
✅ Updated Engine Validation
_refine_defaults_read()
to accept"polars"
as a valid engineengine="polars"
is passed✅ Created a New Test File
test_read_csv_polars.py
insidepandas/tests/io/parser/
engine="polars"
inread_csv()
loads a simple CSV correctlyHow to use it?
This allows pandas users to benefit from Polars' speed and memory efficiency while still using the familiar pandas API.
Dependencies
Requires the user to have Polars installed:
If
polars
is not installed, the engine will raise anImportError
with instructions.Related Issues
Closes #61813
Let me know if any additional tests or validations are needed.