Skip to content

Commit 62aea0f

Browse files
authored
Backport PR pandas-dev#57173: BUG: pandas int extension dtypes has no attribute… (pandas-dev#57198)
Backport PR pandas-dev#57173: BUG: pandas int extension dtypes has no attribute byteorder
1 parent bc09d57 commit 62aea0f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/source/whatsnew/v2.2.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Fixed regressions
3030

3131
Bug fixes
3232
~~~~~~~~~
33+
- Fixed bug in :func:`pandas.api.interchange.from_dataframe` which was raising for Nullable integers (:issue:`55069`)
3334
- Fixed bug in :func:`pandas.api.interchange.from_dataframe` which was raising for empty inputs (:issue:`56700`)
3435
- Fixed bug in :meth:`DataFrame.__getitem__` for empty :class:`DataFrame` with Copy-on-Write enabled (:issue:`57130`)
3536

pandas/core/interchange/column.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pandas.core.dtypes.dtypes import (
1313
ArrowDtype,
14+
BaseMaskedDtype,
1415
DatetimeTZDtype,
1516
)
1617

@@ -143,6 +144,8 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]:
143144
byteorder = dtype.numpy_dtype.byteorder
144145
elif isinstance(dtype, DatetimeTZDtype):
145146
byteorder = dtype.base.byteorder # type: ignore[union-attr]
147+
elif isinstance(dtype, BaseMaskedDtype):
148+
byteorder = dtype.numpy_dtype.byteorder
146149
else:
147150
byteorder = dtype.byteorder
148151

pandas/tests/interchange/test_impl.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
is_platform_windows,
1010
)
1111
from pandas.compat.numpy import np_version_lt1p23
12+
import pandas.util._test_decorators as td
1213

1314
import pandas as pd
1415
import pandas._testing as tm
@@ -381,6 +382,17 @@ def test_large_string():
381382
tm.assert_frame_equal(result, expected)
382383

383384

385+
@pytest.mark.parametrize(
386+
"dtype", ["Int8", pytest.param("Int8[pyarrow]", marks=td.skip_if_no("pyarrow"))]
387+
)
388+
def test_nullable_integers(dtype: str) -> None:
389+
# https://github.com/pandas-dev/pandas/issues/55069
390+
df = pd.DataFrame({"a": [1]}, dtype=dtype)
391+
expected = pd.DataFrame({"a": [1]}, dtype="int8")
392+
result = pd.api.interchange.from_dataframe(df.__dataframe__())
393+
tm.assert_frame_equal(result, expected)
394+
395+
384396
def test_empty_dataframe():
385397
# https://github.com/pandas-dev/pandas/issues/56700
386398
df = pd.DataFrame({"a": []}, dtype="int8")

0 commit comments

Comments
 (0)