Skip to content

[BUG] Ensure CompositeMetric.__add__ and __mul__ operators are immutable#2254

Open
Muhammad-Rebaal wants to merge 5 commits intosktime:mainfrom
Muhammad-Rebaal:composite-metric-add-mul-immutable
Open

[BUG] Ensure CompositeMetric.__add__ and __mul__ operators are immutable#2254
Muhammad-Rebaal wants to merge 5 commits intosktime:mainfrom
Muhammad-Rebaal:composite-metric-add-mul-immutable

Conversation

@Muhammad-Rebaal
Copy link
Copy Markdown
Contributor

Reference : #2253

Description

The __add__ and __mul__ operators for CompositeMetric were previously modifying self in-place instead of returning newly instantiated objects. This violates typical python magic-method behavior and caused silent logical bugs where building multiple different composite sets out of a base metric modified the base itself permanently.

Changes Made

  • Updated __add__ and __mul__ in _base_metrics.py to copy the internal arrays and construct a fresh CompositeMetric instance off the copied data.

CC : @phoeenniixx , @PranavBhatP , @fkiraly

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@a03b984). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2254   +/-   ##
=======================================
  Coverage        ?   86.97%           
=======================================
  Files           ?      166           
  Lines           ?     9769           
  Branches        ?        0           
=======================================
  Hits            ?     8497           
  Misses          ?     1272           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.97% <100.00%> (?)
pytest 86.97% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@phoeenniixx phoeenniixx changed the title fix: Ensure CompositeMetric.__add__ and __mul__ operators are immutable [BUG] Ensure CompositeMetric.__add__ and __mul__ operators are immutable Apr 11, 2026
Copy link
Copy Markdown
Member

@phoeenniixx phoeenniixx left a comment

Choose a reason for hiding this comment

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

Thanks!
Can you please add a minimal test to make sure it is working as expected?

@Muhammad-Rebaal
Copy link
Copy Markdown
Contributor Author

Hi @phoeenniixx,
Kindly review this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Development

Successfully merging this pull request may close these issues.

2 participants