-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add TLeafC - string - writing support #940
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ba740a5
feat: add TLeafC - string - writing support
ioanaif b7eb44a
style: pre-commit fixes
pre-commit-ci[bot] 260e390
Rename test file to match PR nr.
ioanaif fe2e8f3
Fixes logic for string offset size and adds test for strings with mor…
ioanaif 307edf1
Check files created can be read with ROOT also and make the uncompres…
ioanaif 602270b
Hard code the fix for the tests just to show where the problem comes …
ioanaif f04d1a0
Merge branch 'main' into ioanaif/add-TLeafC-support
ioanaif 88568cd
Adds fLen computation and updating in the case of writing TLeafC.
ioanaif 8ce9d64
style: pre-commit fixes
pre-commit-ci[bot] e9849bd
Merge branch 'main' into ioanaif/add-TLeafC-support
ioanaif a0e6d66
Reverts fLen to 1.
ioanaif 3f2fae2
Moves computation of fLen max to strings.
ioanaif 51bdc33
style: pre-commit fixes
pre-commit-ci[bot] a1269fe
Add some stress-tests for extremes and corner-cases.
jpivarski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import pytest | ||
import os | ||
import awkward as ak | ||
import uproot | ||
|
||
ROOT = pytest.importorskip("ROOT") | ||
|
||
|
||
def test_write_tfleac_uproot_1(tmp_path): | ||
filename = os.path.join(tmp_path, "tleafc_test_write_1.root") | ||
|
||
with uproot.recreate(filename) as f: | ||
array = ak.Array(["one", "two", "three"]) | ||
f["tree"] = {"branch": array} | ||
|
||
rf = ROOT.TFile(filename) | ||
data = rf.Get("tree") | ||
assert data.GetLeaf("branch").Class_Name() == "TLeafC" | ||
assert [entry.branch for entry in data] == ["one", "two", "three"] | ||
rf.Close() | ||
|
||
with uproot.open(filename) as g: | ||
assert g["tree"]["branch"].array().tolist() == ["one", "two", "three"] | ||
|
||
|
||
def test_write_tfleac_uproot_2(tmp_path): | ||
filename = os.path.join(tmp_path, "tleafc_test_write_2.root") | ||
|
||
with uproot.recreate(filename) as f: | ||
array = ak.Array( | ||
["unu", "doi", "trei", "patru", "cinci", "sase", "sapte", "opt"] | ||
) | ||
f["tree"] = {"branch": array} | ||
|
||
rf = ROOT.TFile(filename) | ||
data = rf.Get("tree") | ||
assert data.GetLeaf("branch").Class_Name() == "TLeafC" | ||
assert [entry.branch for entry in data] == [ | ||
"unu", | ||
"doi", | ||
"trei", | ||
"patru", | ||
"cinci", | ||
"sase", | ||
"sapte", | ||
"opt", | ||
] | ||
rf.Close() | ||
|
||
with uproot.open(filename) as g: | ||
assert g["tree"]["branch"].array().tolist() == [ | ||
"unu", | ||
"doi", | ||
"trei", | ||
"patru", | ||
"cinci", | ||
"sase", | ||
"sapte", | ||
"opt", | ||
] | ||
|
||
|
||
def test_write_tfleac_uproot_3(tmp_path): | ||
filename = os.path.join(tmp_path, "tleafc_test_write_3.root") | ||
|
||
with uproot.recreate(filename) as f: | ||
array = ak.Array(["zero", "one" * 100, "two", "three" * 100, "four", "five"]) | ||
f["tree"] = {"branch": array} | ||
|
||
rf = ROOT.TFile(filename) | ||
data = rf.Get("tree") | ||
assert data.GetLeaf("branch").Class_Name() == "TLeafC" | ||
assert [entry.branch for entry in data] == [ | ||
"zero", | ||
"one" * 100, | ||
"two", | ||
"three" * 100, | ||
"four", | ||
"five", | ||
] | ||
rf.Close() | ||
ioanaif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with uproot.open(filename) as g: | ||
assert g["tree"]["branch"].array().tolist() == [ | ||
"zero", | ||
"one" * 100, | ||
"two", | ||
"three" * 100, | ||
"four", | ||
"five", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)