Skip to content

Commit

Permalink
[df] Add DistRDF test for DefaultValueFor, FilterAvailable, FilterMis…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
gpetruc committed Dec 11, 2024
1 parent e068831 commit 4556a5a
Showing 1 changed file with 29 additions and 0 deletions.
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__])

0 comments on commit 4556a5a

Please sign in to comment.