def test_is_correct_length(self): # df1 has 2 columns, so asserting it has anything other than 2 columns should raise an exception (5 has no special meaning except 5 != 2) self.assertRaises(DimensionMismatchException, is_correct_length, self.df1, 5) # df1 has 2 columns, so is_correct_length(self.df1, 2) should not raise an exception # if it does, then this is a problem try: is_correct_length(self.df1, 2) except DimensionMismatchException: self.fail("is_correct_length() raised DimensionMismatchException unexpectedly!")
def transform(self, df, **transform_params): # sanity checks is_dataframe(df) is_correct_length(df,2) # Should we be checking for divide by zero? # It's unlikely in practice with real data, but what if something funky gets passed to this function? return pd.DataFrame((df.iloc[:,1].sub(df.iloc[:,0])).div(df.iloc[:,0]))