SIENTIAPDE-1316
Update .gitignore and refactor metrics.py, activities.py, and gates.py for improved clarity and consistency. Added coverage.xml and cache directories to .gitignore. Standardized string formatting and parameter handling in metrics and activities classes, enhancing code readability. Removed the deprecated faker.py file and adjusted related tests accordingly.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import pytest
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from pandas.testing import assert_frame_equal
|
||||
from scouter.utils.quality.filters import check_data_range, out_of_bounds_filter, null_values_filter
|
||||
|
||||
from scouter.utils.quality.filters import check_data_range, null_values_filter, out_of_bounds_filter
|
||||
|
||||
# Fixtures
|
||||
|
||||
@@ -10,12 +11,14 @@ from scouter.utils.quality.filters import check_data_range, out_of_bounds_filter
|
||||
@pytest.fixture
|
||||
def sample_dataframe():
|
||||
"""Fixture providing a sample DataFrame for testing."""
|
||||
return pd.DataFrame({
|
||||
'tag': ['temp', 'temp', 'pressure', 'pressure', 'humidity', 'wind_speed'],
|
||||
'name': ['temp', 'temp', 'pressure', 'pressure', 'humidity', 'wind_speed'],
|
||||
'value': [25, 35, 95, 105, 60, None],
|
||||
'timestamp': pd.date_range(start='2023-01-01', periods=6)
|
||||
})
|
||||
return pd.DataFrame(
|
||||
{
|
||||
'tag': ['temp', 'temp', 'pressure', 'pressure', 'humidity', 'wind_speed'],
|
||||
'name': ['temp', 'temp', 'pressure', 'pressure', 'humidity', 'wind_speed'],
|
||||
'value': [25, 35, 95, 105, 60, None],
|
||||
'timestamp': pd.date_range(start='2023-01-01', periods=6),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -25,7 +28,7 @@ def nodes_data_range():
|
||||
'temp': {'data_range': [10, 30]},
|
||||
'pressure': {'data_range': [90, 100]},
|
||||
'humidity': {'data_range': [40, 80]},
|
||||
'wind_speed': {'data_range': [0, 50]}
|
||||
'wind_speed': {'data_range': [0, 50]},
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +62,7 @@ def test_check_data_range(value, val_range, expected):
|
||||
else:
|
||||
assert result == expected
|
||||
|
||||
|
||||
# Tests for out_of_bounds_filter
|
||||
|
||||
|
||||
@@ -72,8 +76,8 @@ def test_out_of_bounds_filter(sample_dataframe, nodes_data_range):
|
||||
'timestamp': [
|
||||
pd.Timestamp('2023-01-02'),
|
||||
pd.Timestamp('2023-01-04'),
|
||||
pd.Timestamp('2023-01-06')
|
||||
]
|
||||
pd.Timestamp('2023-01-06'),
|
||||
],
|
||||
}
|
||||
expected_df = pd.DataFrame(expected_data)
|
||||
|
||||
@@ -91,6 +95,7 @@ def test_out_of_bounds_filter_empty_df(nodes_data_range):
|
||||
assert result.empty
|
||||
assert list(result.columns) == ['tag', 'name', 'value', 'timestamp']
|
||||
|
||||
|
||||
# Tests for null_values_filter
|
||||
|
||||
|
||||
@@ -100,7 +105,7 @@ def test_null_values_filter(sample_dataframe, nodes_data_range):
|
||||
'tag': ['wind_speed'],
|
||||
'name': ['wind_speed'],
|
||||
'value': [None],
|
||||
'timestamp': [pd.Timestamp('2023-01-06')]
|
||||
'timestamp': [pd.Timestamp('2023-01-06')],
|
||||
}
|
||||
expected_df = pd.DataFrame(expected_data)
|
||||
|
||||
@@ -113,12 +118,14 @@ def test_null_values_filter(sample_dataframe, nodes_data_range):
|
||||
|
||||
def test_null_values_filter_no_nulls(nodes_data_range):
|
||||
"""Test with a DataFrame containing no null values."""
|
||||
df = pd.DataFrame({
|
||||
'tag': ['temp', 'pressure'],
|
||||
'name': ['temp', 'pressure'],
|
||||
'value': [25, 100],
|
||||
'timestamp': pd.date_range(start='2023-01-01', periods=2)
|
||||
})
|
||||
df = pd.DataFrame(
|
||||
{
|
||||
'tag': ['temp', 'pressure'],
|
||||
'name': ['temp', 'pressure'],
|
||||
'value': [25, 100],
|
||||
'timestamp': pd.date_range(start='2023-01-01', periods=2),
|
||||
}
|
||||
)
|
||||
result = null_values_filter(df, nodes_data_range)
|
||||
assert result.empty
|
||||
assert list(result.columns) == ['tag', 'name', 'value', 'timestamp']
|
||||
|
||||
Reference in New Issue
Block a user