@@ -514,27 +514,33 @@ def check_truncate_impute(filename):
514514 assert_true (fields_1d )
515515 assert_true (fields_md )
516516
517- arr1 = rnp .root2array (filename , branches = [(f , 0 ) for f in fields_1d ])
518- assert_true (len (arr1 ))
519- assert_equal (set (arr1 .dtype .names ), set (fields_1d ))
520- # Giving length of 1 will result in the same output
521- arr2 = rnp .root2array (filename , branches = [(f , 0 , 1 ) for f in fields_1d ])
522- assert_array_equal (arr1 , arr2 )
523- # fill_value of 1 instead of 0 should change output array
524- arr2 = rnp .root2array (filename , branches = [(f , 1 , 1 ) for f in fields_1d ])
525- assert_raises (AssertionError , assert_array_equal , arr1 , arr2 )
526- # check dtype shape
527- arr3 = rnp .root2array (filename , branches = [(f , 0 , 3 ) for f in fields_1d ])
528- for field in fields_1d :
529- assert_equal (arr3 .dtype [field ].shape , (3 ,))
530-
531- # length must be at least 1
532- assert_raises (ValueError , rnp .root2array , filename , branches = [(fields_1d [0 ], 0 , 0 )])
533- # tuple is not of length 2 or 3
534- assert_raises (ValueError , rnp .root2array , filename , branches = [(fields_1d [0 ], 1 , 1 , 1 )])
535- assert_raises (ValueError , rnp .root2array , filename , branches = (fields_1d [0 ], 1 , 1 , 1 ))
536- # can only truncate 1d arrays
537- assert_raises (TypeError , rnp .root2array , filename , branches = (fields_md [0 ], 0 ))
517+ rfile = ROOT .TFile .Open (filename )
518+ tree = rfile .Get (rnp .list_trees (filename )[0 ])
519+
520+ # test both root2array and tree2array
521+ for func , arg in [(rnp .root2array , filename ), (rnp .tree2array , tree )]:
522+
523+ arr1 = func (arg , branches = [(f , 0 ) for f in fields_1d ])
524+ assert_true (len (arr1 ))
525+ assert_equal (set (arr1 .dtype .names ), set (fields_1d ))
526+ # Giving length of 1 will result in the same output
527+ arr2 = func (arg , branches = [(f , 0 , 1 ) for f in fields_1d ])
528+ assert_array_equal (arr1 , arr2 )
529+ # fill_value of 1 instead of 0 should change output array
530+ arr2 = func (arg , branches = [(f , 1 , 1 ) for f in fields_1d ])
531+ assert_raises (AssertionError , assert_array_equal , arr1 , arr2 )
532+ # check dtype shape
533+ arr3 = func (arg , branches = [(f , 0 , 3 ) for f in fields_1d ])
534+ for field in fields_1d :
535+ assert_equal (arr3 .dtype [field ].shape , (3 ,))
536+
537+ # length must be at least 1
538+ assert_raises (ValueError , func , arg , branches = [(fields_1d [0 ], 0 , 0 )])
539+ # tuple is not of length 2 or 3
540+ assert_raises (ValueError , func , arg , branches = [(fields_1d [0 ], 1 , 1 , 1 )])
541+ assert_raises (ValueError , func , arg , branches = (fields_1d [0 ], 1 , 1 , 1 ))
542+ # can only truncate 1d arrays
543+ assert_raises (TypeError , func , arg , branches = (fields_md [0 ], 0 ))
538544
539545
540546def test_truncate_impute ():
0 commit comments