Skip to content

Commit f96a7ab

Browse files
DOC: add NaN example to DataFrame.equals
1 parent 1b5b02c commit f96a7ab

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/core/generic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,20 @@ 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+
>>> import numpy as np
1463+
>>> df_nan1 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]})
1464+
>>> df_nan2 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]})
1465+
>>> df_nan1.equals(df_nan2)
1466+
True
1467+
1468+
If the NaN values are not in the same locations, they compare unequal.
1469+
1470+
>>> df_nan3 = pd.DataFrame({"a": [1, np.nan], "b": [3, 4]})
1471+
>>> df_nan1.equals(df_nan3)
1472+
False
14591473
"""
14601474
if not (isinstance(other, type(self)) or isinstance(self, type(other))):
14611475
return False

0 commit comments

Comments
 (0)