def check_for_discontinuity(df, tolerance): """ Returns a DataFrame object containing only rows and columns with values of <df> at which there is an outlier first-order partial derivative along row axis. Normal values are set to NaN. tolerance: used in outlier test for first-order derivative, how many sigmas? """ if isinstance(df.index, DatetimeIndex): # doesn't matter what value, this is just for allowing the division to occur # result of is_outlier does not depend on index_unit index_unit = np.timedelta64(365, 'D') else: index_unit = 1 der = derivative(df, index_unit) return df[is_outlier(der, tolerance)].dropna(axis=0, how="all").dropna(axis=1, how="all")
def test_derivative__DataFrame(self): result = calculator.derivative(pd.DataFrame({'a': [3, 2, 8], 'b': [3, 2, 11]}, index=[0, 1, 4])) self.assertFrameEqual(result, pd.DataFrame({'a': [-1, 2], 'b': [-1, 3]}), check_dtype=False)
def test_derivative__Series(self): result = calculator.derivative(pd.Series([3, 2, 8], index=[0, 1, 4])) self.assertFrameEqual(result, pd.Series([-1, 2]), check_dtype=False) result = calculator.derivative(pd.Series([3, 2, 8], index=[0, 1, 4]), index_unit=2) self.assertFrameEqual(result, pd.Series([-2, 4]), check_dtype=False)