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