diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3a4e8fdd91362..3424b990a746c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -893,8 +893,8 @@ def __dataframe__( Parameters ---------- nan_as_null : bool, default False - Whether to tell the DataFrame to overwrite null values in the data - with ``NaN`` (or ``NaT``). + `nan_as_null` is DEPRECATED and has no effect. Please avoid using + it; it will be removed in a future release. allow_copy : bool, default True Whether to allow memory copying when exporting. If set to False it would cause non-zero-copy exports to fail. @@ -909,9 +909,6 @@ def __dataframe__( Details on the interchange protocol: https://data-apis.org/dataframe-protocol/latest/index.html - `nan_as_null` currently has no effect; once support for nullable extension - dtypes is added, this value should be propagated to columns. - Examples -------- >>> df_not_necessarily_pandas = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) @@ -931,7 +928,7 @@ def __dataframe__( from pandas.core.interchange.dataframe import PandasDataFrameXchg - return PandasDataFrameXchg(self, nan_as_null, allow_copy) + return PandasDataFrameXchg(self, allow_copy=allow_copy) def __dataframe_consortium_standard__( self, *, api_version: str | None = None diff --git a/pandas/core/interchange/dataframe.py b/pandas/core/interchange/dataframe.py index 0ddceb6b8139b..3413f7281de78 100644 --- a/pandas/core/interchange/dataframe.py +++ b/pandas/core/interchange/dataframe.py @@ -27,25 +27,20 @@ class PandasDataFrameXchg(DataFrameXchg): attributes defined on this class. """ - def __init__( - self, df: DataFrame, nan_as_null: bool = False, allow_copy: bool = True - ) -> None: + def __init__(self, df: DataFrame, allow_copy: bool = True) -> None: """ Constructor - an instance of this (private) class is returned from `pd.DataFrame.__dataframe__`. """ self._df = df - # ``nan_as_null`` is a keyword intended for the consumer to tell the - # producer to overwrite null values in the data with ``NaN`` (or ``NaT``). - # This currently has no effect; once support for nullable extension - # dtypes is added, this value should be propagated to columns. - self._nan_as_null = nan_as_null self._allow_copy = allow_copy def __dataframe__( self, nan_as_null: bool = False, allow_copy: bool = True ) -> PandasDataFrameXchg: - return PandasDataFrameXchg(self._df, nan_as_null, allow_copy) + # `nan_as_null` can be removed here once it's removed from + # Dataframe.__dataframe__ + return PandasDataFrameXchg(self._df, allow_copy) @property def metadata(self) -> dict[str, Index]: @@ -84,7 +79,7 @@ def select_columns(self, indices: Sequence[int]) -> PandasDataFrameXchg: indices = list(indices) return PandasDataFrameXchg( - self._df.iloc[:, indices], self._nan_as_null, self._allow_copy + self._df.iloc[:, indices], allow_copy=self._allow_copy ) def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # type: ignore[override] # noqa: E501 @@ -93,9 +88,7 @@ def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # ty if not isinstance(names, list): names = list(names) - return PandasDataFrameXchg( - self._df.loc[:, names], self._nan_as_null, self._allow_copy - ) + return PandasDataFrameXchg(self._df.loc[:, names], allow_copy=self._allow_copy) def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXchg]: """ @@ -109,8 +102,7 @@ def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXch for start in range(0, step * n_chunks, step): yield PandasDataFrameXchg( self._df.iloc[start : start + step, :], - self._nan_as_null, - self._allow_copy, + allow_copy=self._allow_copy, ) else: yield self