Skip to content

Commit

Permalink
Merge pull request #73 from kaklise/main
Browse files Browse the repository at this point in the history
Update to custom static and streaming methods to use a specific column
  • Loading branch information
kaklise authored Oct 12, 2021
2 parents f38f857 + 301a5e2 commit 8d95ba4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions documentation/whatsnew/v0.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v0.2.1 (main)
--------------------------

* Bug fix in custom static and streaming quality control tests to use a specific column
* Minor updates for testing and documentation
* Added GitHub Actions and Python 3.9 tests

6 changes: 3 additions & 3 deletions pecos/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def check_custom_static(self, quality_control_func, key=None, min_failures=1,

# Function that operates on the entire dataset and returns a mask and
# metadata for the entire dataset
mask, metadata = quality_control_func(self.df)
mask, metadata = quality_control_func(df)
assert isinstance(mask, pd.DataFrame), 'mask returned by quality_control_func must be of type pd.DataFrame'
assert isinstance(metadata, pd.DataFrame), 'metadata returned by quality_control_func must be of type pd.DataFrame'

Expand Down Expand Up @@ -852,7 +852,7 @@ def check_custom_streaming(self, quality_control_func, window, key=None,
# The streaming framework uses numpy arrays to improve performance but
# still expects pandas DataFrames and Series in the user defined quality
# control function to keep data types consitent on the user side.
np_mask = pd.DataFrame(True, index=self.df.index, columns=self.df.columns).values
np_mask = pd.DataFrame(True, index=df.index, columns=df.columns).values
np_data = df.values.astype('float64')

ti = df.index.get_loc(df.index[0]+history_window)
Expand Down Expand Up @@ -881,7 +881,7 @@ def check_custom_streaming(self, quality_control_func, window, key=None,
np_data[t][check_rebase] = df.iloc[t][check_rebase]
rebase_count = rebase_count + sum(check_rebase)

mask = pd.DataFrame(np_mask, index=self.df.index, columns=self.df.columns)
mask = pd.DataFrame(np_mask, index=df.index, columns=df.columns)
self._append_test_results(mask, error_message, min_failures)

# Convert metadata to a dataframe
Expand Down
10 changes: 9 additions & 1 deletion pecos/tests/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,15 @@ def custom_func(data):
percent = 1-self.pm.test_results['Timesteps'].sum()/N
assert_almost_equal(percent, 0.95, 2) # 95% within 2 std

# using a specific key
metadata_A = self.pm.check_custom_static(custom_func, key='A', error_message='Static')
assert_frame_equal(metadata[['A']], metadata_A)

# Functional tests
results = pecos.monitoring.check_custom_static(self.pm.data, custom_func, error_message='Static')
percent = 1-results['test_results']['Timesteps'].sum()/N
assert_almost_equal(percent, 0.95, 2) # 95% within 2 std

def test_custom_streaming(self):

def custom_func(data_pt, history):
Expand All @@ -607,6 +611,10 @@ def custom_func(data_pt, history):
percent = 1-self.pm.test_results['Timesteps'].sum()/N
assert_almost_equal(percent, 0.95, 2) # 95% within 2 std

# using a specific key
metadata_A = self.pm.check_custom_streaming(custom_func, 50, key='A', error_message='Streaming')
assert_frame_equal(metadata[['A']], metadata_A)

# Functional tests
results = pecos.monitoring.check_custom_streaming(self.pm.data, custom_func, 50, error_message='Streaming')
percent = 1-results['test_results']['Timesteps'].sum()/N
Expand Down

0 comments on commit 8d95ba4

Please sign in to comment.