Skip to content

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

Open
guitargeek wants to merge 2 commits into
root-project:masterfrom
guitargeek:rooargset
Open

[Python] Deprecate conversion from Python set to RooArgSet#22657
guitargeek wants to merge 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) whithout thinking
too much about this footgun.
guitargeek
guitargeek
committed
3 minutes ago

@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

    21 files      21 suites   3d 8h 37m 43s ⏱️
 3 869 tests  3 869 ✅ 0 💤 0 ❌
72 622 runs  72 622 ✅ 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.
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.

1 participant