Skip to content

Commit 5c36558

Browse files
authored
fix: update tests to match new package structure (#17)
1 parent d7caa81 commit 5c36558

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

tests/test_hist_tools.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def test_hist():
3535

3636
h_regular_bins = cuda_histogram.Hist(
3737
"regular joe",
38-
cuda_histogram.Bin("x", "x", 20, 0, 200),
39-
cuda_histogram.Bin("y", "why", 20, -3, 3),
38+
cuda_histogram.axis.Bin("x", "x", 20, 0, 200),
39+
cuda_histogram.axis.Bin("y", "why", 20, -3, 3),
4040
)
4141
h_regular_bins.fill(x=test_pt, y=test_eta)
4242
nentries = np.sum(counts)
@@ -63,8 +63,8 @@ def test_hist():
6363
assert h_reduced.integrate("x", slice(20, 30)).values()[()][2] == count_some_bin + 1
6464
assert h_reduced.integrate("y", slice(0, 0.3)).values()[()][1] == count_some_bin + 1
6565

66-
animal = cuda_histogram.Cat("animal", "type of animal")
67-
vocalization = cuda_histogram.Cat(
66+
animal = cuda_histogram.axis.Cat("animal", "type of animal")
67+
vocalization = cuda_histogram.axis.Cat(
6868
"vocalization", "onomatopoiea is that how you spell it?"
6969
)
7070
h_cat_bins = cuda_histogram.Hist("I like cats", animal, vocalization)
@@ -80,14 +80,14 @@ def test_hist():
8080
("dog",)
8181
] == (101.0, 10001.0)
8282

83-
height = cuda_histogram.Bin("height", "height [m]", 10, 0, 5)
83+
height = cuda_histogram.axis.Bin("height", "height [m]", 10, 0, 5)
8484
h_mascots_1 = cuda_histogram.Hist(
8585
"fermi mascot showdown",
8686
animal,
8787
vocalization,
8888
height,
8989
# weight is a reserved keyword
90-
cuda_histogram.Bin(
90+
cuda_histogram.axis.Bin(
9191
"mass", "weight (g=9.81m/s**2) [kg]", np.power(10.0, np.arange(5) - 1)
9292
),
9393
)
@@ -99,7 +99,7 @@ def test_hist():
9999
vocalization,
100100
height,
101101
# weight is a reserved keyword
102-
cuda_histogram.Bin(
102+
cuda_histogram.axis.Bin(
103103
"mass", "weight (g=9.81m/s**2) [kg]", np.power(10.0, np.arange(5) - 1)
104104
),
105105
),
@@ -111,7 +111,7 @@ def test_hist():
111111
vocalization,
112112
height,
113113
# weight is a reserved keyword
114-
cuda_histogram.Bin(
114+
cuda_histogram.axis.Bin(
115115
"mass", "weight (g=9.81m/s**2) [kg]", np.power(10.0, np.arange(5) - 1)
116116
),
117117
],
@@ -125,15 +125,15 @@ def test_hist():
125125
vocalization,
126126
height,
127127
# weight is a reserved keyword
128-
cuda_histogram.Bin(
128+
cuda_histogram.axis.Bin(
129129
"mass", "weight (g=9.81m/s**2) [kg]", np.power(10.0, np.arange(5) - 1)
130130
),
131131
axes=[
132132
animal,
133133
vocalization,
134134
height,
135135
# weight is a reserved keyword
136-
cuda_histogram.Bin(
136+
cuda_histogram.axis.Bin(
137137
"mass",
138138
"weight (g=9.81m/s**2) [kg]",
139139
np.power(10.0, np.arange(5) - 1),
@@ -188,7 +188,7 @@ def test_hist():
188188
== 1040.0
189189
)
190190

191-
species_class = cuda_histogram.Cat(
191+
species_class = cuda_histogram.axis.Cat(
192192
"species_class", "where the subphylum is vertibrates"
193193
)
194194
classes = {
@@ -224,7 +224,9 @@ def test_hist():
224224
assert h_species.axis("height") is height
225225
assert h_species.integrate("vocalization", "h*").axis("height") is height
226226

227-
tall_class = cuda_histogram.Cat("tall_class", "species class (species above 1m)")
227+
tall_class = cuda_histogram.axis.Cat(
228+
"tall_class", "species class (species above 1m)"
229+
)
228230
mapping = {
229231
"birds": (["goose", "crane"], slice(1.0, None)),
230232
"mammals": (["bison", "fox"], slice(1.0, None)),
@@ -246,8 +248,8 @@ def test_hist_serdes():
246248

247249
h_regular_bins = cuda_histogram.Hist(
248250
"regular joe",
249-
cuda_histogram.Bin("x", "x", 20, 0, 200),
250-
cuda_histogram.Bin("y", "why", 20, -3, 3),
251+
cuda_histogram.axis.Bin("x", "x", 20, 0, 200),
252+
cuda_histogram.axis.Bin("y", "why", 20, -3, 3),
251253
)
252254

253255
h_regular_bins.fill(
@@ -269,7 +271,7 @@ def test_hist_serdes():
269271
def test_hist_serdes_labels():
270272
import pickle
271273

272-
ax = cuda_histogram.Bin("asdf", "asdf", 3, 0, 3)
274+
ax = cuda_histogram.axis.Bin("asdf", "asdf", 3, 0, 3)
273275
ax.identifiers()[0].label = "type 1"
274276
h = cuda_histogram.Hist("a", ax)
275277
h.identifiers("asdf")
@@ -288,9 +290,9 @@ def test_hist_serdes_labels():
288290
def test_issue_247():
289291
import cuda_histogram
290292

291-
h = cuda_histogram.Hist("stuff", cuda_histogram.Bin("old", "old", 20, -1, 1))
293+
h = cuda_histogram.Hist("stuff", cuda_histogram.axis.Bin("old", "old", 20, -1, 1))
292294
h.fill(old=h.axis("old").centers())
293-
h2 = h.rebin(h.axis("old"), cuda_histogram.Bin("new", "new", 10, -1, 1))
295+
h2 = h.rebin(h.axis("old"), cuda_histogram.axis.Bin("new", "new", 10, -1, 1))
294296
# check first if its even possible to have correct binning
295297
assert np.all(h2.axis("new").edges() == h.axis("old").edges()[::2])
296298
# make sure the lookup works properly
@@ -300,31 +302,31 @@ def test_issue_247():
300302

301303
with pytest.raises(ValueError):
302304
# invalid division
303-
_ = h.rebin(h.axis("old"), cuda_histogram.Bin("new", "new", 8, -1, 1))
305+
_ = h.rebin(h.axis("old"), cuda_histogram.axis.Bin("new", "new", 8, -1, 1))
304306

305-
newaxis = cuda_histogram.Bin(
307+
newaxis = cuda_histogram.axis.Bin(
306308
"new", "new", h.axis("old").edges()[np.cumsum([0, 2, 3, 5])]
307309
)
308310
h.rebin("old", newaxis)
309311

310312

311313
def test_issue_333():
312-
axis = cuda_histogram.Bin("channel", "Channel b1", 50, 0, 2000)
314+
axis = cuda_histogram.axis.Bin("channel", "Channel b1", 50, 0, 2000)
313315
temp = np.arange(0, 2000, 40, dtype=np.int16)
314316
assert np.all(axis.index(temp).get() == np.arange(50) + 1)
315317

316318

317319
def test_issue_394():
318320
dummy = cuda_histogram.Hist(
319321
"Dummy",
320-
cuda_histogram.Cat("sample", "sample"),
321-
cuda_histogram.Bin("dummy", "Number of events", 1, 0, 1),
322+
cuda_histogram.axis.Cat("sample", "sample"),
323+
cuda_histogram.axis.Bin("dummy", "Number of events", 1, 0, 1),
322324
)
323325
dummy.fill(sample="test", dummy=1, weight=0.5)
324326

325327

326328
def test_fill_none():
327-
dummy = cuda_histogram.Hist("Dummy", cuda_histogram.Bin("x", "asdf", 1, 0, 1))
329+
dummy = cuda_histogram.Hist("Dummy", cuda_histogram.axis.Bin("x", "asdf", 1, 0, 1))
328330
with pytest.raises(ValueError):
329331
# attempt to fill with none
330332
dummy.fill(x=ak.Array([0.1, None, 0.3]))
@@ -338,8 +340,8 @@ def test_boost_conversion():
338340

339341
dummy = cuda_histogram.Hist(
340342
"Dummy",
341-
cuda_histogram.Cat("sample", "sample"),
342-
cuda_histogram.Bin("dummy", "Number of events", 1, 0, 1),
343+
cuda_histogram.axis.Cat("sample", "sample"),
344+
cuda_histogram.axis.Bin("dummy", "Number of events", 1, 0, 1),
343345
)
344346
dummy.fill(sample="test", dummy=1, weight=0.5)
345347
dummy.fill(sample="test", dummy=0.1)
@@ -362,8 +364,8 @@ def test_boost_conversion():
362364

363365
dummy = cuda_histogram.Hist(
364366
"Dummy",
365-
cuda_histogram.Cat("sample", "sample"),
366-
cuda_histogram.Bin("dummy", "Number of events", 1, 0, 1),
367+
cuda_histogram.axis.Cat("sample", "sample"),
368+
cuda_histogram.axis.Bin("dummy", "Number of events", 1, 0, 1),
367369
)
368370
dummy.fill(sample="test", dummy=0.1)
369371
dummy.fill(sample="test", dummy=0.2)

0 commit comments

Comments
 (0)