Skip to content

TST: check compatibility with pyarrow types_mapper parameter #44369

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 12 commits into from
Dec 1, 2021
18 changes: 18 additions & 0 deletions pandas/tests/extension/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,21 @@ class TestParsing(base.BaseParsingTests):

class Test2DCompat(base.Dim2CompatTests):
pass


def test_from_arrow(dtype):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might need to use a min version here in the skip and use the decorator version like
td.skip_if_no("pyarrow", min_version="1.0.0")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also move the test to /tests/arrays/boolean/ ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more specifically, we have tests for arrow compat in tests/arrays/masked/test_arrow_compat.py. I would add it there (or first check if it's not actually already covered)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/arrays/masked/test_arrow_compat.py looks more low-level than what I'm aiming to test here, but a combo test there could make sense.

pyarrow = pytest.importorskip("pyarrow")

def types_mapper(arrow_type):
if pyarrow.types.is_boolean(arrow_type):
return dtype

pyarrow_array = pyarrow.array([True, None, False], type=pyarrow.bool_())
expected = pd.Series([True, None, False], dtype=dtype.name)

# Convert to RecordBatch because types_mapper argument is ignored when
# using a pyarrow.Array. https://issues.apache.org/jira/browse/ARROW-9664
record_batch = pyarrow.RecordBatch.from_arrays([pyarrow_array], ["test_col"])
dataframe = record_batch.to_pandas(types_mapper=types_mapper)
series = dataframe["test_col"]
tm.assert_series_equal(series, expected, check_names=False)