Skip to content

Commit 38589f9

Browse files
authored
DEPR: remove use of nan_as_null from callers of __dataframe__ (#54846)
1 parent 089481f commit 38589f9

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

pandas/core/frame.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,8 @@ def __dataframe__(
909909
Parameters
910910
----------
911911
nan_as_null : bool, default False
912-
Whether to tell the DataFrame to overwrite null values in the data
913-
with ``NaN`` (or ``NaT``).
912+
`nan_as_null` is DEPRECATED and has no effect. Please avoid using
913+
it; it will be removed in a future release.
914914
allow_copy : bool, default True
915915
Whether to allow memory copying when exporting. If set to False
916916
it would cause non-zero-copy exports to fail.
@@ -925,9 +925,6 @@ def __dataframe__(
925925
Details on the interchange protocol:
926926
https://data-apis.org/dataframe-protocol/latest/index.html
927927
928-
`nan_as_null` currently has no effect; once support for nullable extension
929-
dtypes is added, this value should be propagated to columns.
930-
931928
Examples
932929
--------
933930
>>> df_not_necessarily_pandas = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
@@ -947,7 +944,7 @@ def __dataframe__(
947944

948945
from pandas.core.interchange.dataframe import PandasDataFrameXchg
949946

950-
return PandasDataFrameXchg(self, nan_as_null, allow_copy)
947+
return PandasDataFrameXchg(self, allow_copy=allow_copy)
951948

952949
def __dataframe_consortium_standard__(
953950
self, *, api_version: str | None = None

pandas/core/interchange/dataframe.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,20 @@ class PandasDataFrameXchg(DataFrameXchg):
2727
attributes defined on this class.
2828
"""
2929

30-
def __init__(
31-
self, df: DataFrame, nan_as_null: bool = False, allow_copy: bool = True
32-
) -> None:
30+
def __init__(self, df: DataFrame, allow_copy: bool = True) -> None:
3331
"""
3432
Constructor - an instance of this (private) class is returned from
3533
`pd.DataFrame.__dataframe__`.
3634
"""
3735
self._df = df
38-
# ``nan_as_null`` is a keyword intended for the consumer to tell the
39-
# producer to overwrite null values in the data with ``NaN`` (or ``NaT``).
40-
# This currently has no effect; once support for nullable extension
41-
# dtypes is added, this value should be propagated to columns.
42-
self._nan_as_null = nan_as_null
4336
self._allow_copy = allow_copy
4437

4538
def __dataframe__(
4639
self, nan_as_null: bool = False, allow_copy: bool = True
4740
) -> PandasDataFrameXchg:
48-
return PandasDataFrameXchg(self._df, nan_as_null, allow_copy)
41+
# `nan_as_null` can be removed here once it's removed from
42+
# Dataframe.__dataframe__
43+
return PandasDataFrameXchg(self._df, allow_copy)
4944

5045
@property
5146
def metadata(self) -> dict[str, Index]:
@@ -84,7 +79,7 @@ def select_columns(self, indices: Sequence[int]) -> PandasDataFrameXchg:
8479
indices = list(indices)
8580

8681
return PandasDataFrameXchg(
87-
self._df.iloc[:, indices], self._nan_as_null, self._allow_copy
82+
self._df.iloc[:, indices], allow_copy=self._allow_copy
8883
)
8984

9085
def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # type: ignore[override]
@@ -93,9 +88,7 @@ def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # ty
9388
if not isinstance(names, list):
9489
names = list(names)
9590

96-
return PandasDataFrameXchg(
97-
self._df.loc[:, names], self._nan_as_null, self._allow_copy
98-
)
91+
return PandasDataFrameXchg(self._df.loc[:, names], allow_copy=self._allow_copy)
9992

10093
def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXchg]:
10194
"""
@@ -109,8 +102,7 @@ def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXch
109102
for start in range(0, step * n_chunks, step):
110103
yield PandasDataFrameXchg(
111104
self._df.iloc[start : start + step, :],
112-
self._nan_as_null,
113-
self._allow_copy,
105+
allow_copy=self._allow_copy,
114106
)
115107
else:
116108
yield self

0 commit comments

Comments
 (0)