|
9 | 9 | is_platform_windows,
|
10 | 10 | )
|
11 | 11 | from pandas.compat.numpy import np_version_lt1p23
|
12 |
| -import pandas.util._test_decorators as td |
13 | 12 |
|
14 | 13 | import pandas as pd
|
15 | 14 | import pandas._testing as tm
|
@@ -404,17 +403,50 @@ def test_non_str_names_w_duplicates():
|
404 | 403 | pd.api.interchange.from_dataframe(dfi, allow_copy=False)
|
405 | 404 |
|
406 | 405 |
|
407 |
| -@pytest.mark.parametrize( |
408 |
| - "dtype", ["Int8", pytest.param("Int8[pyarrow]", marks=td.skip_if_no("pyarrow"))] |
409 |
| -) |
410 |
| -def test_nullable_integers(dtype: str) -> None: |
| 406 | +def test_nullable_integers() -> None: |
| 407 | + # https://github.com/pandas-dev/pandas/issues/55069 |
| 408 | + df = pd.DataFrame({"a": [1]}, dtype="Int8") |
| 409 | + expected = pd.DataFrame({"a": [1]}, dtype="int8") |
| 410 | + result = pd.api.interchange.from_dataframe(df.__dataframe__()) |
| 411 | + tm.assert_frame_equal(result, expected) |
| 412 | + |
| 413 | + |
| 414 | +@pytest.mark.xfail(reason="https://github.com/pandas-dev/pandas/issues/57664") |
| 415 | +def test_nullable_integers_pyarrow() -> None: |
411 | 416 | # https://github.com/pandas-dev/pandas/issues/55069
|
412 |
| - df = pd.DataFrame({"a": [1]}, dtype=dtype) |
| 417 | + df = pd.DataFrame({"a": [1]}, dtype="Int8[pyarrow]") |
413 | 418 | expected = pd.DataFrame({"a": [1]}, dtype="int8")
|
414 | 419 | result = pd.api.interchange.from_dataframe(df.__dataframe__())
|
415 | 420 | tm.assert_frame_equal(result, expected)
|
416 | 421 |
|
417 | 422 |
|
| 423 | +@pytest.mark.parametrize( |
| 424 | + ("data", "dtype", "expected_dtype"), |
| 425 | + [ |
| 426 | + ([1, 2, None], "Int64", "int64"), |
| 427 | + ( |
| 428 | + [1, 2, None], |
| 429 | + "UInt64", |
| 430 | + "uint64", |
| 431 | + ), |
| 432 | + ([1.0, 2.25, None], "Float32", "float32"), |
| 433 | + ], |
| 434 | +) |
| 435 | +def test_pandas_nullable_w_missing_values( |
| 436 | + data: list, dtype: str, expected_dtype: str |
| 437 | +) -> None: |
| 438 | + # https://github.com/pandas-dev/pandas/issues/57643 |
| 439 | + pytest.importorskip("pyarrow", "11.0.0") |
| 440 | + import pyarrow.interchange as pai |
| 441 | + |
| 442 | + df = pd.DataFrame({"a": data}, dtype=dtype) |
| 443 | + result = pai.from_dataframe(df.__dataframe__())["a"] |
| 444 | + assert result.type == expected_dtype |
| 445 | + assert result[0].as_py() == data[0] |
| 446 | + assert result[1].as_py() == data[1] |
| 447 | + assert result[2].as_py() is None |
| 448 | + |
| 449 | + |
418 | 450 | def test_empty_dataframe():
|
419 | 451 | # https://github.com/pandas-dev/pandas/issues/56700
|
420 | 452 | df = pd.DataFrame({"a": []}, dtype="int8")
|
|
0 commit comments