Skip to content
Closed
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
19 changes: 6 additions & 13 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3025,18 +3025,14 @@ def test_array_protocol():
if LooseVersion(pd.__version__) < '0.24.0':
pytest.skip('IntegerArray only introduced in 0.24')

def __arrow_array__(self, type=None):
return pa.array(self._data, mask=self._mask, type=type)

df = pd.DataFrame({'a': pd.Series([1, 2, None], dtype='Int64')})

# with latest pandas/arrow, trying to convert nullable integer errors
with pytest.raises(TypeError):
pa.table(df)

try:
# patch IntegerArray with the protocol
pd.arrays.IntegerArray.__arrow_array__ = __arrow_array__
if LooseVersion(pd.__version__) < '0.26.0.dev':
# with pandas<=0.25, trying to convert nullable integer errors
with pytest.raises(TypeError):
pa.table(df)
else:
# __arrow_array__ added to pandas IntegerArray in 0.26.0.dev

# default conversion
result = pa.table(df)
Expand All @@ -3061,9 +3057,6 @@ def __arrow_array__(self, type=None):
result = pa.array(df['a'].values, type=pa.float64())
assert result.equals(expected2)

finally:
del pd.arrays.IntegerArray.__arrow_array__


# ----------------------------------------------------------------------
# Legacy metadata compatibility tests
Expand Down