Skip to content

Remove prod positive argument#275

Open
Mohammad-Tayyab-Frequenz wants to merge 2 commits intofrequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:remove-prod-positive-argument
Open

Remove prod positive argument#275
Mohammad-Tayyab-Frequenz wants to merge 2 commits intofrequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:remove-prod-positive-argument

Conversation

@Mohammad-Tayyab-Frequenz
Copy link
Contributor

Remove the production_is_positive toggle and standardize reporting metrics to always use PSC sign conventions (production is negative). Update all call sites and tests to pass -production where needed, and document the change in release notes.

  • Removed production_is_positive from reporting metrics helpers and add_energy_flows().
  • Standardized production sign handling by negating production inside metrics helpers.
  • Updated callers to pass -production where required.
  • Updated tests and release notes.

Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
@Mohammad-Tayyab-Frequenz Mohammad-Tayyab-Frequenz requested a review from a team as a code owner March 4, 2026 10:54
Copilot AI review requested due to automatic review settings March 4, 2026 10:54
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Mar 4, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the production_is_positive toggle and standardizes reporting metrics to follow PSC sign conventions, where production inputs are expected to be negative and are sign-corrected internally.

Changes:

  • Removed production_is_positive from reporting metrics helpers and add_energy_flows().
  • Updated add_energy_flows() to convert internally computed positive production totals back to PSC-negative before calling metrics helpers.
  • Updated tests and release notes to reflect the new fixed sign convention.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/frequenz/lib/notebooks/reporting/metrics/reporting_metrics.py Removes the toggle from helper APIs and makes production sign handling unconditional (PSC).
src/frequenz/lib/notebooks/reporting/utils/helpers.py Drops the toggle from add_energy_flows() and updates downstream helper calls to pass PSC-negative production.
src/frequenz/lib/notebooks/reporting/data_processing.py Updates add_energy_flows() call site for the new signature.
tests/test_reporting_metrics.py Updates the production sign convention in the asset production test (needs further consistency fixes).
RELEASE_NOTES.md Documents the breaking change and upgrade guidance.
Comments suppressed due to low confidence (1)

src/frequenz/lib/notebooks/reporting/utils/helpers.py:445

  • The comment says production is already positive, but the call converts production_total back to PSC-negative via * -1 before passing into production_excess(). Please reword this comment to reflect what the code is doing (e.g., production_total is positive after asset_production(), then converted back to PSC convention for downstream metrics helpers).
    # Surplus vs. consumption (production is already positive because of the above cleaning)
    df_flows["production_excess"] = production_excess(
        df_flows["production_total"] * -1,
        df_flows["consumption_total"],
    )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to 54
def production_excess(production: pd.Series, consumption: pd.Series) -> pd.Series:
"""Compute the excess production relative to consumption.

Calculates surplus by subtracting consumption from production and removing
negative results. Production is optionally sign-corrected first.

Args:
production: Series of production values (e.g., kW or MW).
production: Series of production values (PSC convention, negative).
consumption: Series of consumption values (same units as `production`).
production_is_positive: Whether production values are already positive.
If False, `production` is inverted before clipping.

Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

production_excess() docstring still says production is “optionally sign-corrected first”, but the function now always assumes PSC convention and unconditionally sign-corrects via asset_production(production). Please update the docstring to match the new behavior (remove “optionally” wording and clarify the expected PSC-negative input).

Copilot uses AI. Check for mistakes.
Comment on lines 139 to 142
Args:
production: Series of production values (e.g., kW or MW).
consumption: Series of consumption values (same units as `production`).
production_is_positive: Whether production values are already positive.
If False, `production` is inverted before clipping.

Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

production_self_consumption() now assumes PSC convention (production negative), but the Args section still describes production generically (“production values”), which can be misread as already-positive input. Please update the parameter docs here (and consistently for related self-* helpers if needed) to explicitly state PSC-negative production is expected.

Copilot uses AI. Check for mistakes.
Comment on lines 15 to +21
def test_asset_production_respects_sign_and_missing_values() -> None:
"""Positive flag controls sign inversion and NaNs stay missing."""
production = pd.Series([10, -5, None], index=pd.RangeIndex(3))
"""Production is negated and NaNs stay missing."""
production = pd.Series([-10, 5, None], index=pd.RangeIndex(3))

positive = metrics.asset_production(production, production_is_positive=True)
expected_positive = pd.Series([10.0, 0.0, float("nan")], index=production.index)
assert_series_equal(positive, expected_positive)

negative = metrics.asset_production(production, production_is_positive=False)
expected_negative = pd.Series([0.0, 5.0, float("nan")], index=production.index)
assert_series_equal(negative, expected_negative)
result = metrics.asset_production(production)
expected = pd.Series([10.0, 0.0, float("nan")], index=production.index)
assert_series_equal(result, expected)
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR standardizes PSC sign conventions (production negative), but there is still at least one test in this file that uses a positive production input for grid_consumption() (later in the file). Please update remaining tests to consistently pass PSC-negative production so they exercise the intended convention and don’t lock in the old behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants