Skip to content

Extending pre-existing RNTuple #1575

@Superharz

Description

@Superharz

Question

Is there an existing extending mechanism for already existing RNTuples in root files?

Versions

  • Python: 3.13.12
  • Uproot: 5.7.1
  • Awkward: 2.8.12
  • Numpy: 2.4.2

File Creation

I have created a RNTuple in a file as described in the docs:

with uproot.recreate("example.root") as file:
    data = {"my_int": [1,2], "my_vector": [[1,2], [3,4,5]]}
    rntuple = file.mkrntuple("my_rntuple", data)

RNTuple extending

Now I would like to later reopen this file and extend the RNTuple:

with uproot.open("example.root:my_rntuple") as rntuple:
    data = {"my_int": [1,2], "my_vector": [[1,2], [3,4,5]]}
    rntuple.extend(data)

This results in

AttributeError: 'Model_ROOT_3a3a_RNTuple' object has no attribute 'extend'

I also tried to use uproot.update:

with uproot.update("example.root") as file:
    data = {"my_int": [1,2], "my_vector": [[1,2], [3,4,5]]}
    rntuple = file["my_rntuple"]
    rntuple.extend(data)

This results in

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[61], line 3
      1 with uproot.update("example.root") as file:
      2     data = {"my_int": [1,2], "my_vector": [[1,2], [3,4,5]]}
----> 3     rntuple = file["my_rntuple"]
      4     rntuple.extend(data)

File [\Lib\site-packages\uproot\writing\writable.py:983](Lib/site-packages/uproot/writing/writable.py#line=982), in WritableDirectory.__getitem__(self, where)
    981 if self._file.sink.closed:
    982     raise ValueError("cannot get data from a closed file")
--> 983 return self._get_del_search(where, True)

File [\Lib\site-packages\uproot\writing\writable.py:976](Lib/site-packages/uproot/writing/writable.py#line=975), in WritableDirectory._get_del_search(self, where, isget)
    973     item, cycle = where, None
    975 if isget:
--> 976     return self._get(item, cycle)
    977 else:
    978     return self._del(item, cycle)

File [\Lib\site-packages\uproot\writing\writable.py:1020](Lib/site-packages/uproot/writing/writable.py#line=1019), in WritableDirectory._get(self, name, cycle)
   1018         return self._file._get_ntuple(key.seek_location)
   1019     else:
-> 1020         raise TypeError(
   1021             "WritableDirectory cannot view preexisting RNTuple; open the file with uproot.open instead of uproot.recreate or uproot.update"
   1022         )
   1024 else:
   1026     def get_chunk(start, stop):

TypeError: WritableDirectory cannot view preexisting RNTuple; open the file with uproot.open instead of uproot.recreate or uproot.update

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions