Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #344 from scikit-hep/issue336
Browse files Browse the repository at this point in the history
Fix append method of TTree
  • Loading branch information
reikdas committed Sep 20, 2019
2 parents 41068e3 + c11d47d commit 5f4443b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,3 +1887,18 @@ def test_issue340(tmp_path):
t = uproot.open(filename)["t"]
for i in range(10):
assert t["normal"].basket(0)[i] == a[i]

def test_basket_append(tmp_path):
filename = join(str(tmp_path), "example.root")

b = newbranch("int32")
branchdict = {"intBranch": b}
tree = newtree(branchdict)
with uproot.recreate(filename, compression=None) as f:
f["t"] = tree
f["t"].append({"intBranch": 1})

f = ROOT.TFile.Open(filename)
tree = f.Get("t")
treedata = tree.AsMatrix().astype(">i4")
assert treedata[0] == 1
8 changes: 4 additions & 4 deletions uproot/write/objects/TTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def extend(self, branchdict, flush=True):
self._branches[key]._branch.treecheck = 0

def append(self, branchdict):
for value in branchdict.values:
if len(value) != 1:
raise Exception("The length of all the baskets should be 1")
self.extend(branchdict, flush=False)
appenddict = {}
for key, value in branchdict.items():
appenddict[key] = [value]
self.extend(appenddict, flush=False)

def flush(self):
for key in self._branches.keys():
Expand Down

0 comments on commit 5f4443b

Please sign in to comment.