Skip to content

BUG: Add numpy_nullable support to arrow csv parser #51985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/io/parsers/arrow_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pandas as pd
from pandas import DataFrame

from pandas.io._util import _arrow_dtype_mapping
from pandas.io.parsers.base_parser import ParserBase

if TYPE_CHECKING:
Expand Down Expand Up @@ -151,6 +152,8 @@ def read(self) -> DataFrame:
)
if self.kwds["dtype_backend"] == "pyarrow":
frame = table.to_pandas(types_mapper=pd.ArrowDtype)
elif self.kwds["dtype_backend"] == "numpy_nullable":
frame = table.to_pandas(types_mapper=_arrow_dtype_mapping().get)
else:
frame = table.to_pandas()
return self._finalize_pandas_output(frame)
9 changes: 6 additions & 3 deletions pandas/tests/io/parser/dtypes/test_dtypes_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ def test_dtypes_defaultdict_invalid(all_parsers):
parser.read_csv(StringIO(data), dtype=dtype)


@pytest.mark.usefixtures("pyarrow_xfail")
def test_dtype_backend(all_parsers):
# GH#36712

Expand All @@ -424,9 +423,13 @@ def test_dtype_backend(all_parsers):
"e": pd.Series([pd.NA, 6], dtype="Int64"),
"f": pd.Series([pd.NA, 7.5], dtype="Float64"),
"g": pd.Series([pd.NA, True], dtype="boolean"),
"h": pd.Series([pd.NA, "a"], dtype="string"),
"h": pd.Series(
[pd.NA if parser.engine != "pyarrow" else "", "a"], dtype="string"
),
"i": pd.Series([Timestamp("2019-12-31")] * 2),
"j": pd.Series([pd.NA, pd.NA], dtype="Int64"),
"j": pd.Series(
[pd.NA, pd.NA], dtype="Int64" if parser.engine != "pyarrow" else object
),
}
)
tm.assert_frame_equal(result, expected)
Expand Down