Skip to content

Commit f43e79f

Browse files
authored
Merge branch 'main' into ariostas/fix_tprofiles
2 parents c29f076 + 7301d81 commit f43e79f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/uproot/writing/writable.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ def mkdir(self, name, *, initial_directory_bytes=None):
12371237
self._file.uuid_function(),
12381238
),
12391239
)
1240+
self._subdirs[head] = directory
12401241

12411242
elif key.classname.string not in ("TDirectory", "TDirectoryFile"):
12421243
raise TypeError(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE
2+
3+
import os
4+
5+
import uproot
6+
7+
8+
def test_mktree_repeated_same_subdir(tmp_path):
9+
newfile = os.path.join(tmp_path, "newfile.root")
10+
11+
with uproot.recreate(newfile) as f:
12+
f.mktree("tree/x", {"x": [1, 2, 3]})
13+
f.mktree("tree/y", {"x": [1, 2, 3]})
14+
f.mktree("tree/z", {"x": [1, 2, 3]})
15+
f.mktree("tree/w", {"x": [1, 2, 3]})
16+
17+
assert set(f.keys(cycle=False)) == {
18+
"tree",
19+
"tree/x",
20+
"tree/y",
21+
"tree/z",
22+
"tree/w",
23+
}
24+
25+
with uproot.open(newfile) as fin:
26+
assert set(fin.keys(cycle=False)) == {
27+
"tree",
28+
"tree/x",
29+
"tree/y",
30+
"tree/z",
31+
"tree/w",
32+
}
33+
34+
35+
def test_mkrntuple_repeated_same_subdir(tmp_path):
36+
newfile = os.path.join(tmp_path, "newfile.root")
37+
38+
with uproot.recreate(newfile) as f:
39+
f.mkrntuple("ntpl/x", {"x": [1, 2, 3]})
40+
f.mkrntuple("ntpl/y", {"x": [1, 2, 3]})
41+
f.mkrntuple("ntpl/z", {"x": [1, 2, 3]})
42+
f.mkrntuple("ntpl/w", {"x": [1, 2, 3]})
43+
44+
assert set(f.keys(cycle=False)) == {
45+
"ntpl",
46+
"ntpl/x",
47+
"ntpl/y",
48+
"ntpl/z",
49+
"ntpl/w",
50+
}
51+
52+
with uproot.open(newfile) as fin:
53+
assert set(fin.keys(cycle=False)) == {
54+
"ntpl",
55+
"ntpl/x",
56+
"ntpl/y",
57+
"ntpl/z",
58+
"ntpl/w",
59+
}

0 commit comments

Comments
 (0)