SIENTIAPDE-1430: Remove verbose options and direct print statements from model, preprocessor, and report utilities.

This commit is contained in:
Bruno Domingues
2025-12-18 21:09:12 -03:00
parent 13941fc3f7
commit 38fb9a9c53
4 changed files with 13 additions and 89 deletions

View File

@@ -43,7 +43,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
weights: dict[str, float] | None = None,
degree: int = 1,
interaction_only: bool = False,
verbose: bool = False,
):
"""
Linear Regression Model for Time Series Analysis
@@ -58,7 +57,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
*Format: {'variable_name': weight}*
degree (int): The degree of the polynomial features (1 = linear, >1 = polynomial)
interaction_only (bool): If True, only interaction features are produced
verbose (bool): If True, print verbose output during fitting
Returns:
LinearRegressionModel: The prediction model object
@@ -73,7 +71,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
self.weights: dict[str, float] | None = weights
self.degree: int = degree
self.interaction_only: bool = interaction_only
self.verbose: bool = verbose
self.poly: PolynomialFeatures | None = None
self.poly_feature_names: list[str] | None = None
@@ -152,8 +149,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
# Remove columns with all NaN values
cols_to_drop = X_train.columns[X_train.isna().all()].tolist()
if cols_to_drop: # pragma: no cover
if self.verbose:
print(f'Dropping columns with all NaN values: {cols_to_drop}')
X_train = X_train.drop(columns=cols_to_drop)
self.variable_columns = [c for c in self.variable_columns if c not in cols_to_drop]
@@ -163,8 +158,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
# Apply polynomial features if degree > 1
if self.degree > 1:
X_train = self.create_poly_features(X_train, fit=True)
if self.verbose and self.poly_feature_names is not None:
print(f'Created {len(self.poly_feature_names)} polynomial features')
# Fit the model
self.regr.fit(X_train, y_train)
@@ -181,9 +174,6 @@ class LinearRegressionModel(BaseEstimator, TransformerMixin):
weights = {'Bias': float(round_intercept), **weights}
self.weights = weights
if self.verbose and feature_names is not None:
print(f'Model fitted with {len(feature_names)} features')
return self
def predict(self, input_data: pd.DataFrame) -> np.ndarray:
@@ -266,7 +256,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
cross_operations: list[str] | None = None,
created_lags: dict[str, int] | None = None,
steps_order: list[str] | None = None,
verbose: bool = False,
):
"""
Data Preprocessor for Time Series Analysis
@@ -313,7 +302,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
'Normalization',
'Feature Creation',
'Lag Creation'*
verbose (bool): If True, print verbose output during preprocessing
Returns:
DataPreprocessor: The data preprocessor object
@@ -338,7 +326,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
self.scaler_name = scaler_name
self.scaler_params = scaler_params
self.feature_names_order: list[str] = [] # Initialize to avoid AttributeError
self.verbose = verbose
self._fitted_feature_order: list[str] | None = None # Track feature order after fit
if self.scaler_name == 'Standard Scaler':
@@ -453,8 +440,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
if treatment == 'linear interpolation':
treatment = 'fill linear'
input_data = treat_nan(input_data, treatment)
if self.verbose:
print(f'Applied NaN treatment: {self.nan_treatment}')
return input_data
def range_selection(self, input_data: pd.DataFrame) -> pd.DataFrame:
@@ -472,8 +457,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
try:
start = pd.to_datetime(self.start_date)
input_data = input_data[input_data.index >= start]
if self.verbose:
print(f'Filtered data from start_date: {self.start_date}')
except (ValueError, TypeError):
pass # Invalid date format, skip filtering
@@ -481,8 +464,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
try:
end = pd.to_datetime(self.end_date)
input_data = input_data[input_data.index <= end]
if self.verbose:
print(f'Filtered data to end_date: {self.end_date}')
except (ValueError, TypeError):
pass # Invalid date format, skip filtering
@@ -498,8 +479,6 @@ class DataPreprocessor(BaseEstimator, TransformerMixin):
& (input_data.index <= interval_end)
)
input_data = input_data[mask]
if self.verbose:
print(f'Removed interval: {interval[0]} to {interval[1]}')
except (ValueError, TypeError):
pass # Invalid date format, skip this interval

View File

@@ -36,10 +36,8 @@ def load_html_from_file(file_path):
with open(file_path, encoding='utf-8') as file:
return file.read()
except FileNotFoundError:
print(f'File not found: {file_path}')
return None
except OSError as e: # noqa: BLE001
print(f'Error reading file: {e}')
except OSError: # noqa: BLE001
return None
@@ -49,8 +47,6 @@ def inject_content(main_html, section_id, content):
if section:
section.clear()
section.append(BeautifulSoup(content, 'html.parser'))
else:
print(f"Section with id '{section_id}' not found in the main HTML template.")
return str(soup)