From f96a7aba685028ebedc67a50d5ef26cf817be43d Mon Sep 17 00:00:00 2001 From: Ingo Stallknecht Date: Fri, 28 Nov 2025 15:12:40 +0100 Subject: [PATCH 1/2] DOC: add NaN example to DataFrame.equals --- pandas/core/generic.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 600171648d110..458d1625e08a4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1456,6 +1456,20 @@ def equals(self, other: object) -> bool: 0 10.0 20.0 >>> df.equals(different_data_type) False + + DataFrames with NaN in the same locations compare equal. + + >>> import numpy as np + >>> df_nan1 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) + >>> df_nan2 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) + >>> df_nan1.equals(df_nan2) + True + + If the NaN values are not in the same locations, they compare unequal. + + >>> df_nan3 = pd.DataFrame({"a": [1, np.nan], "b": [3, 4]}) + >>> df_nan1.equals(df_nan3) + False """ if not (isinstance(other, type(self)) or isinstance(self, type(other))): return False From 2b9e93ca3df793eb0c791e677943ac31789a3a00 Mon Sep 17 00:00:00 2001 From: Ingo Stallknecht Date: Fri, 28 Nov 2025 15:51:59 +0100 Subject: [PATCH 2/2] DOC: fix equals docstring for docstring validation --- pandas/core/generic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 458d1625e08a4..ccce1fadc16cf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1459,7 +1459,6 @@ def equals(self, other: object) -> bool: DataFrames with NaN in the same locations compare equal. - >>> import numpy as np >>> df_nan1 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) >>> df_nan2 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) >>> df_nan1.equals(df_nan2)