Raise value error for min max computation of feature range (#2072)
* Raise value error for min max computation of feature range * Update rai_insights.py * Add test * Update test name * Update formatting * Update exception type * Update test for new exception type * Update formatting
This commit is contained in:
Родитель
36894f4b4e
Коммит
cde413c074
|
@ -16,7 +16,8 @@ import pandas as pd
|
|||
from erroranalysis._internal.cohort_filter import FilterDataWithCohortFilters
|
||||
from erroranalysis._internal.process_categoricals import process_categoricals
|
||||
from raiutils.data_processing import convert_to_list
|
||||
from raiutils.exceptions import UserConfigValidationException
|
||||
from raiutils.exceptions import (SystemErrorException,
|
||||
UserConfigValidationException)
|
||||
from raiutils.models import Forecasting, ModelTask, SKLearn
|
||||
from responsibleai._interfaces import (Dataset, RAIInsightsData,
|
||||
TabularDatasetMetadata)
|
||||
|
@ -1279,8 +1280,18 @@ class RAIInsights(RAIBaseInsights):
|
|||
res_object[_MIN_VALUE] = test[col].min()
|
||||
res_object[_MAX_VALUE] = test[col].max()
|
||||
else:
|
||||
min_value = float(test[col].min())
|
||||
max_value = float(test[col].max())
|
||||
col_min = test[col].min()
|
||||
col_max = test[col].max()
|
||||
try:
|
||||
min_value = float(col_min)
|
||||
max_value = float(col_max)
|
||||
except Exception as e:
|
||||
raise SystemErrorException(
|
||||
"Unable to convert min or max value "
|
||||
f"of feature column {col} to float. "
|
||||
f"min value of {col} is of type {type(col_min)} and "
|
||||
f"max value of {col} is of type {type(col_max)} "
|
||||
f"Original Excepton: {e}")
|
||||
res_object[_RANGE_TYPE] = "integer"
|
||||
res_object[_MIN_VALUE] = min_value
|
||||
res_object[_MAX_VALUE] = max_value
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
# Licensed under the MIT License.
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
from raiutils.exceptions import SystemErrorException
|
||||
from responsibleai.rai_insights import RAIInsights
|
||||
|
||||
|
||||
|
@ -18,3 +20,12 @@ class TestRAIInsightsGetFeatureRanges:
|
|||
assert len(feature_ranges) == 2
|
||||
assert 'Category' == feature_ranges[0]['column_name']
|
||||
assert 'Numerical' == feature_ranges[1]['column_name']
|
||||
|
||||
def test_invalid_float_cast_raises_value_error(self):
|
||||
data = {'col1': ['A', 'B', 'C', '50']}
|
||||
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
with pytest.raises(SystemErrorException,
|
||||
match='Unable to convert min or max value'):
|
||||
RAIInsights._get_feature_ranges(df, [], ['col1'])
|
||||
|
|
Загрузка…
Ссылка в новой задаче