Skip to content

Commit

Permalink
Make the multi-branch 'arrays' function stable. (#22)
Browse files Browse the repository at this point in the history
* Comment out multi-branch 'arrays' function to rethink it.

* The keys of 'arrays' (formerly 'output') will be 'id(branch)'.

* In a working state.

* First test of the new 'arrays' interface.

* MacOS is failing the XRootD tests.

* Interpretation tests.

* Simple computation.

* Cuts work.

* Aliases work.

* Fix 'typename'.

* Old tests work again.
  • Loading branch information
jpivarski authored Jun 17, 2020
1 parent 3e325b9 commit 84fa73d
Show file tree
Hide file tree
Showing 14 changed files with 1,094 additions and 466 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
conda list
- name: "install XRootD"
if: "${{ matrix.python-version != 3.5 && !contains(matrix.platform, 'windows') }}"
if: "${{ matrix.python-version != 3.5 && !contains(matrix.platform, 'macos') && !contains(matrix.platform, 'windows') }}"
shell: "bash -l {0}"
run: |
conda env list
Expand Down
22 changes: 11 additions & 11 deletions tests/test_0017-multi-basket-multi-branch-fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _names_entries_to_ranges_or_baskets(self, branch_names, entry_start, entry_s
for basket_num, range_or_basket in branch.entries_to_ranges_or_baskets(
entry_start, entry_stop
):
out.append((name, branch, basket_num, range_or_basket))
out.append((branch, basket_num, range_or_basket))
return out


Expand All @@ -100,9 +100,8 @@ def test_names_entries_to_ranges_or_baskets():
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root")
)["sample"] as sample:
out = _names_entries_to_ranges_or_baskets(sample, ["i4"], 0, 30)
assert all(x[0] == "i4" for x in out)
assert [x[2] for x in out] == [0, 1, 2, 3, 4]
assert [x[3] for x in out] == [
assert [x[1] for x in out] == [0, 1, 2, 3, 4]
assert [x[2] for x in out] == [
(6992, 7091),
(16085, 16184),
(25939, 26038),
Expand All @@ -126,18 +125,19 @@ def test_ranges_or_baskets_to_arrays():
interpretation_executor = uproot4.source.futures.TrivialExecutor()
library = uproot4.interpretation.library._libraries["np"]

output = {}
sample._ranges_or_baskets_to_arrays(
arrays = {}
uproot4.behaviors.TBranch._ranges_or_baskets_to_arrays(
sample,
ranges_or_baskets,
branchid_interpretation,
entry_start,
entry_stop,
decompression_executor,
interpretation_executor,
library,
output,
arrays,
)
assert output["i4"].tolist() == [
assert arrays[id(branch)].tolist() == [
-15,
-14,
-13,
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_branch_array_1(file_handler):
def test_branch_array_2(file_handler):
with uproot4.open(
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"),
file_handler=file_handler
file_handler=file_handler,
)["sample/i4"] as branch:
assert branch.array(
uproot4.interpretation.numerical.AsDtype(">i4"),
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_branch_array_2(file_handler):
def test_branch_array_3(file_handler):
with uproot4.open(
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"),
file_handler=file_handler
file_handler=file_handler,
)["sample/i4"] as branch:
assert branch.array(
uproot4.interpretation.numerical.AsDtype(">i4"),
Expand Down Expand Up @@ -300,7 +300,7 @@ def test_branch_array_3(file_handler):
def test_branch_array_4(file_handler):
with uproot4.open(
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"),
file_handler=file_handler
file_handler=file_handler,
)["sample/i4"] as branch:
with pytest.raises(ValueError):
branch.array(uproot4.interpretation.numerical.AsDtype(">i8"), library="np")
Expand Down
76 changes: 36 additions & 40 deletions tests/test_0018-array-fetching-interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,40 @@ def test_leaf_interpretation():
assert repr(sample["af8"].interpretation) == """AsDtype("('>f8', (3,))")"""
assert repr(sample["Af8"].interpretation) == """AsJagged(AsDtype('>f8'))"""

assert sample["n"].typename == "n/I"
assert sample["b"].typename == "b/O"
assert sample["ab"].typename == "ab[3]/O"
assert sample["Ab"].typename == "Ab[n]/O"
assert sample["i1"].typename == "i1/B"
assert sample["ai1"].typename == "ai1[3]/B"
assert sample["Ai1"].typename == "Ai1[n]/B"
assert sample["u1"].typename == "u1/B"
assert sample["au1"].typename == "au1[3]/B"
assert sample["Au1"].typename == "Au1[n]/B"
assert sample["i2"].typename == "i2/S"
assert sample["ai2"].typename == "ai2[3]/S"
assert sample["Ai2"].typename == "Ai2[n]/S"
assert sample["u2"].typename == "u2/S"
assert sample["au2"].typename == "au2[3]/S"
assert sample["Au2"].typename == "Au2[n]/S"
assert sample["i4"].typename == "i4/I"
assert sample["ai4"].typename == "ai4[3]/I"
assert sample["Ai4"].typename == "Ai4[n]/I"
assert sample["u4"].typename == "u4/I"
assert sample["au4"].typename == "au4[3]/I"
assert sample["Au4"].typename == "Au4[n]/I"
assert sample["i8"].typename == "i8/L"
assert sample["ai8"].typename == "ai8[3]/L"
assert sample["Ai8"].typename == "Ai8[n]/L"
assert sample["u8"].typename == "u8/L"
assert sample["au8"].typename == "au8[3]/L"
assert sample["Au8"].typename == "Au8[n]/L"
assert sample["f4"].typename == "f4/F"
assert sample["af4"].typename == "af4[3]/F"
assert sample["Af4"].typename == "Af4[n]/F"
assert sample["f8"].typename == "f8/D"
assert sample["af8"].typename == "af8[3]/D"
assert sample["Af8"].typename == "Af8[n]/D"
assert sample["n"].typename == "int32_t"
assert sample["b"].typename == "bool"
assert sample["ab"].typename == "bool[]"
assert sample["Ab"].typename == "bool[]"
assert sample["i1"].typename == "int8_t"
assert sample["ai1"].typename == "int8_t[]"
assert sample["Ai1"].typename == "int8_t[]"
assert sample["u1"].typename == "uint8_t"
assert sample["au1"].typename == "uint8_t[]"
assert sample["Au1"].typename == "uint8_t[]"
assert sample["i2"].typename == "int16_t"
assert sample["ai2"].typename == "int16_t[]"
assert sample["Ai2"].typename == "int16_t[]"
assert sample["u2"].typename == "uint16_t"
assert sample["au2"].typename == "uint16_t[]"
assert sample["Au2"].typename == "uint16_t[]"
assert sample["i4"].typename == "int32_t"
assert sample["ai4"].typename == "int32_t[]"
assert sample["Ai4"].typename == "int32_t[]"
assert sample["u4"].typename == "uint32_t"
assert sample["au4"].typename == "uint32_t[]"
assert sample["Au4"].typename == "uint32_t[]"
assert sample["i8"].typename == "int64_t"
assert sample["ai8"].typename == "int64_t[]"
assert sample["Ai8"].typename == "int64_t[]"
assert sample["u8"].typename == "uint64_t"
assert sample["au8"].typename == "uint64_t[]"
assert sample["Au8"].typename == "uint64_t[]"
assert sample["f4"].typename == "float"
assert sample["af4"].typename == "float[]"
assert sample["Af4"].typename == "float[]"
assert sample["f8"].typename == "double"
assert sample["af8"].typename == "double[]"
assert sample["Af8"].typename == "double[]"


def test_compute():
Expand All @@ -96,9 +96,7 @@ def test_compute():
with uproot4.open(
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root")
)["sample"] as sample:
result = sample.arrays(
["stuff", "i4"], aliases={"stuff": "abs(i4) + Ai8"}, functions={"abs": abs}
)
result = sample.arrays(["stuff", "i4"], aliases={"stuff": "abs(i4) + Ai8"})
assert result.tolist() == [
{"stuff": [], "i4": -15},
{"stuff": [-1], "i4": -14},
Expand Down Expand Up @@ -155,9 +153,7 @@ def test_arrays():
with uproot4.open(
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root")
)["sample"] as sample:
result = sample.arrays(
{"I4": interp_i4, "F4": interp_f4}, aliases={"I4": "i4", "F4": "f4"}
)
result = sample.arrays(["I4", "F4"], aliases={"I4": "i4", "F4": "f4"})
assert result.tolist() == [
{"I4": -15, "F4": -14.899999618530273},
{"I4": -14, "F4": -13.899999618530273},
Expand Down
Loading

0 comments on commit 84fa73d

Please sign in to comment.