Skip to content

Commit

Permalink
fix: allow colon in key names (#1127)
Browse files Browse the repository at this point in the history
* fix: allow column in key names

* style: pre-commit fixes

* Rename test file to match PR number.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ioanaif and pre-commit-ci[bot] authored Feb 15, 2024
1 parent 71cca34 commit 8a42e7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/uproot/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,8 @@ def __getitem__(self, where):
keys=[key.fName for key in last._keys],
file_path=self._file.file_path,
)
elif ":" in item and item in step:
return self.key(where).get()
else:
last = step
step = step[item]
Expand Down
26 changes: 26 additions & 0 deletions tests/test_1127_fix_allow_colon_in_key_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import awkward as ak
import uproot
import skhep_testdata
import numpy
import os


def test_colon_in_path_and_name(tmp_path):
newfile = os.path.join(tmp_path, "test_colon_in_name.root")
with uproot.recreate(newfile) as f:
f["one:two"] = "together"
array = ak.Array(["one", "two", "three"])
f["one"] = {"two": array}

with uproot.open(newfile) as f:
f["one:two"] == "together"
f["one"]["two"].array() == ["one", "two", "three"]


def test_colon_reading_in_path():
with uproot.open(
skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root")
) as f:
f["tree:evt/P3/P3.Py"].array() == numpy.arange(100)

0 comments on commit 8a42e7d

Please sign in to comment.