Skip to content

Commit 5f05027

Browse files
committed
Add test for missing values support and restructure string tests
1 parent 840bac9 commit 5f05027

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

python/pyarrow/tests/interchange/test_conversion.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,20 @@ def test_roundtrip_pandas_string():
216216
assert table_protocol.num_chunks() == result_protocol.num_chunks()
217217
assert table_protocol.column_names() == result_protocol.column_names()
218218

219+
220+
@pytest.mark.pandas
221+
def test_roundtrip_pandas_large_string():
222+
# See https://github.com/pandas-dev/pandas/issues/50554
223+
if Version(pd.__version__) < Version("1.6"):
224+
pytest.skip(" Column.size() called as a method in pandas 2.0.0")
225+
226+
arr = ["a", "", "c"]
219227
table = pa.table({"a_large": pa.array(arr, type=pa.large_string())})
220228

229+
from pandas.api.interchange import (
230+
from_dataframe as pandas_from_dataframe
231+
)
232+
221233
if Version(pd.__version__) >= Version("2.0.1"):
222234
pandas_df = pandas_from_dataframe(table)
223235
result = pi.from_dataframe(pandas_df)
@@ -237,10 +249,43 @@ def test_roundtrip_pandas_string():
237249
else:
238250
# large string not supported by pandas implementation for
239251
# older versions of pandas
252+
# https://github.com/pandas-dev/pandas/issues/52795
240253
with pytest.raises(AssertionError):
241254
pandas_from_dataframe(table)
242255

243256

257+
@pytest.mark.pandas
258+
def test_roundtrip_pandas_string_with_missing():
259+
# See https://github.com/pandas-dev/pandas/issues/50554
260+
if Version(pd.__version__) < Version("1.6"):
261+
pytest.skip(" Column.size() called as a method in pandas 2.0.0")
262+
263+
arr = ["a", "", "c", None]
264+
table = pa.table({"a": pa.array(arr),
265+
"a_large": pa.array(arr, type=pa.large_string())})
266+
267+
from pandas.api.interchange import (
268+
from_dataframe as pandas_from_dataframe
269+
)
270+
271+
if Version(pd.__version__) >= Version("2.0.2"):
272+
pandas_df = pandas_from_dataframe(table)
273+
result = pi.from_dataframe(pandas_df)
274+
275+
assert result["a"].to_pylist() == table["a"].to_pylist()
276+
assert pa.types.is_string(table["a"].type)
277+
assert pa.types.is_large_string(result["a"].type)
278+
279+
assert result["a_large"].to_pylist() == table["a_large"].to_pylist()
280+
assert pa.types.is_large_string(table["a_large"].type)
281+
assert pa.types.is_large_string(result["a_large"].type)
282+
else:
283+
# older versions of pandas do not have bitmask support
284+
# https://github.com/pandas-dev/pandas/issues/49888
285+
with pytest.raises(NotImplementedError):
286+
pandas_from_dataframe(table)
287+
288+
244289
@pytest.mark.pandas
245290
def test_roundtrip_pandas_boolean():
246291
if Version(pd.__version__) < Version("1.5.0"):

0 commit comments

Comments
 (0)