def __eq__(self, other): if isinstance(other, self.__class__): # Auto check attrs if assigned to DataFrames/Series, then add to list blacklisted = [attr for attr in self.__dict__ if isinstance(getattr(self, attr), (pd.DataFrame, pd.Series))] # Check DataFrames and Series for attrname in blacklisted: ndf_eq = ut.ndframe_equal(getattr(self, attrname), getattr(other, attrname)) # Ignore pandas objects; check rest of __dict__ and build trimmed dicts # Important to blacklist the trimmed dict from looping in __dict__ blacklisted.append('_dict_trim') # prevent infinite loop self._dict_trim = { key: value for key, value in self.__dict__.items() if key not in blacklisted} other._dict_trim = { key: value for key, value in other.__dict__.items() if key not in blacklisted} return ndf_eq and self._dict_trim == other._dict_trim # order is important return NotImplemented
def __eq__(self, other): '''Compare Case objects, designed to handle pandas objects. Notes ----- DEV: `__eq__` handles all DataFrame/Series items of `__dict__` separately. Attribute names with DataFrame/Series assignments are blacklisted and checked separately from other `__dict__` items. ''' if isinstance(other, self.__class__): # Auto check attrs if assigned to DataFrames/Series, then add to list blacklisted = [attr for attr in self.__dict__ if isinstance(getattr(self, attr), (pd.DataFrame, pd.Series))] # DEV: Blacklist attribute names pointing to DataFrames/Series here. # blacklisted = ['parameters', 'properties'] # Check DataFrames and Series for attrname in blacklisted: ndf_eq = ut.ndframe_equal(getattr(self, attrname), getattr(other, attrname)) ##ndf_eq = ndframe_equal(getattr(self, attr), getattr(other, attr)) # Ignore pandas objects; check rest of __dict__ and build trimmed dicts blacklisted.append('_dict_trim') # prevent infinite loop self._dict_trim = { key: value for key, value in self.__dict__.items() if key not in blacklisted} other._dict_trim = { key: value for key, value in other.__dict__.items() if key not in blacklisted} return ndf_eq and self._dict_trim == other._dict_trim # order is important return NotImplemented
def test_ndframeeq_Series2(self): '''Check helper function compares Series, False.''' actual = ut.ndframe_equal(self.s1, self.s3) expected = False nt.assert_equal(actual, expected)
def test_ndframeeq_Series1(self): '''Check helper function compares Series, True.''' actual = ut.ndframe_equal(self.s1, self.s2) expected = True nt.assert_equal(actual, expected)
def test_ndframeeq_DataFrame2(self): '''Check helper function compares DataFrames, False.''' actual = ut.ndframe_equal(self.df1, self.df3) expected = False nt.assert_equal(actual, expected)
def test_ndframeeq_DataFrame1(self): '''Check helper function compares DataFrames, True.''' actual = ut.ndframe_equal(self.df1, self.df2) expected = True nt.assert_equal(actual, expected)