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

Writing jagged array from tuple created by uproot #1318

Open
apoluekt opened this issue Oct 19, 2024 · 1 comment · May be fixed by #1319
Open

Writing jagged array from tuple created by uproot #1318

apoluekt opened this issue Oct 19, 2024 · 1 comment · May be fixed by #1319
Labels
bug The problem described is something that must be fixed

Comments

@apoluekt
Copy link

Hello,

I have an issue with writing the ntuple from the jagged array which was read in from another ntuple created by uproot:

import uproot

data = uproot.concatenate("data.root", library = "ak")

print(data.fields)
# data has two keys, in this case 'nLc_MCP_PseudoTypes' and 'Lc_MCP_PseudoTypes'. 

with uproot.recreate("data2.root", compression=uproot.ZLIB(4)) as file :
  input = {k : data[k] for k in data.fields}
  file["tree"] = input

This results in the following crash:

Traceback (most recent call last):
  File "mre.py", line 9, in <module>
    file["tree"] = input
    ~~~~^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/uproot/writing/writable.py", line 984, in __setitem__
    self.update({where: what})
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/uproot/writing/writable.py", line 1553, in update
    uproot.writing.identify.add_to_directory(v, name, directory, streamers)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/uproot/writing/identify.py", line 152, in add_to_directory
    tree.extend(data)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/uproot/writing/writable.py", line 1832, in extend
    self._cascading.extend(self._file, self._file.sink, data)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/uproot/writing/_cascadetree.py", line 588, in extend
    if kk in provided and not numpy.array_equal(vv, provided[kk]):
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/highlevel.py", line 1527, in __array_function__
    return ak._connect.numpy.array_function(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_connect/numpy.py", line 102, in array_function
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_connect/numpy.py", line 142, in ensure_valid_args
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_dispatch.py", line 64, in dispatch
    next(gen_or_result)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/operations/ak_array_equal.py", line 44, in array_equal
    return ak.operations.ak_almost_equal._impl(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/operations/ak_almost_equal.py", line 87, in _impl
    to_layout(left, allow_record=False),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_dispatch.py", line 64, in dispatch
    next(gen_or_result)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/operations/ak_to_layout.py", line 80, in to_layout
    return _impl(
           ^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/operations/ak_to_layout.py", line 177, in _impl
    promoted_layout = ak.operations.from_numpy(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_dispatch.py", line 39, in dispatch
    gen_or_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/operations/ak_from_numpy.py", line 56, in from_numpy
    from_arraylib(
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_layout.py", line 364, in from_arraylib
    layout = recurse(array, mask)
             ^^^^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/_layout.py", line 323, in recurse
    data = NumpyArray(array)
           ^^^^^^^^^^^^^^^^^
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/contents/numpyarray.py", line 123, in __init__
    ak.types.numpytype.dtype_to_primitive(self._data.dtype)
  File "/cvmfs/lhcbdev.cern.ch/conda/envs/pidgen/2024-10-15_18-48/linux-64/lib/python3.12/site-packages/awkward/types/numpytype.py", line 51, in dtype_to_primitive
    raise TypeError(
TypeError: unsupported dtype: dtype('>u4'). Must be one of

    bool, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, complex64, complex128, datetime64, timedelta64, float16, float128, complex256

or a datetime64/timedelta64 with units (e.g. 'datetime64[15us]')

This error occurred while calling

    ak.array_equal(
        numpy.ndarray([4 4 4 ... 4 4 4])
        <Array [4, 4, 4, 4, 4, 4, 4, 4, 4, 4] type='10 * int32'>
    )

uproot version is 5.4.1. data.root is attached. Thanks!
data.root.txt

@apoluekt apoluekt added the bug (unverified) The problem described would be a bug, but needs to be triaged label Oct 19, 2024
@jpivarski jpivarski added bug The problem described is something that must be fixed and removed bug (unverified) The problem described would be a bug, but needs to be triaged labels Oct 20, 2024
@jpivarski
Copy link
Member

It should be fixed in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The problem described is something that must be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants