How to reset the kEntriesReshuffled bin in pyroot?

Ok, that’s very interesting. So there are two things and btw I’m also on ROOT v6.22.
First, I was using a TChain to load my ntuple and if I check the value of the bit it’s already “False”. I modified a bit your example to reproduce this. So this might be a bug in TChain.
Second, if I load the ntuple with TFile and TTree and reset the bin correclty, I can add the Friend tree. However, if I load the ntuple with the friendtree in a RDataFrame, as it is suggested in the documentation, I get again the error message :

Error in : Tree ‘t’ has the kEntriesReshuffled bit set, and cannot be used as friend nor can be added as a friend unless the main tree has a TTreeIndex on the friend tree ‘t2’. You can also unset the bit manually if you know what you are doing.

So this might be a bug in RDataFrame. I also modified a bit your example to reproduce this.

import ROOT

ROOT.EnableImplicitMT()
ROOT.RDataFrame(10).Define("x", "42").Snapshot("t", "f.root")

chain = ROOT.TChain("t")
chain.Add("f.root")
print(chain.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))

f = ROOT.TFile("f.root")
t = f.Get("t")
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))
t.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))

ROOT.RDataFrame(10).Define("y", "43").Snapshot("t2", "f2.root")
f2 = ROOT.TFile("f2.root")
t2 = f2.Get("t2")
t2.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
t.AddFriend(t2)

rdf = ROOT.RDataFrame(t)
h = rdf.Histo1D("x")
h.Draw()