Skip to content

[Python] Deprecate conversion from Python set to RooArgSet#22657

Merged
guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:rooargset
Jun 24, 2026
Merged

[Python] Deprecate conversion from Python set to RooArgSet#22657
guitargeek merged 2 commits into
root-project:masterfrom
guitargeek:rooargset

Conversation

@guitargeek

@guitargeek guitargeek commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

This conversion can lead to subtle problems because Python sets are
unordered, different from C++ initializer lists with the same syntax.
This can lead to confusion that we should prevent.

Example:

import ROOT

x = ROOT.RooRealVar("x", "x", 1.0)
y = ROOT.RooRealVar("y", "y", -1.0)

ROOT.RooArgSet(set([x, y])).Print()
ROOT.RooArgSet(set([y, x])).Print()

Gives on my system:

RooArgSet:: = (x,y)
RooArgSet:: = (x,y) <--- reverse order expected!

This is not even deterministic, because Python doesn't guarantee that
a set is ordered in any way.

I introduced this 5 years ago in commit guitargeek@c54c324
(PR #8751) without thinking
too much about this footgun.

@guitargeek guitargeek self-assigned this Jun 18, 2026
@guitargeek guitargeek requested a review from vepadulano as a code owner June 18, 2026 13:46
@guitargeek guitargeek force-pushed the rooargset branch 2 times, most recently from 602fa89 to 1ef2f17 Compare June 18, 2026 16:05
@guitargeek guitargeek requested review from couet and dpiparo as code owners June 18, 2026 16:05
@guitargeek guitargeek changed the title [Python] Remove explicit RooArgSet constructor Pythonization [Python] Deprecate conversion from Python set to RooArgSet Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

Test Results

    22 files      22 suites   3d 13h 11m 43s ⏱️
 3 869 tests  3 869 ✅ 0 💤 0 ❌
76 393 runs  76 393 ✅ 0 💤 0 ❌

Results for commit b2c978c.

♻️ This comment has been updated with latest results.

This conversion can lead to subtle problems because Python sets are
unordered, different from C++ initializer lists with the same syntax.
This can lead to confusion that we should prevent.

Example:
```python
import ROOT

x = ROOT.RooRealVar("x", "x", 1.0)
y = ROOT.RooRealVar("y", "y", -1.0)

ROOT.RooArgSet(set([x, y])).Print()
ROOT.RooArgSet(set([y, x])).Print()
```
Gives on my system:
```txt
RooArgSet:: = (x,y)
RooArgSet:: = (x,y) <--- reverse order expected!
```

This is not even deterministic, because Python doesn't guarantee that
a `set` is ordered in any way.

I introduced this 5 years ago in commit c54c324
(PR root-project#8751) whithout thinking
too much about this footgun.
This pattern should not be used, because it leaves the RooArgSet in a
non-deterministic ordering, depending on the implementation of Python.

@lmoneta lmoneta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! I agree to deprecate these conversions.

Are the changes breaking the current Python code using RooFit? This could be a potential issue, it should probably be very well documented!

@guitargeek

Copy link
Copy Markdown
Contributor Author

LGTM! I agree to deprecate these conversions.

Are the changes breaking the current Python code using RooFit? This could be a potential issue, it should probably be very well documented!

I don't think it doesn't break much Python code using RooFit in practice, because this implicit conversion was only introduced 5 years ago and is mainly used by the RooFit tutorials. Not sure exactly how much users picked it up, but I have not seen it in user code so far.

The release notes are including a clear statement about this documentation.

@guitargeek guitargeek merged commit ad16073 into root-project:master Jun 24, 2026
56 of 58 checks passed
@guitargeek guitargeek deleted the rooargset branch June 24, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants