scikit-hep / uproot3-methods

Pythonic behaviors for non-I/O related ROOT classes.
BSD 3-Clause "New" or "Revised" License
21 stars 28 forks source link

fix: Set from_numpy fSumw2 equal to entries #98

Closed matthewfeickert closed 3 years ago

matthewfeickert commented 3 years ago

Resolves #97 given @henryiii's proposed solution.

The call hist.Sumw2(kTRUE) [in ROOT] sets the variances equal to the entries. Then the error is the square root of the entries. Uproot is setting the variance equal to the square of the entries, making the error equal to the entries. I think it's a simple bug due to the fact "sumw2" has a square in it, so it looks like it should be set with a square.

matthewfeickert commented 3 years ago

Oh thanks @jpivarski! You were super speedy, but I also did a test and with this change all the test on uproot3 still pass:

$ pip list
Package         Version Location
--------------- ------- -----------------------------------------------------
attrs           20.3.0
awkward0        0.15.5
cachetools      4.2.1
iniconfig       1.1.1
lz4             3.1.3
mock            4.0.3
numpy           1.20.1
packaging       20.9
pip             21.0.1
pluggy          0.13.1
py              1.10.0
pyparsing       2.4.7
pytest          6.2.2
setuptools      54.1.2
toml            0.10.2
uproot3         3.14.4  /home/feickert/Code/GitHub/Scikit-HEP/uproot3
uproot3-methods 0.10.0  /home/feickert/Code/GitHub/Scikit-HEP/uproot3-methods
wheel           0.36.2
xxhash          2.0.0
$ python -m pytest -sx tests/
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.7, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/feickert/Code/GitHub/Scikit-HEP/uproot3
collected 224 items / 2 skipped / 222 selected                                                                                                                                                            

tests/test_cache.py ....
tests/test_issues.py ......................ss.......s.......s....
tests/test_jagged.py sss
tests/test_rntuple.py .
tests/test_stlvector.py ........
tests/test_tree.py ................................sssss.
tests/test_versions.py ..............
tests/test_write.py ................................................................................................................

============================================================================================ warnings summary =============================================================================================
tests/test_issues.py::Test::test_issue76
tests/test_issues.py::Test::test_issue243
tests/test_issues.py::Test::test_issue243_new
tests/test_issues.py::Test::test_issue371
tests/test_issues.py::Test::test_issue367
tests/test_issues.py::Test::test_issue399
tests/test_stlvector.py::Test::test_vector_of_vector_of_numbers
tests/test_stlvector.py::Test::test_strings3
tests/test_stlvector.py::Test::test_unsplit
  /home/feickert/.pyenv/versions/uproot3-dev/lib/python3.8/site-packages/awkward0/array/base.py:398: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
    return cls.numpy.array(value, copy=False)

tests/test_write.py::test_tree_twodim
tests/test_write.py::test_tree_threedim
  /home/feickert/bin/root/lib/ROOT/pythonization/_rdataframe.py:82: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    tmp = numpy.empty(len(cpp_reference), dtype=numpy.object)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================================== 212 passed, 14 skipped, 11 warnings in 23.38s ==============================================================================