From 922bafe087af565debd2be59d1148297337257d8 Mon Sep 17 00:00:00 2001 From: Bert Palm <bert.palm@ufz.de> Date: Mon, 4 May 2020 15:10:06 +0200 Subject: [PATCH] equals docu --- dios/dios.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dios/dios.py b/dios/dios.py index 86cd0f1..620f0fd 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 -- GitLab