diff --git a/scdata/device/process/regression.py b/scdata/device/process/regression.py index dd30b86..026ac35 100644 --- a/scdata/device/process/regression.py +++ b/scdata/device/process/regression.py @@ -4,6 +4,7 @@ from scdata.tools.cleaning import clean from pandas import DataFrame from numpy import array +from scdata.device.process.error_codes import StatusCode, ProcessResult def apply_regressor(dataframe, **kwargs): ''' @@ -37,8 +38,7 @@ def apply_regressor(dataframe, **kwargs): inputdf = inputdf.reindex(sorted(inputdf.columns), axis=1) except KeyError: logger.error('Inputs not in dataframe') - pass - return None + return ProcessResult(None, StatusCode.ERROR_MISSING_INPUTS) if 'model' not in kwargs: logger.error('Model not in inputs') @@ -56,4 +56,4 @@ def apply_regressor(dataframe, **kwargs): features = array(inputdf) result = DataFrame(model.predict(features)).set_index(inputdf.index) - return result \ No newline at end of file + return ProcessResult(result, StatusCode.SUCCESS) \ No newline at end of file diff --git a/scdata/device/process/timeseries.py b/scdata/device/process/timeseries.py index 64f30cc..82691dc 100644 --- a/scdata/device/process/timeseries.py +++ b/scdata/device/process/timeseries.py @@ -2,10 +2,16 @@ from scipy import ndimage from scdata.device.process import is_within_circle from scdata.tools.custom_logger import logger +from scdata.device.process.error_codes import StatusCode, ProcessResult + +# TODO UPDATE all these functions to make them comply with StatusCode types def delta_index_ts(dataframe, **kwargs): - result = dataframe.index.to_series().diff().astype('timedelta64[s]') - return result + try: + result = dataframe.index.to_series().diff().astype('timedelta64[s]') + except: + return ProcessResult(None, StatusCode.ERROR_UNDEFINED) + return ProcessResult(result, StatusCode.SUCCESS) def poly_ts(dataframe, **kwargs): """ @@ -45,7 +51,7 @@ def poly_ts(dataframe, **kwargs): for i in range(n_channels): result += power(dataframe[channels[i]], exponents[i]) * coefficients[i] - return result + extra_term + return ProcessResult(result + extra_term, StatusCode.SUCCESS) def clean_ts(dataframe, **kwargs): """ @@ -91,7 +97,7 @@ def clean_ts(dataframe, **kwargs): if window is not None: result.rolling(window = window, win_type = win_type).mean() - return result + return ProcessResult(result, StatusCode.SUCCESS) def merge_ts(dataframe, **kwargs): """ @@ -168,7 +174,7 @@ def merge_ts(dataframe, **kwargs): # elif pick == 'min_nonzero': # df['result'] = df.loc[df['flag'] == True, kwargs['names']].min(skipna=True, axis = 1) - return df['result'] + return ProcessResult(df['result'], StatusCode.SUCCESS) def rolling_avg(dataframe, **kwargs): """ @@ -208,11 +214,14 @@ def rolling_avg(dataframe, **kwargs): else: win_type = None if 'type' in kwargs: - if kwargs['type'] == 'mean': return result.rolling(window = window, win_type = win_type).mean() - if kwargs['type'] == 'max': return result.rolling(window = window, win_type = win_type).max() - if kwargs['type'] == 'min': return result.rolling(window = window, win_type = win_type).min() + if kwargs['type'] == 'mean': + return ProcessResult(result.rolling(window = window, win_type = win_type).mean(), StatusCode.SUCCESS) + if kwargs['type'] == 'max': + return ProcessResult(result.rolling(window = window, win_type = win_type).max(), StatusCode.SUCCESS) + if kwargs['type'] == 'min': + return ProcessResult(result.rolling(window = window, win_type = win_type).min(), StatusCode.SUCCESS) else: - return result.rolling(window = window, win_type = win_type).mean() + return ProcessResult(result.rolling(window = window, win_type = win_type).mean(), StatusCode.SUCCESS) def time_derivative(dataframe, **kwargs): """ @@ -243,9 +252,8 @@ def time_derivative(dataframe, **kwargs): if gaussian_filter1d: df['diff_filter1d'] = ndimage.gaussian_filter1d(df['diff'], sigma=1, order=1, mode='wrap') / dx - return df['diff_filter1d'] - - return df['diff'] + return ProcessResult(df['diff_filter1d'], StatusCode.SUCCESS) + return ProcessResult(df['diff'], StatusCode.SUCCESS) def geo_located(dataframe, **kwargs): """ @@ -276,4 +284,4 @@ def geo_located(dataframe, **kwargs): result['within'] = result.apply(lambda x: is_within_circle(x, kwargs['within'], lat_name, long_name), axis=1) - return result['within'] \ No newline at end of file + return ProcessResult(result['within'], StatusCode.SUCCESS) \ No newline at end of file