-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport PR #51976 on branch 2.0.x (BUG: read_csv for arrow with mism…
…atching dtypes does not work) (#51995) BUG: read_csv for arrow with mismatching dtypes does not work (#51976) * BUG: read_csv for arrow with mismatching dtypes does not work * Rename var
- Loading branch information
Showing
2 changed files
with
44 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas.errors import DtypeWarning | ||
|
||
import pandas._testing as tm | ||
from pandas.core.arrays import ArrowExtensionArray | ||
|
||
from pandas.io.parsers.c_parser_wrapper import _concatenate_chunks | ||
|
||
|
||
def test_concatenate_chunks_pyarrow(): | ||
# GH#51876 | ||
pa = pytest.importorskip("pyarrow") | ||
chunks = [ | ||
{0: ArrowExtensionArray(pa.array([1.5, 2.5]))}, | ||
{0: ArrowExtensionArray(pa.array([1, 2]))}, | ||
] | ||
result = _concatenate_chunks(chunks) | ||
expected = ArrowExtensionArray(pa.array([1.5, 2.5, 1.0, 2.0])) | ||
tm.assert_extension_array_equal(result[0], expected) | ||
|
||
|
||
def test_concatenate_chunks_pyarrow_strings(): | ||
# GH#51876 | ||
pa = pytest.importorskip("pyarrow") | ||
chunks = [ | ||
{0: ArrowExtensionArray(pa.array([1.5, 2.5]))}, | ||
{0: ArrowExtensionArray(pa.array(["a", "b"]))}, | ||
] | ||
with tm.assert_produces_warning(DtypeWarning, match="have mixed types"): | ||
result = _concatenate_chunks(chunks) | ||
expected = np.concatenate( | ||
[np.array([1.5, 2.5], dtype=object), np.array(["a", "b"])] | ||
) | ||
tm.assert_numpy_array_equal(result[0], expected) |