Skip to content

Commit 38bf579

Browse files
committed
Remove use of nan_as_null from callers of __dataframe__
No one was using it yet and it seemed easier to clean it up from libraries than to ask everyone to add support for it - see data-apis/dataframe-api#125.
1 parent 4e0630c commit 38bf579

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

pandas/core/frame.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ def __dataframe__(
893893
Parameters
894894
----------
895895
nan_as_null : bool, default False
896-
Whether to tell the DataFrame to overwrite null values in the data
897-
with ``NaN`` (or ``NaT``).
896+
`nan_as_null` is DEPRECATED and has no effect. Please avoid using
897+
it; it will be removed in a future release (after Aug 2024).
898898
allow_copy : bool, default True
899899
Whether to allow memory copying when exporting. If set to False
900900
it would cause non-zero-copy exports to fail.
@@ -909,9 +909,6 @@ def __dataframe__(
909909
Details on the interchange protocol:
910910
https://data-apis.org/dataframe-protocol/latest/index.html
911911
912-
`nan_as_null` currently has no effect; once support for nullable extension
913-
dtypes is added, this value should be propagated to columns.
914-
915912
Examples
916913
--------
917914
>>> df_not_necessarily_pandas = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
@@ -931,7 +928,7 @@ def __dataframe__(
931928

932929
from pandas.core.interchange.dataframe import PandasDataFrameXchg
933930

934-
return PandasDataFrameXchg(self, nan_as_null, allow_copy)
931+
return PandasDataFrameXchg(self, allow_copy=allow_copy)
935932

936933
def __dataframe_consortium_standard__(
937934
self, *, api_version: str | None = None

pandas/core/interchange/dataframe.py

+7-13
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] # noqa: E501
@@ -94,7 +89,7 @@ def select_columns_by_name(self, names: list[str]) -> PandasDataFrameXchg: # ty
9489
names = list(names)
9590

9691
return PandasDataFrameXchg(
97-
self._df.loc[:, names], self._nan_as_null, self._allow_copy
92+
self._df.loc[:, names], allow_copy=self._allow_copy
9893
)
9994

10095
def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXchg]:
@@ -109,8 +104,7 @@ def get_chunks(self, n_chunks: int | None = None) -> Iterable[PandasDataFrameXch
109104
for start in range(0, step * n_chunks, step):
110105
yield PandasDataFrameXchg(
111106
self._df.iloc[start : start + step, :],
112-
self._nan_as_null,
113-
self._allow_copy,
107+
allow_copy=self._allow_copy,
114108
)
115109
else:
116110
yield self

0 commit comments

Comments
 (0)