Skip to content

Commit

Permalink
Model.parent should point to the concrete instance, not the objects r…
Browse files Browse the repository at this point in the history
…eferring to base class data. (#53)

* Model.parent should point to the concrete instance, not the objects referring to base class data.

* Objects in TClonesArrays need an extra level of jaggedness.

* Make TRefArray accessible in Awkward.

* TRefArrays in TClonesArrays can now be read and converted into Awkward.

* Distinguish between branches with the same name in cache_key and object_path.
  • Loading branch information
jpivarski authored Jul 20, 2020
1 parent ee3a8b4 commit bfcdf58
Show file tree
Hide file tree
Showing 20 changed files with 922 additions and 173 deletions.
6 changes: 3 additions & 3 deletions tests/test_0017-multi-basket-multi-branch-fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ def test_cache():
skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root")
) as f:
assert f.cache_key == "db4be408-93ad-11ea-9027-d201a8c0beef:/"
assert f["sample"].cache_key == "db4be408-93ad-11ea-9027-d201a8c0beef:/sample"
assert f["sample"].cache_key == "db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1"
assert (
f["sample/i4"].cache_key
== "db4be408-93ad-11ea-9027-d201a8c0beef:/sample:i4"
== "db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:i4(16)"
)
i4 = f["sample/i4"]
assert list(f.array_cache) == []
i4.array(uproot4.interpretation.numerical.AsDtype(">i4"), library="np")
assert list(f.array_cache) == [
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample:i4:AsDtype(Bi4(),Li4()):0-30:np"
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:i4(16):AsDtype(Bi4(),Li4()):0-30:np"
]

with pytest.raises(OSError):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_0018-array-fetching-interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_compute():

assert set(sample.file.array_cache) == set(
[
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample:i4:AsDtype(Bi4(),Li4()):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample:Ai8:AsJagged(AsDtype(Bi8(),Li8()),0):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:i4:AsDtype(Bi4(),Li4()):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:Ai8:AsJagged(AsDtype(Bi8(),Li8()),0):0-30:ak",
]
)

Expand Down Expand Up @@ -189,8 +189,8 @@ def test_arrays():

assert set(sample.file.array_cache) == set(
[
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample:i4:AsDtype(Bi4(),Li4()):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample:f4:AsDtype(Bf4(),Lf4()):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:i4:AsDtype(Bi4(),Li4()):0-30:ak",
"db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:f4:AsDtype(Bf4(),Lf4()):0-30:ak",
]
)

Expand Down
349 changes: 349 additions & 0 deletions tests/test_0053-parents-should-not-be-bases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE

from __future__ import absolute_import

import numpy
import pytest
import skhep_testdata

import uproot4


def test_TRefArray():
with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t:
array = t["GenJet.Particles"].array(entry_stop=1, library="np")[0]
assert len(array) == 7
assert array[0].refs.tolist() == [
2396,
2320,
2075,
2483,
2479,
2499,
2259,
1865,
2078,
2482,
2503,
2477,
2502,
2480,
2061,
2077,
2393,
2376,
2496,
2504,
2495,
2505,
1318,
1317,
2506,
2076,
2346,
2501,
2107,
1957,
2241,
1823,
2242,
1825,
1863,
2399,
1824,
1866,
2497,
1996,
2345,
1864,
2243,
1821,
2244,
]
assert array[1].refs.tolist() == [
2370,
1830,
2371,
2024,
1412,
2250,
1530,
2500,
2498,
2388,
1949,
1885,
2055,
2069,
2368,
2054,
2059,
2272,
2053,
2367,
]


def test_awkward_TRefArray():
awkward1 = pytest.importorskip("awkward1")
with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t:
assert t["GenJet.Particles"].array(entry_stop=1)[0].tolist() == [
{
"fName": "",
"fSize": 45,
"refs": [
2396,
2320,
2075,
2483,
2479,
2499,
2259,
1865,
2078,
2482,
2503,
2477,
2502,
2480,
2061,
2077,
2393,
2376,
2496,
2504,
2495,
2505,
1318,
1317,
2506,
2076,
2346,
2501,
2107,
1957,
2241,
1823,
2242,
1825,
1863,
2399,
1824,
1866,
2497,
1996,
2345,
1864,
2243,
1821,
2244,
],
},
{
"fName": "",
"fSize": 20,
"refs": [
2370,
1830,
2371,
2024,
1412,
2250,
1530,
2500,
2498,
2388,
1949,
1885,
2055,
2069,
2368,
2054,
2059,
2272,
2053,
2367,
],
},
{
"fName": "",
"fSize": 21,
"refs": [
2284,
1883,
2282,
2108,
1939,
2102,
2356,
2005,
2236,
1364,
1770,
1882,
1840,
2249,
2446,
1985,
1839,
2248,
1365,
1841,
1842,
],
},
{
"fName": "",
"fSize": 31,
"refs": [
1379,
2123,
2090,
1378,
1593,
1836,
1862,
1859,
1904,
1984,
1322,
1383,
2074,
2257,
1591,
1382,
2357,
1954,
2066,
2256,
2010,
2011,
2490,
2251,
2343,
1993,
2344,
1846,
1992,
1843,
1845,
],
},
{
"fName": "",
"fSize": 26,
"refs": [
1989,
1911,
1990,
1629,
2277,
2419,
2139,
2292,
1618,
2518,
2519,
2516,
2509,
2135,
2136,
2514,
2517,
2510,
2512,
2420,
2402,
1619,
1617,
2494,
1400,
2511,
],
},
{
"fName": "",
"fSize": 32,
"refs": [
2082,
2445,
1868,
1893,
2384,
2081,
1512,
2263,
2261,
1870,
2398,
2017,
1849,
2401,
1875,
2387,
1872,
2315,
2260,
1873,
2386,
1522,
1874,
2083,
1775,
2086,
2237,
2087,
1876,
2084,
2264,
2265,
],
},
{
"fName": "",
"fSize": 26,
"refs": [
2266,
1847,
1894,
2142,
2291,
1599,
1774,
1916,
2200,
2129,
2148,
2146,
2143,
2144,
2145,
1913,
2290,
2421,
1918,
1706,
2137,
1914,
2289,
1915,
1627,
1628,
],
},
]


def test_same_names():
with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t:
one, two = t.values(filter_name="Particle_size")
assert (
one.cache_key
== "ac4a884e-c931-11ea-a7a5-c78b2480beef:/Delphes;1:Particle_size(3)"
)
assert (
two.cache_key
== "ac4a884e-c931-11ea-a7a5-c78b2480beef:/Delphes;1:Particle_size(17)"
)
assert one.object_path == "/Delphes;1:Particle_size"
assert two.object_path == "/Delphes;1:Particle_size"
Loading

0 comments on commit bfcdf58

Please sign in to comment.