diff --git a/dios/dios.py b/dios/dios.py index 86cd0f1a77636d3c7357add6e3bbc72f2b661285..620f0fd6f8ad7ef3121bb944e31799311b7c2c95 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -645,12 +645,34 @@ class DictOfSeries(_DiosBase): raise ValueError(axis) # ---------------------------------------------------------------------- - # Boolean stuff + # Boolean and empty stuff def equals(self, other): + """ + Test whether two DictOfSeries contain the same elements. + + This function allows two DictOfSeries to be compared against each other to see + if they have the same shape and elements. NaNs in the same location are considered equal. + The column headers do not need to have the same type, but the elements within the columns + must be the same dtype. + + Parameters + ---------- + other: DictOfSeries + The other DictOfSeries to compare with. + + Returns + ------- + bool + True if all elements are the same in both DictOfSeries, False otherwise. + """ + if not isinstance(other, DictOfSeries): + return False try: - eqna = (self.isna() == other.isna()).all(None) - return eqna and (self.dropna() == other.dropna()).all(None) + eq_nans = (self.isna() == other.isna()).all(None) + eq_data = (self.dropna() == other.dropna()).all(None) + eq_dtypes = (self.dtypes == other.dtypes).all() + return eq_nans and eq_dtypes and eq_data except Exception: return False