Skip to content

feat: add awkward_form method for TMatrixTSym-v5 model#1610

Open
mrzimu wants to merge 1 commit intoscikit-hep:mainfrom
mrzimu:mrzimu/feat_add_ak_form_for_TMatrixTSym_v5
Open

feat: add awkward_form method for TMatrixTSym-v5 model#1610
mrzimu wants to merge 1 commit intoscikit-hep:mainfrom
mrzimu:mrzimu/feat_add_ak_form_for_TMatrixTSym_v5

Conversation

@mrzimu
Copy link
Copy Markdown
Contributor

@mrzimu mrzimu commented Mar 29, 2026

Hi,

I encountered a problem similar to issue #359. The difference is: in #359, they were trying to read a TMatrixTSym<double> directly from a ROOT file, while I'm trying to read it from a TTree.

I found that PR #484 did not implement awkward_form for Model_TMatrixTSym_3c_double_3e__v5, so I've added it.

The awkward form I added is derived from the awkward array that was read from a properly generated ROOT file (contains the streamer information of TMatrixTSym<double>, which allows Uproot to dynamically generate its model). So the form given by Model_TMatrixTSym_3c_double_3e__v5 should be consistent with that given by the dynamically-generated model.

I haven't added test yet (though I have tested on my PC), since I think it better to create this PR first, then upload the test file to scikit-hep-testdata. Please let me know if my modification is OK and I shall go ahead (upload test file, add test). :)


To reproduce the issue, run:

>>> import uproot
>>> f = uproot.open("issue_file.root")
>>> t = f["TMatrixTSymAnalysis"]
>>> t.show(name_width=40, typename_width=40)
name                                     | typename                                 | interpretation                
-----------------------------------------+------------------------------------------+-------------------------------
TMatrixTSymAnalysis                      | COMET::TMatrixTSymAnalysis               | AsGroup(<TBranchElement 'TM...
TMatrixTSymAnalysis/TObject              | (group of fUniqueID:uint32_t, fBits:u... | AsGroup(<TBranchElement 'TO...
TMatrixTSymAnalysis/TObject/fUniqueID    | uint32_t                                 | AsDtype('>u4')
TMatrixTSymAnalysis/TObject/fBits        | uint32_t                                 | AsDtype('>u4')
TMatrixTSymAnalysis/covMatrixOfTurn      | std::vector<TMatrixTSym<double>>         | AsObjects(AsVector(True, Mo...

>>> t["covMatrixOfTurn"].array()
Traceback (most recent call last):
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/behaviors/TBranch.py", line 2856, in _awkward_check
    interpretation.awkward_form(self.file)
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/interpretation/objects.py", line 142, in awkward_form
    return self._model.awkward_form(self._branch.file, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/containers.py", line 898, in awkward_form
    uproot._util.awkward_form(self._items, file, context),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/_util.py", line 560, in awkward_form
    return model.awkward_form(file, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/model.py", line 1196, in awkward_form
    return versioned_cls.awkward_form(file, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/model.py", line 687, in awkward_form
    raise uproot.interpretation.objects.CannotBeAwkward(
uproot.interpretation.objects.CannotBeAwkward: TMatrixTSym<double>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/behaviors/TBranch.py", line 2213, in array
    _ranges_or_baskets_to_arrays(
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/behaviors/TBranch.py", line 3422, in _ranges_or_baskets_to_arrays
    branchid_to_branch[cache_key]._awkward_check(interpretation)
  File "/home/mrli/work/my-uproot/uproot5/src/uproot/behaviors/TBranch.py", line 2858, in _awkward_check
    raise ValueError(
ValueError: cannot produce Awkward Arrays for interpretation AsObjects(AsVector(True, Model_TMatrixTSym_3c_double_3e_)) because

    TMatrixTSym<double>

instead, try library="np" rather than library="ak" or globally set uproot.default_library

in file issue_file.root
in object /TMatrixTSymAnalysis;1:TMatrixTSymAnalysis/covMatrixOfTurn

while the properly generated file can be read as:

>>> import uproot
>>> f = uproot.open("good_file.root")
>>> t = f["TMatrixTSymAnalysis"]
>>> t.show(name_width=40, typename_width=40)
name                                     | typename                                 | interpretation                
-----------------------------------------+------------------------------------------+-------------------------------
TMatrixTSymAnalysis                      | TMatrixTSymAnalysis                      | AsGroup(<TBranchElement 'TM...
TMatrixTSymAnalysis/TObject              | (group of fUniqueID:uint32_t, fBits:u... | AsGroup(<TBranchElement 'TO...
TMatrixTSymAnalysis/TObject/fUniqueID    | uint32_t                                 | AsDtype('>u4')
TMatrixTSymAnalysis/TObject/fBits        | uint32_t                                 | AsDtype('>u4')
TMatrixTSymAnalysis/covMatrixOfTurn      | std::vector<TMatrixTSym<double>>         | AsObjects(AsVector(True, Mo...

>>> t["covMatrixOfTurn"].array()
<Array [[{fNrows: 6, fNcols: 6, ...}], ...] type='8 * var * struct[{fNrows:...'>

issue_file.root.txt
good_file.root.txt

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.44%. Comparing base (7301d81) to head (6ff2ebe).

Files with missing lines Patch % Lines
src/uproot/models/TMatrixT.py 75.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (75.00%) is below the target coverage (98.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
Files with missing lines Coverage Δ
src/uproot/models/TMatrixT.py 86.11% <75.00%> (-1.39%) ⬇️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant