Skip to content

Commit 11c8fbe

Browse files
DOC: add NaN example to DataFrame.equals (#63227)
1 parent 1895c38 commit 11c8fbe

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/core/generic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,19 @@ def equals(self, other: object) -> bool:
14561456
0 10.0 20.0
14571457
>>> df.equals(different_data_type)
14581458
False
1459+
1460+
DataFrames with NaN in the same locations compare equal.
1461+
1462+
>>> df_nan1 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]})
1463+
>>> df_nan2 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]})
1464+
>>> df_nan1.equals(df_nan2)
1465+
True
1466+
1467+
If the NaN values are not in the same locations, they compare unequal.
1468+
1469+
>>> df_nan3 = pd.DataFrame({"a": [1, np.nan], "b": [3, 4]})
1470+
>>> df_nan1.equals(df_nan3)
1471+
False
14591472
"""
14601473
if not (isinstance(other, type(self)) or isinstance(self, type(other))):
14611474
return False

0 commit comments

Comments
 (0)