API: .equals for Extension Arrays · Issue #27081 · pandas-dev/pandas (original) (raw)

We don't have a good method of testing for equality between EA's

In [19]: from pandas.tests.extension.decimal.array import DecimalArray                                                                                                                                                                                           

In [20]: from decimal import Decimal                                                                                                                                                                                                                             

In [21]: x = DecimalArray([Decimal('1'),Decimal('Nan')])                                                                                                                                                                                                         

In [22]: x == x                                                                                                                                                                                                                                                  
Out[22]: array([ True, False])

In [23]: x = pd.Series([1,np.nan], dtype='Int64').array                                                                                                                                                                                                          

In [24]: x == x                                                                                                                                                                                                                                                  
Out[24]: array([ True, False])

These happen to work with Series now because the null checks are handled at a higher level.

In [26]: x.equals(x)                                                                                                                                                                                                                                             
Out[26]: True

In [27]: x = pd.Series(DecimalArray([Decimal('1'),Decimal('Nan')]))                                                                                                                                                                                              

In [28]: x.equals(x)                                                                                                                                                                                                                                             
Out[28]: True

we could provide a default implementation that should just work in the presence of NA.

def equals(self, other):
    return ((self == other) | (self.isna() == other.isna())).all()

actually we should also implement a default __eq__