Skip to content

Refine warning suppression, logger naming, and exception sanitization#4

Merged
bartzbeielstein merged 2 commits into
mainfrom
copilot/update-warning-suppression
Feb 11, 2026
Merged

Refine warning suppression, logger naming, and exception sanitization#4
bartzbeielstein merged 2 commits into
mainfrom
copilot/update-warning-suppression

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Applies targeted code quality and security improvements to the N-to-1 forecasting task module.

Changes

  • Warning suppression: Narrow from global ignore to FutureWarning and UserWarning categories only
  • DEFAULT_WEIGHTS clarity: Add inline comments mapping indices to forecast components
  • Logger instantiation: Replace hardcoded "task_safe_n_to_1" with __name__ (2 occurrences) for proper hierarchy
  • Exception logging: Log type(e).__name__ instead of str(e) to prevent potential sensitive data exposure (CWE-532)
# Before
warnings.simplefilter("ignore")
logger = logging.getLogger("task_safe_n_to_1")
logger.error("Forecasting failed: %s", str(e))

# After  
warnings.simplefilter("ignore", category=FutureWarning)
warnings.simplefilter("ignore", category=UserWarning)
logger = logging.getLogger(__name__)
logger.error("Forecasting failed during N-to-1 forecasting. Exception type: %s", type(e).__name__)
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"Global warning suppression is discouraged as it can mask important issues. Consider using specific warning filters or context managers to suppress only expected warnings.","fixFiles":[{"filePath":"src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py","diff":"diff --git a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n--- a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n+++ b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n@@ -78,7 +78,8 @@\n     1.0,\n ]\n \n-warnings.simplefilter(\"ignore\")\n+warnings.simplefilter(\"ignore\", category=FutureWarning)\n+warnings.simplefilter(\"ignore\", category=UserWarning)\n \n \n def _mask_latitude(lat: float) -> str:\n"}]},{"message":"The DEFAULT_WEIGHTS constant has extensive documentation but lacks explanation of what each position represents. Consider adding inline comments or a mapping dictionary to clarify which weight corresponds to which forecast component.","fixFiles":[{"filePath":"src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py","diff":"diff --git a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n--- a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n+++ b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n@@ -65,17 +65,17 @@\n # - They are defined as a named constant (rather than inline) to make it clear\n #   what is being tuned and to avoid unexplained \"magic numbers\" in the code.\n DEFAULT_WEIGHTS: List[float] = [\n-    1.0,\n-    1.0,\n-    -1.0,\n-    -1.0,\n-    1.0,\n-    -1.0,\n-    1.0,\n-    1.0,\n-    1.0,\n-    -1.0,\n-    1.0,\n+    1.0,   # Index 0 – weight for forecast component 0\n+    1.0,   # Index 1 – weight for forecast component 1\n+    -1.0,  # Index 2 – weight for forecast component 2\n+    -1.0,  # Index 3 – weight for forecast component 3\n+    1.0,   # Index 4 – weight for forecast component 4\n+    -1.0,  # Index 5 – weight for forecast component 5\n+    1.0,   # Index 6 – weight for forecast component 6\n+    1.0,   # Index 7 – weight for forecast component 7\n+    1.0,   # Index 8 – weight for forecast component 8\n+    -1.0,  # Index 9 – weight for forecast component 9\n+    1.0,   # Index 10 – weight for forecast component 10\n ]\n \n warnings.simplefilter(\"ignore\")\n"}]},{"message":"Logger name should follow Python module naming conventions. Consider using __name__ instead of hardcoded string to maintain consistency and enable proper logger hierarchy.","fixFiles":[{"filePath":"src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py","diff":"diff --git a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n--- a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n+++ b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n@@ -342,7 +342,7 @@\n         >>> print(f\"Model Metrics: {metrics}\")\n         >>> print(f\"Feature Info: {features}\")\n     \"\"\"\n-    logger = logging.getLogger(\"task_safe_n_to_1\")\n+    logger = logging.getLogger(__name__)\n \n     # Security: Mask sensitive coordinates immediately (CWE-532, CWE-312)\n     # This prevents raw latitude/longitude from being accessed in logging contexts\n"}]},{"message":"Logger name should follow Python module naming conventions. Consider using __name__ instead of hardcoded string to maintain consistency and enable proper logger hierarchy.","fixFiles":[{"filePath":"src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py","diff":"diff --git a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n--- a/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n+++ b/src/spotforecast2_safe/tasks/task_safe_n_to_1_with_covariates_and_dataframe.py\n@@ -512,7 +512,7 @@\n             level=logging.INFO if verbose else logging.WARNING, log_dir=log_dir\n         )\n     else:\n-        logger = logging.getLogger(\"task_safe_n_to_1\")\n+        logger = logging.getLogger(__name__)\n         logger.addHandler(logging.NullHandler())\n \n     if weights is None:\n"}]},{"message":"The exception handling logs the exception message str(e) which could potentially contain sensitive data from the underlying function calls. Consider sanitizing or filtering the exception message befor...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov

codecov Bot commented Feb 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…ates_and_dataframe.py

Co-authored-by: bartzbeielstein <32470350+bartzbeielstein@users.noreply.github.com>
Copilot AI changed the title [WIP] Update warning suppression to be more specific Refine warning suppression, logger naming, and exception sanitization Feb 11, 2026
@bartzbeielstein bartzbeielstein marked this pull request as ready for review February 11, 2026 20:25
@bartzbeielstein bartzbeielstein merged commit 3b4ea64 into main Feb 11, 2026
12 checks passed
@bartzbeielstein bartzbeielstein deleted the copilot/update-warning-suppression branch February 11, 2026 22:37
bartzbeielstein pushed a commit that referenced this pull request Jun 7, 2026
## [19.1.0-rc.1](v19.0.0...v19.1.0-rc.1) (2026-06-07)

### Features

* **configurator:** convert ConfigMulti and ConfigEntsoe to dataclasses ([184a3d9](184a3d9)), closes [#4](#4)
bartzbeielstein pushed a commit that referenced this pull request Jun 7, 2026
## [19.1.0](v19.0.0...v19.1.0) (2026-06-07)

### Features

* **configurator:** convert ConfigMulti and ConfigEntsoe to dataclasses ([184a3d9](184a3d9)), closes [#4](#4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants