scikit-hep / awkward

Manipulate JSON-like data with NumPy-like idioms.
https://awkward-array.org
BSD 3-Clause "New" or "Revised" License
821 stars 85 forks source link

`ak.unflatten` can't deal with int64 datatype for counts #1083

Closed gordonwatts closed 3 years ago

gordonwatts commented 3 years ago

Version of Awkward Array

1.4

Description and code to reproduce

The following seems like it should work, but does not due to type error on counts:

counts = ak.Array([0, 1, 2])
data = ak.Array([1.1, 2.1, 2.2])
print(counts.type)
ak.unflatten(counts, data)

Output:

3 * int64

ValueError: counts must be integers

(https://github.com/scikit-hep/awkward-1.0/blob/1.4.0/src/awkward/operations/structure.py#L1988)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-bb8eaec2314e> in <module>
      1 # The KDE can deal with numpy, but not with akward, so we have to unfold and refold
----> 2 jet_probs = ak.unflatten(jet_pts.counts, trigger_jet_pt_probabilities_kde(jet_pts.flatten()))
      3 jet_probs[~ good_jet_mask] = 0.0

/LLPData/gwatts/calratio_abcd_ml/.conda_env/lib/python3.9/site-packages/awkward/operations/structure.py in unflatten(array, counts, axis, highlevel, behavior)
   1985             )
   1986         if not issubclass(counts.dtype.type, np.integer):
-> 1987             raise ValueError(
   1988                 "counts must be integers" + ak._util.exception_suffix(__file__)
   1989             )

ValueError: counts must be integers

(https://github.com/scikit-hep/awkward-1.0/blob/1.4.0/src/awkward/operations/structure.py#L1988)
agoose77 commented 3 years ago

You're passing in the data in the counts argument, which is causing the error. Try switching them around, that should fix it!

gordonwatts commented 3 years ago

Yeah - I just realized that when I started modifying the code. I'd just replaced the old from_counts with this one and didn't catch the arguments reversed. My bad, sorry for the noise!