Skip to content
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

[df] Add DistRDF test for DefaultValueFor, FilterAvailable, … #1241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/distrdf/backends/check_definepersample.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ def declare_definepersample_code():
for count in samplescounts:
assert count.GetValue() == 10, f"{count.GetValue()=}"

def test_defaults_and_missing(self, payload):
"""
Test DefaultValueFor, FilterAvailable, FilterMissing operations
string of operations.
"""
filenames = [
f"../data/ttree/distrdf_roottest_check_rungraphs.root", # 10k entries, defining b1, b2, b3 (Int_t), all always equal to 42
f"../data/ttree/distrdf_roottest_check_reducer_merge_1.root", # 100 entries defining 'v' (Double_t)
]
connection, backend = payload
if backend == "dask":
RDataFrame = ROOT.RDF.Experimental.Distributed.Dask.RDataFrame
df = RDataFrame("tree", filenames, daskclient=connection)
elif backend == "spark":
RDataFrame = ROOT.RDF.Experimental.Distributed.Spark.RDataFrame
df = RDataFrame("tree", filenames, sparkcontext=connection)

c10k = df.FilterAvailable("b1").Count()
c100 = df.FilterAvailable("v").Count()
c100b = df.FilterMissing("b1").Count()
cD10k = df.DefaultValueFor("b1",40).Filter("b1 == 42").Count()
cD10100 = df.DefaultValueFor("b1",42).Filter("b1 == 42").Count()
sV = df.DefaultValueFor("v",0.1).Sum("v")
assert c10k.GetValue() == 10000, f"{c10k.GetValue()=}"
assert c100.GetValue() == 100, f"{c100.GetValue()=}"
assert c100b.GetValue() == 100, f"{c100b.GetValue()=}"
assert cD10k.GetValue() == 10000, f"{cD10k.GetValue()=}"
assert cD10100.GetValue() == 10100, f"{cD10100.GetValue()=}"
assert sV.GetValue() == 5950.0, f"{sV.GetValue()=}"

if __name__ == "__main__":
pytest.main(args=[__file__])