Skip to content

Commit

Permalink
ressurect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgray committed May 15, 2024
1 parent c075935 commit 238156e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 124 deletions.
14 changes: 7 additions & 7 deletions tests/test_hist_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def fill_lepton_kinematics():
ak.behavior.update(candidate.behavior)

# histogram creation and manipulation
from coffea import hist
from coffea.jitters import hist

fin = uproot.open("HZZ.root")
tree = fin["events"]
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_plot1d():

plt.switch_backend("agg")

from coffea import hist
from coffea.jitters import hist

lepton_kinematics = fill_lepton_kinematics()

Expand Down Expand Up @@ -96,7 +96,7 @@ def test_plot2d():
# matplotlib
import matplotlib.pyplot as plt

from coffea import hist
from coffea.jitters import hist

plt.switch_backend("agg")

Expand All @@ -115,7 +115,7 @@ def test_plotratio():
# matplotlib
import matplotlib.pyplot as plt

from coffea import hist
from coffea.jitters import hist

plt.switch_backend("agg")

Expand Down Expand Up @@ -238,7 +238,7 @@ def test_plotgrid():
# matplotlib
import matplotlib.pyplot as plt

from coffea import hist
from coffea.jitters import hist

plt.switch_backend("agg")

Expand Down Expand Up @@ -268,7 +268,7 @@ def test_plotgrid():


def test_clopper_pearson_interval():
from coffea.hist.plot import clopper_pearson_interval
from coffea.jitters.hist.plot import clopper_pearson_interval

# Reference values for CL=0.6800 calculated with ROOT's TEfficiency
num = np.array([1.0, 5.0, 10.0, 10.0])
Expand All @@ -293,7 +293,7 @@ def test_clopper_pearson_interval():


def test_normal_interval():
from coffea.hist.plot import normal_interval
from coffea.jitters.hist.plot import normal_interval

# Reference weighted efficiency and error from ROOTs TEfficiency

Expand Down
119 changes: 2 additions & 117 deletions tests/test_hist_tools.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys

import awkward as ak
import numpy as np
import pytest
from dummy_distributions import dummy_jagged_eta_pt

from coffea import hist
from coffea.jitters import hist


def test_hist():
Expand Down Expand Up @@ -217,38 +215,6 @@ def test_hist():
assert h_less.sum("vocalization", "height", "mass", "animal").values()[()] == 1004.0


def test_export1d():
import os

import uproot3

from coffea.hist.export import export1d

counts, test_eta, test_pt = dummy_jagged_eta_pt()
h_regular_bins = hist.Hist("regular_joe", hist.Bin("x", "x", 20, 0, 200))
h_regular_bins.fill(x=test_pt)

hout = export1d(h_regular_bins)

filename = "test_export1d.root"

with uproot3.create(filename) as fout:
fout["regular_joe"] = hout
fout.close()

with uproot3.open(filename) as fin:
hin = fin["regular_joe"]

assert np.all(hin.edges == hout.edges)
assert np.all(hin.values == hout.values)

del hin
del fin

if os.path.exists(filename):
os.remove(filename)


def test_hist_serdes():
import pickle

Expand Down Expand Up @@ -291,89 +257,8 @@ def test_hist_serdes_labels():
assert h._axes == hnew._axes


@pytest.mark.skipif(
sys.version_info < (3, 4),
reason="requires python3.4 or higher, test file is pickle proto 4",
)
def test_hist_compat():
from coffea.util import load

test = load("tests/samples/old_hist_format.coffea")

expected_bins = np.array(
[
-np.inf,
0.0,
20.0,
40.0,
60.0,
80.0,
100.0,
120.0,
140.0,
160.0,
180.0,
200.0,
220.0,
240.0,
260.0,
280.0,
300.0,
320.0,
340.0,
360.0,
380.0,
400.0,
420.0,
440.0,
460.0,
480.0,
500.0,
520.0,
540.0,
560.0,
580.0,
600.0,
620.0,
640.0,
660.0,
680.0,
700.0,
720.0,
740.0,
760.0,
780.0,
800.0,
820.0,
840.0,
860.0,
880.0,
900.0,
920.0,
940.0,
960.0,
980.0,
1000.0,
1020.0,
1040.0,
1060.0,
1080.0,
1100.0,
1120.0,
1140.0,
1160.0,
1180.0,
1200.0,
np.inf,
np.nan,
]
)
assert np.all(test._axes[2]._interval_bins[:-1] == expected_bins[:-1])
assert np.isnan(test._axes[2]._interval_bins[-1])


def test_issue_247():
from coffea import hist
from coffea.jitters import hist

h = hist.Hist("stuff", hist.Bin("old", "old", 20, -1, 1))
h.fill(old=h.axis("old").centers())
Expand Down

0 comments on commit 238156e

Please sign in to comment.