Skip to content

Commit cf1921c

Browse files
author
abujabarmubarak
committed
ENH: Add engine='polars' support in read_csv and update version to 2.3.3.dev0
1 parent 78d74fe commit cf1921c

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

pandas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
__version__ = v.get("closest-tag", v["version"])
188188
__git_version__ = v.get("full-revisionid")
189189
del get_versions, v
190-
190+
__version__ = "2.3.3.dev0"
191191

192192
# module level doc-string
193193
__doc__ = """

pandas/io/parsers/readers.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,27 @@ def _read(
680680
if engine == "polars":
681681
try:
682682
import polars as pl # type: ignore[import-untyped]
683-
except ImportError:
684-
raise ImportError("Polars is not installed. Please install it with 'pip install polars'.")
683+
except ImportError as err:
684+
raise ImportError(
685+
"Polars is not installed. Please install it with 'pip install polars'."
686+
) from err
685687

686688
# Filter kwargs that are not supported by Polars
687689
allowed_polars_args = {
688-
"has_header", "columns", "new_columns", "skip_rows", "n_rows",
689-
"encoding", "separator", "quote_char", "comment_char", "null_values"
690+
"has_header",
691+
"columns",
692+
"new_columns",
693+
"skip_rows",
694+
"n_rows",
695+
"encoding",
696+
"separator",
697+
"quote_char",
698+
"comment_char",
699+
"null_values",
690700
}
691701
polars_kwargs = {k: v for k, v in kwds.items() if k in allowed_polars_args}
702+
# Convert Path to string for Polars compatibility
692703

693-
# Polars doesn't accept Path-like objects directly in all versions, convert to string
694704
path = str(filepath_or_buffer)
695705

696706
df = pl.read_csv(path, **polars_kwargs).to_pandas()
@@ -1825,7 +1835,7 @@ def _refine_defaults_read(
18251835
kwds["on_bad_lines"] = ParserBase.BadLineHandleMethod.WARN
18261836
elif on_bad_lines == "skip":
18271837
kwds["on_bad_lines"] = ParserBase.BadLineHandleMethod.SKIP
1828-
elif callable(on_bad_lines):
1838+
elif callable(on_bad_lines):
18291839
if engine not in ["python", "pyarrow"]:
18301840
raise ValueError(
18311841
"on_bad_line can only be a callable function "

pandas/tests/io/parser/test_read_csv_polars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3+
34
def test_read_csv_with_polars(tmp_path):
4-
pl = pytest.importorskip("polars")
55
pd = pytest.importorskip("pandas")
66

77
# Create a simple CSV file

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ build-backend = "mesonpy"
1616

1717
[project]
1818
name = 'pandas'
19-
dynamic = [
20-
'version'
21-
]
19+
version = "2.3.3.dev0"
20+
2221
description = 'Powerful data structures for data analysis, time series, and statistics'
2322
readme = 'README.md'
2423
authors = [

0 commit comments

Comments
 (0)