When we have exact same columns in source and target dataframes and distinct number of rows then we are seeing below exception which according to me is misleading.

"ValueError: Can only compare identically-labeled DataFrame objects"

CODE :

```import pandas as pd

define DataFrames

df1 = pd.DataFrame({'points': [25, 12, 15, 14], 'assists': [5, 7, 13, 12]})

df2 = pd.DataFrame({'points': [25, 12, 15], 'assists': [5, 7, 13]})

print(df1)

points assists 0 25 5 1 12 7 2 15 13 3 14 12

print(df2)

points assists 0 25 5 1 12 7 2 15 13

Compare both dataframes

df1.compare(df2)

+++++++++++++++++++++++++++++++++ERROR+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py", line 7117, in compare keep_equal=keep_equal, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 8424, in compare mask = ~((self == other) | (self.isna() & other.isna())) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/ops/common.py", line 69, in new_method return method(self, other) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/arraylike.py", line 32, in eq return self._cmp_method(other, operator.eq) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py", line 6851, in _cmp_method self, other = ops.align_method_FRAME(self, other, axis, flex=False, level=None) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/ops/init.py", line 289, in align_method_FRAME "Can only compare identically-labeled DataFrame objects" ValueError: Can only compare identically-labeled DataFrame objects +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


**Comment From: rhshadrach**

Thanks for the report; labels can refer to either column labels or row labels.

**Comment From: phofl**

Agreed, the exception is not misleading but could be clearer in the sense that it includes index/columns or both

**Comment From: abhid001**

@rhshadrach Thanks for the confirmation but it would be great if it gives clear idea about the error instead a generic one. Like @phofl said it should include something specific to either column or row labels.
Also i was looking if i can make that enhancement and submit a review request for the same.


**Comment From: MarcoGorelli**

OK, so how about changing

Can only compare identically-labeled DataFrame objects

to

Can only compare identically-labeled (both index and columns) DataFrame objects ``` ?

This'd need changing in a few places, as well as in tests. But agree that it'd be nice to clarify

Comment From: abhid001

take