SIENTIAPDE-1579: Fix SientiaMlException propagation in ModelServing.search_runs_by_name to correctly raise the exception with its message, resolving a TypeError. Enhance training test script to support scenario-specific CSV files for different test cases. Update search_runs_by_name return type hint and apply minor code formatting.
This commit is contained in:
@@ -112,18 +112,16 @@ def test_search_runs_by_name_with_order_by(mock_search_runs, mock_set_tracking_u
|
||||
def test_search_runs_by_name_raises_exception(
|
||||
mock_logging_error, mock_search_runs, mock_set_tracking_uri
|
||||
):
|
||||
"""Test search_runs_by_name raises TypeError due to bug in line 80 of model_serving.py."""
|
||||
"""Test search_runs_by_name properly propagates SientiaMlException."""
|
||||
model_serving = ModelServing(tracking_uri='http://mlflow.example.com')
|
||||
|
||||
exception = SientiaMlException(message='Search failed')
|
||||
mock_search_runs.side_effect = exception
|
||||
|
||||
# The code has a bug on line 80: "raise SientiaMlException from e"
|
||||
# This raises TypeError because SientiaMlException requires 'message' argument
|
||||
with raises(TypeError, match="missing 1 required positional argument: 'message'"):
|
||||
with raises(SientiaMlException, match='Search failed'):
|
||||
model_serving.search_runs_by_name(['experiment1'])
|
||||
|
||||
mock_logging_error.assert_called_once()
|
||||
mock_logging_error.assert_called_once_with(exception)
|
||||
|
||||
|
||||
@patch('model_manager.sientia.model_serving.mlflow.set_tracking_uri')
|
||||
|
||||
@@ -993,7 +993,9 @@ class TestConfigureDatetimeIndex:
|
||||
assert 'var2' in result.columns
|
||||
|
||||
@pytest.mark.filterwarnings('ignore::UserWarning')
|
||||
def test_configure_datetime_index_invalid_timestamp_column(self, training_repo, datetime_params):
|
||||
def test_configure_datetime_index_invalid_timestamp_column(
|
||||
self, training_repo, datetime_params
|
||||
):
|
||||
"""Test _configure_datetime_index with invalid timestamp values."""
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
@@ -1199,10 +1201,12 @@ class TestEnsureDateColumnParsed:
|
||||
|
||||
def test_parses_column_with_format(self, date_params):
|
||||
"""When date_column and date_format set, column is parsed as datetime."""
|
||||
data = pd.DataFrame({
|
||||
'ts': ['2023-01-01 10:00:00', '2023-06-15 14:30:00'],
|
||||
'x': [1, 2],
|
||||
})
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
'ts': ['2023-01-01 10:00:00', '2023-06-15 14:30:00'],
|
||||
'x': [1, 2],
|
||||
}
|
||||
)
|
||||
result = _ensure_date_column_parsed(data, date_params)
|
||||
assert result['ts'].dtype == 'datetime64[ns]'
|
||||
assert result['ts'].iloc[0].year == 2023
|
||||
@@ -1212,10 +1216,12 @@ class TestEnsureDateColumnParsed:
|
||||
def test_invalid_values_coerced_to_nat(self, date_params):
|
||||
"""Invalid date strings are coerced to NaT when format is set."""
|
||||
date_params.date_format = 'yyyy-MM-dd HH:mm:ss'
|
||||
data = pd.DataFrame({
|
||||
'ts': ['2023-01-01 00:00:00', 'not-a-date', '2023-12-31 00:00:00'],
|
||||
'x': [1, 2, 3],
|
||||
})
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
'ts': ['2023-01-01 00:00:00', 'not-a-date', '2023-12-31 00:00:00'],
|
||||
'x': [1, 2, 3],
|
||||
}
|
||||
)
|
||||
result = _ensure_date_column_parsed(data, date_params)
|
||||
assert pd.isna(result['ts'].iloc[1])
|
||||
assert result['ts'].iloc[0].year == 2023
|
||||
@@ -1256,10 +1262,12 @@ class TestApplySupportFilters:
|
||||
|
||||
def test_snake_case_upper_lower_line(self):
|
||||
"""Support filters with upper_line/lower_line (snake_case) filter rows."""
|
||||
data = pd.DataFrame({
|
||||
'x': [1.0, 2.0, 3.0, 4.0],
|
||||
'target': [2.0, 4.0, 6.0, 8.0],
|
||||
})
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
'x': [1.0, 2.0, 3.0, 4.0],
|
||||
'target': [2.0, 4.0, 6.0, 8.0],
|
||||
}
|
||||
)
|
||||
support_filters = {
|
||||
'x': {
|
||||
'upper_line': {'intercept': 1.0, 'angle': 50},
|
||||
@@ -1272,10 +1280,12 @@ class TestApplySupportFilters:
|
||||
|
||||
def test_camel_case_upper_lower_line(self):
|
||||
"""Support filters with upperLine/lowerLine (camelCase) are accepted."""
|
||||
data = pd.DataFrame({
|
||||
'x': [1.0, 2.0, 3.0],
|
||||
'target': [1.0, 2.0, 3.0],
|
||||
})
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
'x': [1.0, 2.0, 3.0],
|
||||
'target': [1.0, 2.0, 3.0],
|
||||
}
|
||||
)
|
||||
support_filters = {
|
||||
'x': {
|
||||
'upperLine': {'intercept': 2, 'angle': 5},
|
||||
@@ -1288,11 +1298,13 @@ class TestApplySupportFilters:
|
||||
|
||||
def test_two_variables_ands_masks(self):
|
||||
"""Two variables apply AND of both masks."""
|
||||
data = pd.DataFrame({
|
||||
'a': [1.0, 2.0, 3.0],
|
||||
'b': [1.0, 2.0, 3.0],
|
||||
'target': [2.0, 2.0, 2.0],
|
||||
})
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
'a': [1.0, 2.0, 3.0],
|
||||
'b': [1.0, 2.0, 3.0],
|
||||
'target': [2.0, 2.0, 2.0],
|
||||
}
|
||||
)
|
||||
support_filters = {
|
||||
'a': {
|
||||
'upper_line': {'intercept': 10, 'angle': 45},
|
||||
|
||||
Reference in New Issue
Block a user