From 6de71edecb1dc3ea13a4e9c5b269fa317ee5dfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB=20Bilodeau?= <70441641+zbilodea@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:33:53 +0100 Subject: [PATCH] chore: change name to hepconvert (#53) * Changed name in code * formatting * update new function * more name changes and adjustments to docs * Changed readthedocs setup * fixing tests --- README.md | 44 +- docs/source/conf.py | 6 +- .../source/hepconvert.copy_root.copy_root.rst | 6 + docs/source/hepconvert.copy_root.toctree | 6 + ...onvert.histogram_adding.add_histograms.rst | 6 + .../hepconvert.histogram_adding.toctree | 6 + docs/source/hepconvert.merge.merge_root.rst | 6 + docs/source/hepconvert.merge.toctree | 6 + ...onvert.parquet_to_root.parquet_to_root.rst | 6 + .../source/hepconvert.parquet_to_root.toctree | 6 + ...onvert.root_to_parquet.root_to_parquet.rst | 6 + .../source/hepconvert.root_to_parquet.toctree | 6 + docs/source/hepconvert.toctree | 6 + docs/source/index.rst | 18 +- docs/source/main.toctree | 10 +- docs/source/odapt.copy_root.copy_root.rst | 6 - docs/source/odapt.copy_root.toctree | 6 - docs/source/odapt.histogram_adding.hadd.rst | 6 - docs/source/odapt.histogram_adding.toctree | 6 - docs/source/odapt.merge.hadd_and_merge.rst | 6 - docs/source/odapt.merge.toctree | 6 - .../odapt.parquet_to_root.parquet_to_root.rst | 6 - docs/source/odapt.parquet_to_root.toctree | 6 - .../odapt.root_to_parquet.root_to_parquet.rst | 6 - docs/source/odapt.root_to_parquet.toctree | 6 - docs/source/odapt.toctree | 5 - docs/source/prepare_docstrings.py | 64 +- noxfile.py | 4 +- pyproject.toml | 18 +- src/hepconvert/__init__.py | 22 + src/{odapt => hepconvert}/__main__.py | 22 +- src/{odapt => hepconvert}/_version.pyi | 0 src/{odapt => hepconvert}/copy_root.py | 26 +- src/{odapt => hepconvert}/histogram_adding.py | 40 +- src/{odapt => hepconvert}/merge.py | 40 +- src/{odapt => hepconvert}/parquet_to_root.py | 4 +- src/{odapt => hepconvert}/py.typed | 0 src/{odapt => hepconvert}/root_to_parquet.py | 4 +- src/hepconvert/write_root.py | 0 src/odapt/__init__.py | 22 - tests/test_copy_root.py | 32 +- tests/test_hadd.py | 585 ------------------ tests/test_package.py | 4 +- tests/test_parquet_to_root.py | 2 +- tests/test_root_to_parquet.py | 16 +- tests/test_ttree_merge.py | 130 ---- 46 files changed, 266 insertions(+), 978 deletions(-) create mode 100644 docs/source/hepconvert.copy_root.copy_root.rst create mode 100644 docs/source/hepconvert.copy_root.toctree create mode 100644 docs/source/hepconvert.histogram_adding.add_histograms.rst create mode 100644 docs/source/hepconvert.histogram_adding.toctree create mode 100644 docs/source/hepconvert.merge.merge_root.rst create mode 100644 docs/source/hepconvert.merge.toctree create mode 100644 docs/source/hepconvert.parquet_to_root.parquet_to_root.rst create mode 100644 docs/source/hepconvert.parquet_to_root.toctree create mode 100644 docs/source/hepconvert.root_to_parquet.root_to_parquet.rst create mode 100644 docs/source/hepconvert.root_to_parquet.toctree create mode 100644 docs/source/hepconvert.toctree delete mode 100644 docs/source/odapt.copy_root.copy_root.rst delete mode 100644 docs/source/odapt.copy_root.toctree delete mode 100644 docs/source/odapt.histogram_adding.hadd.rst delete mode 100644 docs/source/odapt.histogram_adding.toctree delete mode 100644 docs/source/odapt.merge.hadd_and_merge.rst delete mode 100644 docs/source/odapt.merge.toctree delete mode 100644 docs/source/odapt.parquet_to_root.parquet_to_root.rst delete mode 100644 docs/source/odapt.parquet_to_root.toctree delete mode 100644 docs/source/odapt.root_to_parquet.root_to_parquet.rst delete mode 100644 docs/source/odapt.root_to_parquet.toctree delete mode 100644 docs/source/odapt.toctree create mode 100644 src/hepconvert/__init__.py rename src/{odapt => hepconvert}/__main__.py (96%) rename src/{odapt => hepconvert}/_version.pyi (100%) rename src/{odapt => hepconvert}/copy_root.py (92%) rename src/{odapt => hepconvert}/histogram_adding.py (96%) rename src/{odapt => hepconvert}/merge.py (89%) rename src/{odapt => hepconvert}/parquet_to_root.py (96%) rename src/{odapt => hepconvert}/py.typed (100%) rename src/{odapt => hepconvert}/root_to_parquet.py (98%) create mode 100644 src/hepconvert/write_root.py delete mode 100644 src/odapt/__init__.py delete mode 100644 tests/test_hadd.py delete mode 100644 tests/test_ttree_merge.py diff --git a/README.md b/README.md index 72f0946..457930b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# odapt +# hepconvert [![Actions Status][actions-badge]][actions-link] [![Documentation Status][rtd-badge]][rtd-link] @@ -12,55 +12,55 @@ -[actions-badge]: https://github.com/zbilodea/odapt/workflows/CI/badge.svg -[actions-link]: https://github.com/zbilodea/odapt/actions -[conda-badge]: https://img.shields.io/conda/vn/conda-forge/odapt -[conda-link]: https://github.com/conda-forge/odapt-feedstock +[actions-badge]: https://github.com/zbilodea/hepconvert/workflows/CI/badge.svg +[actions-link]: https://github.com/zbilodea/hepconvert/actions +[conda-badge]: https://img.shields.io/conda/vn/conda-forge/hepconvert +[conda-link]: https://github.com/conda-forge/hepconvert-feedstock [github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github -[github-discussions-link]: https://github.com/zbilodea/odapt/discussions -[pypi-link]: https://pypi.org/project/odapt/ -[pypi-platforms]: https://img.shields.io/pypi/pyversions/odapt -[pypi-version]: https://img.shields.io/pypi/v/odapt -[rtd-badge]: https://readthedocs.org/projects/odapt/badge/?version=latest -[rtd-link]: https://odapt.readthedocs.io/en/latest/ +[github-discussions-link]: https://github.com/zbilodea/hepconvert/discussions +[pypi-link]: https://pypi.org/project/hepconvert/ +[pypi-platforms]: https://img.shields.io/pypi/pyversions/hepconvert +[pypi-version]: https://img.shields.io/pypi/v/hepconvert +[rtd-badge]: https://readthedocs.org/projects/hepconvert/badge/?version=latest +[rtd-link]: https://hepconvert.readthedocs.io/en/latest/ -The odapt library is a bridge between columnar file formats, currently **ROOT, and Parquet** and soon eventually include **Feather, and HDF5.** It aims to simplify file conversions in Python, replacing what is usually a multi-step process with one line of code, with builtin features for managing large datasets and choosing compression levels. +The hepconvert library is a bridge between columnar file formats, currently **ROOT, and Parquet** and soon eventually include **Feather, and HDF5.** It aims to simplify file conversions in Python, replacing what is usually a multi-step process with one line of code, with builtin features for managing large datasets and choosing compression levels. # Installation -odapt can be installed from [PyPI](https://pypi.org/project/odapt) using pip: +hepconvert can be installed from [PyPI](https://pypi.org/project/hepconvert) using pip: ```bash -pip install odapt +pip install hepconvert ``` # Getting started ```python -import odapt as od +import hepconvert # To merge two or more root files with TTrees, # and add together any histograms: -od.merge_root("destination.root", +hepconvert.merge_root("destination.root", ["ttree_file1.root", "ttree_file2.root"]) -# To add merge files with only histograms: -od.add_histograms("destination.root", +# To add root files with only histograms: +hepconvert.add_histograms("destination.root", ["hist_file1.root", "hist_file2.root"]) ``` -To run ``hadd_and_merge`` from the command line: +To run ``merge_root`` from the command line: ```bash -odapt hadd-and-merge [options] [OUT_FILE] [IN_FILES] +hepconvert merge-root [options] [OUT_FILE] [IN_FILES] ``` -To run ``hadd``: +To run ``add_histograms``: ```bash -odapt add [options] [OUT_FILE] [IN_FILES] +hepconvert add [options] [OUT_FILE] [IN_FILES] ``` Find details on each function's CLI options on the readthedocs. diff --git a/docs/source/conf.py b/docs/source/conf.py index d54d90a..688e5ef 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -10,10 +10,10 @@ import os import sys -sys.path.insert(0, os.path.abspath("../../odapt/")) +sys.path.insert(0, os.path.abspath("../../hepconvert/")) -project = "odapt" +project = "hepconvert" copyright = "2023, Zoë Bilodeau" author = "Zoë Bilodeau" release = "1.1.1" @@ -35,3 +35,5 @@ # Additional stuff master_doc = "index" + +# exec(open("prepare_docstrings.py").read(), dict(globals())) diff --git a/docs/source/hepconvert.copy_root.copy_root.rst b/docs/source/hepconvert.copy_root.copy_root.rst new file mode 100644 index 0000000..f5e6d40 --- /dev/null +++ b/docs/source/hepconvert.copy_root.copy_root.rst @@ -0,0 +1,6 @@ +hepconvert.copy_root +==================== + +Defined in `hepconvert.copy_root `__ on `line 13 `__. + +.. autofunction:: hepconvert.copy_root.copy_root diff --git a/docs/source/hepconvert.copy_root.toctree b/docs/source/hepconvert.copy_root.toctree new file mode 100644 index 0000000..268bc9a --- /dev/null +++ b/docs/source/hepconvert.copy_root.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: copy_root + :hidden: + + hepconvert.copy_root (module) + hepconvert.copy_root.copy_root diff --git a/docs/source/hepconvert.histogram_adding.add_histograms.rst b/docs/source/hepconvert.histogram_adding.add_histograms.rst new file mode 100644 index 0000000..38e33a9 --- /dev/null +++ b/docs/source/hepconvert.histogram_adding.add_histograms.rst @@ -0,0 +1,6 @@ +hepconvert.add_histograms +========================= + +Defined in `hepconvert.histogram_adding `__ on `line 374 `__. + +.. autofunction:: hepconvert.histogram_adding.add_histograms diff --git a/docs/source/hepconvert.histogram_adding.toctree b/docs/source/hepconvert.histogram_adding.toctree new file mode 100644 index 0000000..02bc725 --- /dev/null +++ b/docs/source/hepconvert.histogram_adding.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: histogram_adding + :hidden: + + hepconvert.histogram_adding (module) + hepconvert.histogram_adding.add_histograms diff --git a/docs/source/hepconvert.merge.merge_root.rst b/docs/source/hepconvert.merge.merge_root.rst new file mode 100644 index 0000000..314985e --- /dev/null +++ b/docs/source/hepconvert.merge.merge_root.rst @@ -0,0 +1,6 @@ +hepconvert.merge_root +===================== + +Defined in `hepconvert.merge `__ on `line 11 `__. + +.. autofunction:: hepconvert.merge.merge_root diff --git a/docs/source/hepconvert.merge.toctree b/docs/source/hepconvert.merge.toctree new file mode 100644 index 0000000..6406e9a --- /dev/null +++ b/docs/source/hepconvert.merge.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: merge + :hidden: + + hepconvert.merge (module) + hepconvert.merge.merge_root diff --git a/docs/source/hepconvert.parquet_to_root.parquet_to_root.rst b/docs/source/hepconvert.parquet_to_root.parquet_to_root.rst new file mode 100644 index 0000000..58a1e31 --- /dev/null +++ b/docs/source/hepconvert.parquet_to_root.parquet_to_root.rst @@ -0,0 +1,6 @@ +hepconvert.parquet_to_root +========================== + +Defined in `hepconvert.parquet_to_root `__ on `line 9 `__. + +.. autofunction:: hepconvert.parquet_to_root.parquet_to_root diff --git a/docs/source/hepconvert.parquet_to_root.toctree b/docs/source/hepconvert.parquet_to_root.toctree new file mode 100644 index 0000000..e26a68d --- /dev/null +++ b/docs/source/hepconvert.parquet_to_root.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: parquet_to_root + :hidden: + + hepconvert.parquet_to_root (module) + hepconvert.parquet_to_root.parquet_to_root diff --git a/docs/source/hepconvert.root_to_parquet.root_to_parquet.rst b/docs/source/hepconvert.root_to_parquet.root_to_parquet.rst new file mode 100644 index 0000000..24d7b04 --- /dev/null +++ b/docs/source/hepconvert.root_to_parquet.root_to_parquet.rst @@ -0,0 +1,6 @@ +hepconvert.root_to_parquet +========================== + +Defined in `hepconvert.root_to_parquet `__ on `line 9 `__. + +.. autofunction:: hepconvert.root_to_parquet.root_to_parquet diff --git a/docs/source/hepconvert.root_to_parquet.toctree b/docs/source/hepconvert.root_to_parquet.toctree new file mode 100644 index 0000000..ea852d6 --- /dev/null +++ b/docs/source/hepconvert.root_to_parquet.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: root_to_parquet + :hidden: + + hepconvert.root_to_parquet (module) + hepconvert.root_to_parquet.root_to_parquet diff --git a/docs/source/hepconvert.toctree b/docs/source/hepconvert.toctree new file mode 100644 index 0000000..f04ab24 --- /dev/null +++ b/docs/source/hepconvert.toctree @@ -0,0 +1,6 @@ +.. toctree:: + :caption: Detailed Reference + :hidden: + + hepconvert (module) + hepconvert.merge.merge_root diff --git a/docs/source/index.rst b/docs/source/index.rst index 21a8081..41b4c42 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,4 +1,4 @@ -.. odapt documentation master file, created by +.. hepconvert documentation master file, created by sphinx-quickstart on Tue Dec 5 14:19:03 2023. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. @@ -10,28 +10,28 @@ :hidden: -Welcome to odapt's documentation! -================================= +Welcome to hepconvert's documentation! +====================================== -``odapt`` is an easy-to-use converter tool for columnar file formats ROOT, Parquet, Feather, and HDF5. +``hepconvert`` is an easy-to-use converter tool for columnar file formats ROOT, Parquet, Feather, and HDF5. This package aims to allow users to higher control of file conversions (memory management, compression settings, etc.) all from one function call. We are adding new features at user request, so please share your ideas on our -`github page `__! +`github page `__! How to install ============== -odapt can be installed `from PyPI `__ using pip. +hepconvert can be installed `from PyPI `__ using pip. .. code-block:: bash - pip install odapt + pip install hepconvert -odapt is not yet available using conda. +hepconvert is not yet available using conda. Motivation ********** Many users are all writing similar blocks of code each time they need to convert columnar files. It takes time to learn how to use different I/O packages, -write code, and work through bugs that may come up in this sometimes finicky process. ``odapt`` allows users to find and call just one function. +write code, and work through bugs that may come up in this sometimes finicky process. ``hepconvert`` allows users to find and call just one function. Limitations: ************ diff --git a/docs/source/main.toctree b/docs/source/main.toctree index 42776b4..973542b 100644 --- a/docs/source/main.toctree +++ b/docs/source/main.toctree @@ -2,8 +2,8 @@ :caption: Main Interface :hidden: - odapt.parquet_to_root.parquet_to_root - odapt.root_to_parquet.root_to_parquet - odapt.copy_root.copy_root - odapt.merge.hadd_and_merge - odapt.histogram_adding.hadd + hepconvert.parquet_to_root.parquet_to_root + hepconvert.root_to_parquet.root_to_parquet + hepconvert.copy_root.copy_root + hepconvert.merge.merge_root + hepconvert.histogram_adding.add_histograms diff --git a/docs/source/odapt.copy_root.copy_root.rst b/docs/source/odapt.copy_root.copy_root.rst deleted file mode 100644 index 4c190ae..0000000 --- a/docs/source/odapt.copy_root.copy_root.rst +++ /dev/null @@ -1,6 +0,0 @@ -odapt.copy_root -=============== - -Defined in `odapt.copy_root `__ on `line 13 `__. - -.. autofunction:: odapt.copy_root.copy_root diff --git a/docs/source/odapt.copy_root.toctree b/docs/source/odapt.copy_root.toctree deleted file mode 100644 index 1091294..0000000 --- a/docs/source/odapt.copy_root.toctree +++ /dev/null @@ -1,6 +0,0 @@ -.. toctree:: - :caption: copy_root - :hidden: - - odapt.copy_root (module) - odapt.copy_root.copy_root diff --git a/docs/source/odapt.histogram_adding.hadd.rst b/docs/source/odapt.histogram_adding.hadd.rst deleted file mode 100644 index cd9255e..0000000 --- a/docs/source/odapt.histogram_adding.hadd.rst +++ /dev/null @@ -1,6 +0,0 @@ -odapt.hadd -========== - -Defined in `odapt.histogram_adding `__ on `line 374 `__. - -.. autofunction:: odapt.histogram_adding.hadd diff --git a/docs/source/odapt.histogram_adding.toctree b/docs/source/odapt.histogram_adding.toctree deleted file mode 100644 index 6db281b..0000000 --- a/docs/source/odapt.histogram_adding.toctree +++ /dev/null @@ -1,6 +0,0 @@ -.. toctree:: - :caption: histogram_adding - :hidden: - - odapt.histogram_adding (module) - odapt.histogram_adding.hadd diff --git a/docs/source/odapt.merge.hadd_and_merge.rst b/docs/source/odapt.merge.hadd_and_merge.rst deleted file mode 100644 index 8b45117..0000000 --- a/docs/source/odapt.merge.hadd_and_merge.rst +++ /dev/null @@ -1,6 +0,0 @@ -odapt.hadd_and_merge -==================== - -Defined in `odapt.merge `__ on `line 11 `__. - -.. autofunction:: odapt.merge.hadd_and_merge diff --git a/docs/source/odapt.merge.toctree b/docs/source/odapt.merge.toctree deleted file mode 100644 index c24153e..0000000 --- a/docs/source/odapt.merge.toctree +++ /dev/null @@ -1,6 +0,0 @@ -.. toctree:: - :caption: merge - :hidden: - - odapt.merge (module) - odapt.merge.hadd_and_merge diff --git a/docs/source/odapt.parquet_to_root.parquet_to_root.rst b/docs/source/odapt.parquet_to_root.parquet_to_root.rst deleted file mode 100644 index cdf8083..0000000 --- a/docs/source/odapt.parquet_to_root.parquet_to_root.rst +++ /dev/null @@ -1,6 +0,0 @@ -odapt.parquet_to_root -===================== - -Defined in `odapt.parquet_to_root `__ on `line 9 `__. - -.. autofunction:: odapt.parquet_to_root.parquet_to_root diff --git a/docs/source/odapt.parquet_to_root.toctree b/docs/source/odapt.parquet_to_root.toctree deleted file mode 100644 index b825f9e..0000000 --- a/docs/source/odapt.parquet_to_root.toctree +++ /dev/null @@ -1,6 +0,0 @@ -.. toctree:: - :caption: parquet_to_root - :hidden: - - odapt.parquet_to_root (module) - odapt.parquet_to_root.parquet_to_root diff --git a/docs/source/odapt.root_to_parquet.root_to_parquet.rst b/docs/source/odapt.root_to_parquet.root_to_parquet.rst deleted file mode 100644 index b8c6499..0000000 --- a/docs/source/odapt.root_to_parquet.root_to_parquet.rst +++ /dev/null @@ -1,6 +0,0 @@ -odapt.root_to_parquet -===================== - -Defined in `odapt.root_to_parquet `__ on `line 9 `__. - -.. autofunction:: odapt.root_to_parquet.root_to_parquet diff --git a/docs/source/odapt.root_to_parquet.toctree b/docs/source/odapt.root_to_parquet.toctree deleted file mode 100644 index 4be899d..0000000 --- a/docs/source/odapt.root_to_parquet.toctree +++ /dev/null @@ -1,6 +0,0 @@ -.. toctree:: - :caption: root_to_parquet - :hidden: - - odapt.root_to_parquet (module) - odapt.root_to_parquet.root_to_parquet diff --git a/docs/source/odapt.toctree b/docs/source/odapt.toctree deleted file mode 100644 index 6340c9c..0000000 --- a/docs/source/odapt.toctree +++ /dev/null @@ -1,5 +0,0 @@ -.. toctree:: - :caption: Detailed Reference - :hidden: - - odapt (module) diff --git a/docs/source/prepare_docstrings.py b/docs/source/prepare_docstrings.py index cf86d5c..c6bc1c9 100644 --- a/docs/source/prepare_docstrings.py +++ b/docs/source/prepare_docstrings.py @@ -7,23 +7,23 @@ import subprocess import sys -import odapt +import hepconvert order = [ - "odapt", - "odapt.histogram_adding", - "odapt.merge", - "odapt.parquet_to_root", - "odapt.root_to_parquet", - "odapt.copy_root", + "hepconvert", + "hepconvert.histogram_adding", + "hepconvert.merge", + "hepconvert.parquet_to_root", + "hepconvert.root_to_parquet", + "hepconvert.copy_root", ] common = [ - "odapt.parquet_to_root.parquet_to_root", - "odapt.root_to_parquet.root_to_parquet", - "odapt.copy_root.copy_root", - "odapt.merge.hadd_and_merge", - "odapt.histogram_adding.hadd", + "hepconvert.parquet_to_root.parquet_to_root", + "hepconvert.root_to_parquet.root_to_parquet", + "hepconvert.copy_root.copy_root", + "hepconvert.merge.merge_root", + "hepconvert.histogram_adding.add_histograms", ] latest_commit = ( @@ -39,7 +39,7 @@ {}""".format("".join(f" {x}\n" for x in common)) ) -toctree = open("odapt.toctree", "w") +toctree = open("hepconvert.toctree", "w") toctree.write( """.. toctree:: :caption: Detailed Reference @@ -76,7 +76,7 @@ def handle_module(modulename, module): else: toctree2.write(" " + modulename + " (module) <" + modulename + ">\n") - if modulename != "odapt" and all( + if modulename != "hepconvert" and all( not x.startswith("test") and not x.startswith("_") for x in modulename.split(".") ): @@ -112,15 +112,15 @@ def line_order(obj): methods = {} mro = list(cls.__mro__) - if hasattr(odapt, cls.__name__): - title = "odapt." + cls.__name__ + if hasattr(hepconvert, cls.__name__): + title = "hepconvert." + cls.__name__ upfront = True else: title = classname upfront = False for index, basecls in enumerate(mro): - if basecls.__module__.startswith("odapt."): + if basecls.__module__.startswith("hepconvert."): def good(obj): if inspect.ismethod(obj) or inspect.isfunction(obj): @@ -132,7 +132,7 @@ def good(obj): return False else: module, name = "", "" - if module.startswith("odapt."): + if module.startswith("hepconvert."): if index + 1 >= len(mro) or obj is not getattr( mro[index + 1], name, None ): @@ -168,18 +168,18 @@ def good(obj): def prettymro(c): fullname = c.__module__ + "." + c.__name__ - if c.__module__.startswith("odapt."): + if c.__module__.startswith("hepconvert."): return "#. :doc:`" + fullname + "`" else: return "#. ``" + fullname + "``" fullfilename = importlib.import_module(cls.__module__).__file__ - shortfilename = fullfilename[fullfilename.rindex("odapt/") :] - link = "`{} `__".format( + shortfilename = fullfilename[fullfilename.rindex("hepconvert/") :] + link = "`{} `__".format( cls.__module__, latest_commit, shortfilename ) try: - linelink = "`line {0} `__".format( + linelink = "`line {0} `__".format( inspect.getsourcelines(cls)[1], latest_commit, shortfilename ) except OSError: @@ -234,22 +234,20 @@ def prettymro(c): def handle_function(functionname, cls): - if hasattr(odapt, cls.__name__): - title = "odapt." + cls.__name__ + if hasattr(hepconvert, cls.__name__): + title = "hepconvert." + cls.__name__ upfront = True else: title = functionname upfront = False fullfilename = importlib.import_module(cls.__module__).__file__ - shortfilename = fullfilename[fullfilename.rindex("odapt/") :] - link = "`{} `__".format( + shortfilename = fullfilename[fullfilename.rindex("hepconvert/") :] + link = "`{} `__".format( cls.__module__, latest_commit, shortfilename ) - linelink = ( - "`line {0} `__".format( - inspect.getsourcelines(cls)[1], latest_commit, shortfilename - ) + linelink = "`line {0} `__".format( + inspect.getsourcelines(cls)[1], latest_commit, shortfilename ) content = """{} @@ -271,18 +269,18 @@ def handle_function(functionname, cls): for modulename in order: module = importlib.import_module(modulename) - if modulename != "odapt": + if modulename != "hepconvert": toctree2 = open(modulename + ".toctree", "w") toctree2.write( """.. toctree:: :caption: {} :hidden: -""".format(modulename.replace("odapt.", "")) +""".format(modulename.replace("hepconvert.", "")) ) handle_module(modulename, module) - if module.__file__.endswith("__init__.py") and modulename != "odapt": + if module.__file__.endswith("__init__.py") and modulename != "hepconvert": for submodulename in sorted( modulename + "." + name for loader, name, is_pkg in pkgutil.walk_packages(module.__path__) diff --git a/noxfile.py b/noxfile.py index 5632317..cc2d5c6 100644 --- a/noxfile.py +++ b/noxfile.py @@ -30,7 +30,7 @@ def pylint(session: nox.Session) -> None: # This needs to be installed into the package environment, and is slower # than a pre-commit check session.install(".", "pylint") - session.run("pylint", "odapt", *session.posargs) + session.run("pylint", "hepconvert", *session.posargs) @nox.session @@ -99,7 +99,7 @@ def build_api_docs(session: nox.Session) -> None: "--module-first", "--no-toc", "--force", - "../src/odapt", + "../src/hepconvert", ) diff --git a/pyproject.toml b/pyproject.toml index dbae84b..3dea3ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] -name = "odapt" +name = "hepconvert" authors = [ { name = "Zoë Bilodeau", email = "zobilodeau@gmail.com" }, ] @@ -53,17 +53,17 @@ docs = [ ] [project.urls] -Homepage = "https://github.com/zbilodea/odapt" -"Bug Tracker" = "https://github.com/zbilodea/odapt/issues" -Discussions = "https://github.com/zbilodea/odapt/discussions" -Changelog = "https://github.com/zbilodea/odapt/releases" +Homepage = "https://github.com/zbilodea/hepconvert" +"Bug Tracker" = "https://github.com/zbilodea/hepconvert/issues" +Discussions = "https://github.com/zbilodea/hepconvert/discussions" +Changelog = "https://github.com/zbilodea/hepconvert/releases" [tool.hatch.version] source = "vcs" [tool.hatch.build.hooks.vcs] -version-file = "src/odapt/_version.py" +version-file = "src/hepconvert/_version.py" [tool.pytest.ini_options] minversion = "6.0" @@ -79,7 +79,7 @@ testpaths = [ [tool.coverage] -run.source = ["odapt"] +run.source = ["hepconvert"] port.exclude_lines = [ 'pragma: no cover', '\.\.\.', @@ -97,7 +97,7 @@ disallow_untyped_defs = false disallow_incomplete_defs = false [[tool.mypy.overrides]] -module = "odapt.*" +module = "hepconvert.*" disallow_untyped_defs = true disallow_incomplete_defs = true @@ -160,4 +160,4 @@ messages_control.disable = [ ] [project.scripts] -"odapt" = "odapt.__main__:main" +"hepconvert" = "hepconvert.__main__:main" diff --git a/src/hepconvert/__init__.py b/src/hepconvert/__init__.py new file mode 100644 index 0000000..a32ad98 --- /dev/null +++ b/src/hepconvert/__init__.py @@ -0,0 +1,22 @@ +""" +Copyright (c) 2023 Zoë Bilodeau. All rights reserved. + +odapt: File conversion package. +""" +from __future__ import annotations + +from hepconvert._version import __version__ +from hepconvert.copy_root import copy_root +from hepconvert.histogram_adding import add_histograms +from hepconvert.merge import merge_root +from hepconvert.parquet_to_root import parquet_to_root +from hepconvert.root_to_parquet import root_to_parquet + +__all__ = [ + "__version__", + "add_histograms", + "merge_root", + "copy_root", + "parquet_to_root", + "root_to_parquet", +] diff --git a/src/odapt/__main__.py b/src/hepconvert/__main__.py similarity index 96% rename from src/odapt/__main__.py rename to src/hepconvert/__main__.py index 22dd442..d1ae4e0 100644 --- a/src/odapt/__main__.py +++ b/src/hepconvert/__main__.py @@ -62,9 +62,9 @@ def parquet_to_root( """ Convert Parquet file to ROOT file. """ - import odapt.parquet_to_root # pylint: disable=import-outside-toplevel + import hepconvert.parquet_to_root # pylint: disable=import-outside-toplevel - odapt.parquet_to_root( + hepconvert.parquet_to_root( destination, file, name=name, @@ -120,9 +120,9 @@ def copy_root( """ Copy root file. """ - import odapt.copy_root # pylint: disable=import-outside-toplevel + import hepconvert.copy_root # pylint: disable=import-outside-toplevel - odapt.copy_root( + hepconvert.copy_root( destination, file, drop_branches=drop_branches, @@ -189,9 +189,9 @@ def add( """ Hadd files. """ - import odapt.histogram_adding # pylint: disable=import-outside-toplevel + import hepconvert.histogram_adding # pylint: disable=import-outside-toplevel - odapt.hadd( + hepconvert.add_histograms( destination, files, force=force, @@ -249,7 +249,7 @@ def add( default=False, help="Skip corrupt or non-existent files without exiting", ) -def add_and_merge( +def merge_root( destination, files, *, @@ -270,9 +270,9 @@ def add_and_merge( """ Merge TTrees and add histograms. """ - import odapt.merge # pylint: disable=import-outside-toplevel + import hepconvert.merge # pylint: disable=import-outside-toplevel - odapt.hadd_and_merge( + hepconvert.merge_root( destination, files, fieldname_separator=fieldname_separator, @@ -471,9 +471,9 @@ def root_to_parquet( """ Convert ROOT to Parquet. """ - import odapt.root_to_parquet # pylint: disable=import-outside-toplevel + import hepconvert.root_to_parquet # pylint: disable=import-outside-toplevel - odapt.root_to_parquet( + hepconvert.root_to_parquet( in_file=in_file, out_file=out_file, list_to32=list_to32, diff --git a/src/odapt/_version.pyi b/src/hepconvert/_version.pyi similarity index 100% rename from src/odapt/_version.pyi rename to src/hepconvert/_version.pyi diff --git a/src/odapt/copy_root.py b/src/hepconvert/copy_root.py similarity index 92% rename from src/odapt/copy_root.py rename to src/hepconvert/copy_root.py index 9f005f3..c0ffa73 100644 --- a/src/odapt/copy_root.py +++ b/src/hepconvert/copy_root.py @@ -5,7 +5,7 @@ import awkward as ak import uproot -from odapt.histogram_adding import hadd_1d, hadd_2d, hadd_3d +from hepconvert.histogram_adding import _hadd_1d, _hadd_2d, _hadd_3d # ruff: noqa: B023 @@ -75,17 +75,17 @@ def copy_root( --------- Copies contents of one ROOT file to a new file. If the file is in nanoAOD-format, ``copy_root`` can drop branches from a tree while copying. RNTuple can not yet be copied. - >>> odapt.copy_root("copied_file.root", "original_file.root") + >>> hepconvert.copy_root("copied_file.root", "original_file.root") To copy a file and drop branches with names "branch1" and "branch2": - >>> odapt.copy_root("copied_file.root", "original_file.root", drop_branches=["branch1", "branch2"]) + >>> hepconvert.copy_root("copied_file.root", "original_file.root", drop_branches=["branch1", "branch2"]) Command Line Instructions: -------------------------- This function can be run from the command line. Use command - >>> odapt copy-root [options] [OUT_FILE] [IN_FILE] + >>> hepconvert copy-root [options] [OUT_FILE] [IN_FILE] """ if compression in ("ZLIB", "zlib"): @@ -131,14 +131,14 @@ def copy_root( for key in f.keys(cycle=False, recursive=False): if key in hist_keys: if len(f[key].axes) == 1: - h_sum = hadd_1d(destination, f, key, True) + h_sum = _hadd_1d(destination, f, key, True) # if isinstance(h_sum, uproot.models.TH.Model_TH1F_v3): # print(h_sum.member('fXaxis')) out_file[key] = h_sum elif len(f[key].axes) == 2: - out_file[key] = hadd_2d(destination, f, key, True) + out_file[key] = _hadd_2d(destination, f, key, True) else: - out_file[key] = hadd_3d(destination, f, key, True) + out_file[key] = _hadd_3d(destination, f, key, True) trees = f.keys(filter_classname="TTree", cycle=False, recursive=False) @@ -227,23 +227,23 @@ def copy_root( if len(histograms) > 1: for key in histograms: if len(f[key].axes) == 1: - writable_hists[key] = hadd_1d(destination, f, key, True) + writable_hists[key] = _hadd_1d(destination, f, key, True) elif len(f[key].axes) == 2: - writable_hists[key] = hadd_2d(destination, f, key, True) + writable_hists[key] = _hadd_2d(destination, f, key, True) else: - writable_hists[key] = hadd_3d(destination, f, key, True) + writable_hists[key] = _hadd_3d(destination, f, key, True) elif len(histograms) == 1: if len(f[histograms[0]].axes) == 1: - writable_hists = hadd_1d(destination, f, histograms[0], True) + writable_hists = _hadd_1d(destination, f, histograms[0], True) elif len(f[histograms[0]].axes) == 2: - writable_hists = hadd_2d(destination, f, histograms[0], True) + writable_hists = _hadd_2d(destination, f, histograms[0], True) else: - writable_hists = hadd_3d(destination, f, histograms[0], True) + writable_hists = _hadd_3d(destination, f, histograms[0], True) first = True for chunk in uproot.iterate( diff --git a/src/odapt/histogram_adding.py b/src/hepconvert/histogram_adding.py similarity index 96% rename from src/odapt/histogram_adding.py rename to src/hepconvert/histogram_adding.py index 12ae2a5..ecd8ca5 100644 --- a/src/odapt/histogram_adding.py +++ b/src/hepconvert/histogram_adding.py @@ -6,8 +6,8 @@ import uproot -def hadd_1d(destination, file, key, first, *, n_key=None): - """Supporting function for hadd. +def _hadd_1d(destination, file, key, first, *, n_key=None): + """Supporting function for add_histograms. :param destination: Name of the output file or file path. :type destination: path-like @@ -100,8 +100,8 @@ def hadd_1d(destination, file, key, first, *, n_key=None): ) from None -def hadd_2d(destination, file, key, first, *, n_key=None): - """Supporting function for hadd. +def _hadd_2d(destination, file, key, first, *, n_key=None): + """Supporting function for add_histograms. :param destination: Name of the output file or file path. :type destination: path-like @@ -220,8 +220,8 @@ def hadd_2d(destination, file, key, first, *, n_key=None): ) from None -def hadd_3d(destination, file, key, first, *, n_key=None): - """Supporting function for hadd. +def _hadd_3d(destination, file, key, first, *, n_key=None): + """Supporting function for add_histograms. :param destination: Name of the output file or file path. :type destination: path-like @@ -371,7 +371,7 @@ def hadd_3d(destination, file, key, first, *, n_key=None): ) from None -def hadd( +def add_histograms( destination, files, *, @@ -383,7 +383,7 @@ def hadd( union=True, same_names=False, ): - """Adds together histograms from local ROOT files of a collection of ROOT files, and writes them to a new or existing ROOT file. + """Adds together histograms from local ROOT files of a collection of ROOT files, and writes them to a new or existing ROOT file. Similar to ROOT's hadd function. :param destination: Name of the output file or file path. :type destination: path-like @@ -416,13 +416,13 @@ def hadd( Example: -------- - >>> odapt.hadd("destination.root", ["file1_to_hadd.root", "file2_to_hadd.root"]) + >>> hepconvert.add_histograms("destination.root", ["file1_to_add.root", "file2_to_add.root"]) Command Line Instructions: -------------------------- This function can be run from the command line. Use command - >>> odapt add [options] [OUT_FILE] [IN_FILES] + >>> hepconvert add [options] [OUT_FILE] [IN_FILES] """ if compression in ("ZLIB", "zlib"): @@ -466,7 +466,7 @@ def hadd( files = sorted(path.glob("**/*.root")) if len(files) <= 1: - msg = "Cannot hadd one file. Use root_to_root to copy a ROOT file." + msg = "Cannot add one file. Use copy_root to copy a ROOT file." raise ValueError(msg) from None with uproot.open(files[0]) as file: @@ -519,25 +519,25 @@ def hadd( msg = "Union key filter error." raise ValueError(msg) from None if len(file[key].axes) == 1: - h_sum = hadd_1d(destination, file, key, first) + h_sum = _hadd_1d(destination, file, key, first) elif len(file[key].axes) == 2: - h_sum = hadd_2d(destination, file, key, first) + h_sum = _hadd_2d(destination, file, key, first) else: - h_sum = hadd_3d(destination, file, key, first) + h_sum = _hadd_3d(destination, file, key, first) else: n_keys = file.keys(filter_classname="TH[1|2|3][I|S|F|D|C]", cycle=False) for i, _value in enumerate(keys): if len(file[n_keys[i]].axes) == 1: - h_sum = hadd_1d(destination, file, keys[i], first, n_key=n_keys[i]) + h_sum = _hadd_1d(destination, file, keys[i], first, n_key=n_keys[i]) elif len(file[n_keys[i]].axes) == 2: - h_sum = hadd_2d(destination, file, keys[i], first, n_key=n_keys[i]) + h_sum = _hadd_2d(destination, file, keys[i], first, n_key=n_keys[i]) else: - h_sum = hadd_3d(destination, file, keys[i], first, n_key=n_keys[i]) + h_sum = _hadd_3d(destination, file, keys[i], first, n_key=n_keys[i]) if h_sum is not None: file_out[keys[i]] = h_sum @@ -546,7 +546,7 @@ def hadd( file.close() -def tprofile_1d(destination, file, key, first, *, n_key=None): +def _tprofile_1d(destination, file, key, first, *, n_key=None): """ Args: :param destination: Name of the output file or file path. @@ -649,7 +649,7 @@ def tprofile_1d(destination, file, key, first, *, n_key=None): ) from None -def tprofile_2d(destination, file, key, first, *, n_key=None): +def _tprofile_2d(destination, file, key, first, *, n_key=None): """ Args: :param destination: Name of the output file or file path. @@ -779,7 +779,7 @@ def tprofile_2d(destination, file, key, first, *, n_key=None): ) from None -def tprofile_3d(destination, file, key, first, *, n_key=None): +def _tprofile_3d(destination, file, key, first, *, n_key=None): """ Args: :param destination: Name of the output file or file path. diff --git a/src/odapt/merge.py b/src/hepconvert/merge.py similarity index 89% rename from src/odapt/merge.py rename to src/hepconvert/merge.py index 9dbd3ea..7acce89 100644 --- a/src/odapt/merge.py +++ b/src/hepconvert/merge.py @@ -5,10 +5,10 @@ import awkward as ak import uproot -from odapt.histogram_adding import hadd_1d, hadd_2d, hadd_3d +from hepconvert.histogram_adding import _hadd_1d, _hadd_2d, _hadd_3d -def hadd_and_merge( +def merge_root( destination, files, *, @@ -26,7 +26,7 @@ def hadd_and_merge( compression_level=1, skip_bad_files=False, ): - """Merges TTrees together, and adds values in histograms from local ROOT files, and writes them to a new ROOT file. + """Merges TTrees together, and adds values in histograms from local ROOT files, and writes them to a new ROOT file. Similar to ROOT's hadd function. :param destination: Name of the output file or file path. :type destination: path-like @@ -71,13 +71,13 @@ def hadd_and_merge( Example: -------- - >>> odapt.hadd_and_merge("destination.root", ["file1.root", "file2.root"]) + >>> hepconvert.merge_root("destination.root", ["file1.root", "file2.root"]) Command Line Instructions: -------------------------- This function can be run from the command line. Use command - >>> odapt add-and-merge [options] [OUT_FILE] [IN_FILES] + >>> hepconvert merge [options] [OUT_FILE] [IN_FILES] """ @@ -155,12 +155,12 @@ def hadd_and_merge( for key in f.keys(cycle=False, recursive=False): if key in hist_keys: if len(f[key].axes) == 1: - h_sum = hadd_1d(destination, f, key, True) + h_sum = _hadd_1d(destination, f, key, True) out_file[key] = h_sum elif len(f[key].axes) == 2: - out_file[key] = hadd_2d(destination, f, key, True) + out_file[key] = _hadd_2d(destination, f, key, True) else: - out_file[key] = hadd_3d(destination, f, key, True) + out_file[key] = _hadd_3d(destination, f, key, True) trees = f.keys(filter_classname="TTree", cycle=False, recursive=False) @@ -197,23 +197,23 @@ def hadd_and_merge( if len(histograms) > 1: for key in histograms: if len(f[key].axes) == 1: - writable_hists[key] = hadd_1d(destination, f, key, True) + writable_hists[key] = _hadd_1d(destination, f, key, True) elif len(f[key].axes) == 2: - writable_hists[key] = hadd_2d(destination, f, key, True) + writable_hists[key] = _hadd_2d(destination, f, key, True) else: - writable_hists[key] = hadd_3d(destination, f, key, True) + writable_hists[key] = _hadd_3d(destination, f, key, True) elif len(histograms) == 1: if len(f[histograms[0]].axes) == 1: - writable_hists = hadd_1d(destination, f, histograms[0], True) + writable_hists = _hadd_1d(destination, f, histograms[0], True) elif len(f[histograms[0]].axes) == 2: - writable_hists = hadd_2d(destination, f, histograms[0], True) + writable_hists = _hadd_2d(destination, f, histograms[0], True) else: - writable_hists = hadd_3d(destination, f, histograms[0], True) + writable_hists = _hadd_3d(destination, f, histograms[0], True) first = True for chunk in uproot.iterate(tree, step_size=step_size, how=dict): @@ -281,11 +281,11 @@ def hadd_and_merge( for key in f.keys(cycle=False, recursive=False): if key in hist_keys: if len(f[key].axes) == 1: - h_sum = hadd_1d(destination, f, key, False) + h_sum = _hadd_1d(destination, f, key, False) elif len(f[key].axes) == 2: - h_sum = hadd_2d(destination, f, key, False) + h_sum = _hadd_2d(destination, f, key, False) else: - h_sum = hadd_3d(destination, f, key, False) + h_sum = _hadd_3d(destination, f, key, False) out_file[key] = h_sum @@ -295,13 +295,13 @@ def hadd_and_merge( writable_hists = [] for key in histograms: if len(f[key].axes) == 1: - writable_hists[key] = hadd_1d(destination, out_file, key, False) + writable_hists[key] = _hadd_1d(destination, out_file, key, False) elif len(f[key].axes) == 2: - writable_hists[key] = hadd_2d(destination, out_file, key, False) + writable_hists[key] = _hadd_2d(destination, out_file, key, False) else: - writable_hists[key] = hadd_3d(destination, out_file, key, False) + writable_hists[key] = _hadd_3d(destination, out_file, key, False) for chunk in uproot.iterate(tree, step_size=step_size, how=dict): for group in groups: diff --git a/src/odapt/parquet_to_root.py b/src/hepconvert/parquet_to_root.py similarity index 96% rename from src/odapt/parquet_to_root.py rename to src/hepconvert/parquet_to_root.py index 5d2bd2e..3fecf82 100644 --- a/src/odapt/parquet_to_root.py +++ b/src/hepconvert/parquet_to_root.py @@ -55,7 +55,7 @@ def parquet_to_root( Example: -------- - >>> od.parquet_to_root("file.root", "file.parquet", name="tree") + >>> hepconvert.parquet_to_root("file.root", "file.parquet", name="tree") >>> f = uproot.open("file.root") >>> data = f["tree"] @@ -63,7 +63,7 @@ def parquet_to_root( -------------------------- This function can be run from the command line. Use command - >>> odapt parquet-to-root [options] [OUT_FILE] [IN_FILE] + >>> hepconvert parquet-to-root [options] [OUT_FILE] [IN_FILE] """ if compression in ("LZMA", "lzma"): diff --git a/src/odapt/py.typed b/src/hepconvert/py.typed similarity index 100% rename from src/odapt/py.typed rename to src/hepconvert/py.typed diff --git a/src/odapt/root_to_parquet.py b/src/hepconvert/root_to_parquet.py similarity index 98% rename from src/odapt/root_to_parquet.py rename to src/hepconvert/root_to_parquet.py index 5ca39e4..3af22af 100644 --- a/src/odapt/root_to_parquet.py +++ b/src/hepconvert/root_to_parquet.py @@ -173,13 +173,13 @@ def root_to_parquet( --------- Converts a TTree from a ROOT file to a Parquet File. - >>> odapt.root_to_parquet(in_file="file.root", out_file="file.parquet") + >>> hepconvert.root_to_parquet(in_file="file.root", out_file="file.parquet") Command Line Instructions: -------------------------- This function can be run from the command line. Use command - >>> odapt root-to-parquet [options] [OUT_FILE] [IN_FILE] + >>> hepconvert root-to-parquet [options] [OUT_FILE] [IN_FILE] """ path = Path(out_file) diff --git a/src/hepconvert/write_root.py b/src/hepconvert/write_root.py new file mode 100644 index 0000000..e69de29 diff --git a/src/odapt/__init__.py b/src/odapt/__init__.py deleted file mode 100644 index 4cf996e..0000000 --- a/src/odapt/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Copyright (c) 2023 Zoë Bilodeau. All rights reserved. - -odapt: File conversion package. -""" -from __future__ import annotations - -from odapt._version import __version__ -from odapt.copy_root import copy_root -from odapt.histogram_adding import hadd -from odapt.merge import hadd_and_merge -from odapt.parquet_to_root import parquet_to_root -from odapt.root_to_parquet import root_to_parquet - -__all__ = [ - "__version__", - "hadd", - "hadd_and_merge", - "copy_root", - "parquet_to_root", - "root_to_parquet", -] diff --git a/tests/test_copy_root.py b/tests/test_copy_root.py index 2a854de..04180c0 100644 --- a/tests/test_copy_root.py +++ b/tests/test_copy_root.py @@ -6,26 +6,28 @@ import pytest import uproot -import odapt as od +import hepconvert skhep_testdata = pytest.importorskip("skhep_testdata") def test_copy(tmp_path): - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copy.root", skhep_testdata.data_path("uproot-HZZ.root"), counter_name=lambda counted: "N" + counted, ) - od_file = uproot.open(Path(tmp_path) / "copy.root") + hepconvert_file = uproot.open(Path(tmp_path) / "copy.root") file = uproot.open(skhep_testdata.data_path("uproot-HZZ.root")) - for key in od_file["events"].keys(): + for key in hepconvert_file["events"].keys(): assert key in file["events"].keys() - assert ak.all(od_file["events"][key].array() == file["events"][key].array()) + assert ak.all( + hepconvert_file["events"][key].array() == file["events"][key].array() + ) def test_drop_branch(tmp_path): - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "drop_branches.root", skhep_testdata.data_path("uproot-HZZ.root"), drop_branches=["MClepton_py", "Jet_Px"], @@ -46,7 +48,7 @@ def test_drop_branch(tmp_path): def test_add_branch(tmp_path): - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "drop_branches.root", skhep_testdata.data_path("uproot-HZZ.root"), drop_branches=["MClepton_py", "Jet_Px"], @@ -64,7 +66,7 @@ def test_add_branch(tmp_path): file["events"]["Jet_Px"].name: file["events"]["Jet_Px"].arrays(), } jet_px = {file["events"]["Jet_Px"].name: file["events"]["Jet_Px"].arrays()} - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "add_branches.root", Path(tmp_path) / "drop_branches.root", ) @@ -73,15 +75,15 @@ def test_add_branch(tmp_path): def test_hepdata_example(tmp_path): - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copy_hepdata.root", skhep_testdata.data_path("uproot-hepdata-example.root"), counter_name=lambda counted: "N" + counted, ) - od_file = uproot.open(Path(tmp_path) / "copy_hepdata.root") + hepconvert_file = uproot.open(Path(tmp_path) / "copy_hepdata.root") file = uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) - for key in od_file.keys(cycle=False): + for key in hepconvert_file.keys(cycle=False): assert key in file.keys(cycle=False) @@ -103,7 +105,7 @@ def test_drop_tree(tmp_path): "p1": np.array([44, 55, 66, 7, 8]), } with uproot.open(Path(tmp_path) / "two_trees.root") as file: - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copied.root", Path(tmp_path) / "two_trees.root", drop_trees=["tree", "tree1"], @@ -114,7 +116,7 @@ def test_drop_tree(tmp_path): for key in copy[tree].keys(): assert ak.all(copy[tree][key].array() == file[tree][key].array()) - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copied.root", Path(tmp_path) / "two_trees.root", drop_trees="tree3", @@ -129,7 +131,7 @@ def test_drop_tree(tmp_path): ValueError, match="Key 'tree5' does not match any TTree in ROOT file/Users/zobil/Desktop/directory/two_trees.root", ): - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copied.root", Path(tmp_path) / "two_trees.root", drop_trees=["tree5"], @@ -147,7 +149,7 @@ def test_drop_tree_and_branch(tmp_path): } with uproot.open(Path(tmp_path) / "two_trees.root") as file: - od.copy_root( + hepconvert.copy_root( Path(tmp_path) / "copied.root", Path(tmp_path) / "two_trees.root", drop_branches={"tree": "x", "tree1": "y"}, diff --git a/tests/test_hadd.py b/tests/test_hadd.py deleted file mode 100644 index ec82199..0000000 --- a/tests/test_hadd.py +++ /dev/null @@ -1,585 +0,0 @@ -from __future__ import annotations - -from pathlib import Path - -import numpy as np -import pytest -import uproot - -import odapt as od - -ROOT = pytest.importorskip("ROOT") - - -def write_root_file(hist, path): - outHistFile = ROOT.TFile.Open(path, "RECREATE") - outHistFile.cd() - hist.Write() - outHistFile.Close() - - -def generate_1D_gaussian(file_paths): - gauss_1 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_1.FillRandom("gaus") - gauss_1.Sumw2() - gauss_1.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[0], "RECREATE") - outHistFile.cd() - gauss_1.Write() - outHistFile.Close() - gauss_1 = uproot.from_pyroot(gauss_1) - - gauss_2 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_2.FillRandom("gaus") - gauss_2.Sumw2() - gauss_2.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[1], "RECREATE") - outHistFile.cd() - gauss_2.Write() - outHistFile.Close() - gauss_2 = uproot.from_pyroot(gauss_2) - - gauss_3 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_3.FillRandom("gaus") - gauss_3.Sumw2() - gauss_3.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[2], "RECREATE") - outHistFile.cd() - gauss_3.Write() - outHistFile.Close() - gauss_3 = uproot.from_pyroot(gauss_3) - - return gauss_1, gauss_2, gauss_3 - - -def generate_1D_simple(): - h1 = ROOT.TH1F("name", "", 10, 0.0, 10.0) - data1 = [11.5, 12.0, 9.0, 8.1, 6.4, 6.32, 5.3, 3.0, 2.0, 1.0] - for i in range(len(data1)): - h1.Fill(i, data1[i]) - - outHistFile = ROOT.TFile.Open("tests/file1dim1.root", "RECREATE") - outHistFile.cd() - h1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(h1) - - h2 = ROOT.TH1F("name", "", 10, 0.0, 10.0) - data2 = [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0] - - for i in range(len(data2)): - h2.Fill(i, data2[i]) - - outHistFile = ROOT.TFile.Open("tests/file2dim1.root", "RECREATE") - outHistFile.cd() - h2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(h2) - return h1, h2 - - -def test_simple(tmp_path, file_paths): - gauss_1 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_1.FillRandom("gaus") - gauss_1.Sumw2() - gauss_1.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[0], "RECREATE") - outHistFile.cd() - gauss_1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(gauss_1) - - gauss_2 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_2.FillRandom("gaus") - gauss_2.Sumw2() - gauss_2.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[1], "RECREATE") - outHistFile.cd() - gauss_2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(gauss_2) - - gauss_3 = ROOT.TH1I("name", "title", 5, -4, 4) - gauss_3.FillRandom("gaus") - gauss_3.Sumw2() - gauss_3.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[2], "RECREATE") - outHistFile.cd() - gauss_3.Write() - outHistFile.Close() - h3 = uproot.from_pyroot(gauss_3) - - path = Path(tmp_path) - destination = path / "destination.root" - od.root.hadd(destination, file_paths, force=True) - - with uproot.open(destination) as file: - added = uproot.from_pyroot( - gauss_1 + gauss_2 + gauss_3 - ) # test od vs Pyroot histogram adding - assert file["name"].member("fN") == added.member("fN") - assert file["name"].member("fTsumw") == added.member("fTsumw") - assert np.equal(file["name"].values(flow=True), added.values(flow=True)).all - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h2.member( - "fTsumw" - ) + h3.member("fTsumw") - assert np.equal( - file["name"].values(flow=True), - np.array(h1.values(flow=True) + h2.values(flow=True)), - ).all - - -def mult_1D(tmp_path, file_paths): - gauss_1 = ROOT.TH1I("name1", "title", 5, -4, 4) - gauss_1.FillRandom("gaus") - gauss_1.Sumw2() - gauss_1.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[0], "RECREATE") - outHistFile.cd() - gauss_1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(gauss_1) - - gauss_2 = ROOT.TH1I("name2", "title", 5, -4, 4) - gauss_2.FillRandom("gaus") - gauss_2.Sumw2() - gauss_2.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[0], "UPDATE") - outHistFile.cd() - gauss_2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(gauss_2) - - gauss_3 = ROOT.TH1I("name3", "title", 5, -4, 4) - gauss_3.FillRandom("gaus") - gauss_3.Sumw2() - gauss_3.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[1], "RECREATE") - outHistFile.cd() - gauss_3.Write() - outHistFile.Close() - h3 = uproot.from_pyroot(gauss_3) - - gauss_4 = ROOT.TH1I("name4", "title", 5, -4, 4) - gauss_4.FillRandom("gaus") - gauss_4.Sumw2() - gauss_4.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[1], "UPDATE") - outHistFile.cd() - gauss_4.Write() - outHistFile.Close() - h4 = uproot.from_pyroot(gauss_4) - - gauss_5 = ROOT.TH1I("name5", "title", 5, -4, 4) - gauss_5.FillRandom("gaus") - gauss_5.Sumw2() - gauss_5.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[2], "RECREATE") - outHistFile.cd() - gauss_5.Write() - outHistFile.Close() - h5 = uproot.from_pyroot(gauss_5) - - gauss_6 = ROOT.TH1I("name6", "title", 5, -4, 4) - gauss_6.FillRandom("gaus") - gauss_6.Sumw2() - gauss_6.SetDirectory(0) - outHistFile = ROOT.TFile.Open(file_paths[2], "UPDATE") - outHistFile.cd() - gauss_6.Write() - outHistFile.Close() - h6 = uproot.from_pyroot(gauss_6) - - path = Path(tmp_path) - destination = path / "destination.root" - od.root.hadd(destination, file_paths, force=True, same_names=False) - - with uproot.open(destination) as file: - added = uproot.from_pyroot( - gauss_1 + gauss_3 + gauss_5 - ) # test od vs Pyroot histogram adding - assert file["name1"].member("fN") == added.member("fN") - assert file["name1"].member("fTsumw") == added.member("fTsumw") - assert np.equal(file["name1"].values(flow=True), added.values(flow=True)).all - assert file["name1"].member("fTsumw") == h1.member("fTsumw") + h3.member( - "fTsumw" - ) + h5.member("fTsumw") - added = uproot.from_pyroot( - gauss_2 + gauss_4 + gauss_6 - ) # test od vs Pyroot histogram adding - assert file["name2"].member("fN") == added.member("fN") - assert file["name2"].member("fTsumw") == added.member("fTsumw") - assert np.equal(file["name1"].values(flow=True), added.values(flow=True)).all - assert file["name2"].member("fTsumw") == h2.member("fTsumw") + h4.member( - "fTsumw" - ) + h6.member("fTsumw") - - -def test_3_glob(file_paths): - h1, h2, h3 = generate_1D_gaussian(file_paths) - - od.root.hadd("tests/place.root", "tests/samples", force=True) - - with uproot.open("tests/place.root") as file: - assert file["name"].member("fN") == h1.member("fN") - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h2.member( - "fTsumw" - ) + h3.member("fTsumw") - assert np.equal( - file["name"].values(flow=True), - np.array( - h1.values(flow=True) + h2.values(flow=True) + h3.values(flow=True) - ), - ).all - - -def simple_1dim_F(): - h1, h2 = generate_1D_simple() - od.root.hadd( - "tests/place2.root", - ["tests/file1dim1.root", "tests/file2dim1.root"], - force=True, - ) - - with uproot.open("tests/place2.root") as file: - assert file["name"].member("fN") == h1.member("fN") - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h2.member( - "fTsumw" - ) - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h1.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h2.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h1.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h2.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].values(flow=True), - np.array(h1.values(flow=True) + h2.values(flow=True)), - ).all - - -def mult_2D_hists(): - h1 = ROOT.TH2F("name", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data1 = [ - [13.5, 11.0, 10.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [11.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [10.5, 10.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [9.5, 9.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [8.5, 8.0, 9.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.0, 0.5], - [4.5, 7.0, 7.0, 7.2, 6.8, 5.32, 5.3, 2.0, 0.54, 0.25], - [3.5, 4.0, 4.0, 4.2, 6.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01], - ] - for i in range(len(data1)): - for j in range(len(data1[0])): - h1.Fill(i, j, data1[i][j]) - - outHistFile = ROOT.TFile.Open("tests/file3dim2.root", "RECREATE") - outHistFile.cd() - h1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(h1) - - h2 = ROOT.TH2F("second", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data2 = [ - [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [15.5, 13.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.5], - [12.5, 10.0, 9.5, 8.2, 6.8, 6.32, 5.2, 3.0, 2.0, 1.25], - [9.5, 9.0, 8.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.6, 0.5], - [8.5, 8.0, 6.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.0, 0.4], - [4.5, 4.0, 4.0, 7.2, 5.8, 5.32, 5.3, 2.0, 0.54, 0.3], - [3.5, 4.0, 4.0, 4.2, 5.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02], - ] - - for i in range(len(data2)): - for j in range(len(data2[0])): - h2.Fill(i, j, data2[i][j]) - - outHistFile = ROOT.TFile.Open("tests/file3dim2.root", "UPDATE") - outHistFile.cd() - h2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(h2) - - h3 = ROOT.TH2F("name", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data3 = [ - [13.5, 11.0, 10.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [11.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [10.5, 10.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.5, 1.6, 1.0], - [9.5, 9.0, 8.0, 7.2, 6.8, 5.32, 5.3, 3.0, 3.6, 1.0], - [8.5, 8.0, 9.0, 7.2, 6.8, 5.32, 5.3, 2.0, 2.0, 0.25], - [4.5, 7.0, 7.0, 7.2, 6.8, 5.32, 5.3, 2.0, 0.54, 0.25], - [3.5, 4.0, 4.0, 4.2, 6.8, 5.32, 5.3, 2.0, 1.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.51, 0.01, 0.41, 0.01, 0.01, 0.01], - ] - for i in range(len(data3)): - for j in range(len(data3[0])): - h3.Fill(i, j, data3[i][j]) - - outHistFile = ROOT.TFile.Open("tests/file4dim2.root", "RECREATE") - outHistFile.cd() - h3.Write() - outHistFile.Close() - h3 = uproot.from_pyroot(h3) - - h4 = ROOT.TH2F("second", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data4 = [ - [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [15.5, 13.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.5], - [12.5, 10.0, 9.5, 8.2, 6.8, 6.32, 5.2, 3.0, 2.0, 1.25], - [9.5, 9.0, 8.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.6, 0.5], - [8.5, 8.0, 6.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.0, 0.4], - [4.5, 4.0, 4.0, 7.2, 5.8, 5.32, 5.3, 2.0, 0.54, 0.3], - [3.5, 4.0, 4.0, 4.2, 5.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02], - ] - - for i in range(len(data4)): - for j in range(len(data4[0])): - h4.Fill(i, j, data4[i][j]) - - outHistFile = ROOT.TFile.Open("tests/file4dim2.root", "UPDATE") - outHistFile.cd() - h4.Write() - outHistFile.Close() - h4 = uproot.from_pyroot(h4) - - od.root.hadd( - "tests/place2.root", - ["tests/file3dim2.root", "tests/file4dim2.root"], - force=True, - ) - - with uproot.open("tests/place2.root") as file: - assert file["name"].member("fN") == h1.member("fN") - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h3.member( - "fTsumw" - ) - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h1.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h2.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h1.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h2.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h3.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h4.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h3.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h4.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].values(flow=True), - np.array(h1.values(flow=True) + h3.values(flow=True)), - ).all - assert np.equal( - file["second"].values(flow=True), - np.array(h2.values(flow=True) + h4.values(flow=True)), - ).all - - -def simple_2dim_F(): - fName = "name" - h1 = ROOT.TH2F(fName, "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data1 = [ - [13.5, 11.0, 10.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [11.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [10.5, 10.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [9.5, 9.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [8.5, 8.0, 9.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.0, 0.5], - [4.5, 7.0, 7.0, 7.2, 6.8, 5.32, 5.3, 2.0, 0.54, 0.25], - [3.5, 4.0, 4.0, 4.2, 6.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01], - ] - for i in range(len(data1)): - for j in range(len(data1[0])): - h1.Fill(i, j, data1[i][j]) - - h1 = uproot.from_pyroot(h1) - - h2 = ROOT.TH2F(fName, "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data2 = [ - [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [15.5, 13.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.5], - [12.5, 10.0, 9.5, 8.2, 6.8, 6.32, 5.2, 3.0, 2.0, 1.25], - [9.5, 9.0, 8.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.6, 0.5], - [8.5, 8.0, 6.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.0, 0.4], - [4.5, 4.0, 4.0, 7.2, 5.8, 5.32, 5.3, 2.0, 0.54, 0.3], - [3.5, 4.0, 4.0, 4.2, 5.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02], - ] - - for i in range(len(data2)): - for j in range(len(data2[0])): - h2.Fill(i, j, data2[i][j]) - - h2 = uproot.from_pyroot(h2) - - od.root.hadd( - "tests/place2.root", - ["tests/file1dim2.root", "tests/file2dim2.root"], - force=True, - ) - - with uproot.open("tests/place2.root") as file: - assert file["name"].member("fN") == h1.member("fN") - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h2.member( - "fTsumw" - ) - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h1.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h2.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h1.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h2.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].values(flow=True), - np.array(h1.values(flow=True) + h2.values(flow=True)), - ).all - - -def simple_2D(): - h2 = ROOT.TH2F("name", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data2 = [ - [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [15.5, 13.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.5], - [12.5, 10.0, 9.5, 8.2, 6.8, 6.32, 5.2, 3.0, 2.0, 1.25], - [9.5, 9.0, 8.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.6, 0.5], - [8.5, 8.0, 6.0, 7.2, 5.8, 5.32, 5.3, 2.0, 1.0, 0.4], - [4.5, 4.0, 4.0, 7.2, 5.8, 5.32, 5.3, 2.0, 0.54, 0.3], - [3.5, 4.0, 4.0, 4.2, 5.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02], - ] - - for i in range(len(data2)): - for j in range(len(data2[0])): - h2.Fill(i, j, data2[i][j]) - outHistFile = ROOT.TFile.Open("tests/file2dim2.root", "UPDATE") - outHistFile.cd() - h2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(h2) - - h1 = ROOT.TH2F("name", "", 10, 0.0, 10.0, 8, 0.0, 8.0) - data1 = [ - [13.5, 11.0, 10.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [11.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0], - [10.5, 10.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [9.5, 9.0, 8.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.6, 1.0], - [8.5, 8.0, 9.0, 7.2, 6.8, 5.32, 5.3, 2.0, 1.0, 0.5], - [4.5, 7.0, 7.0, 7.2, 6.8, 5.32, 5.3, 2.0, 0.54, 0.25], - [3.5, 4.0, 4.0, 4.2, 6.8, 5.32, 5.3, 2.0, 0.2, 0.1], - [1.5, 1.01, 0.21, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01], - ] - for i in range(len(data1)): - for j in range(len(data1[0])): - h1.Fill(i, j, data1[i][j]) - - outHistFile = ROOT.TFile.Open("tests/file1dim2.root", "RECREATE") - outHistFile.cd() - h1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(h1) - - od.root.hadd( - "tests/place2.root", - ["tests/file1dim2.root", "tests/file2dim2.root"], - force=True, - ) - - with uproot.open("tests/place2.root") as file: - assert file["name"].member("fN") == h1.member("fN") - assert file["name"].member("fTsumw") == h1.member("fTsumw") + h2.member( - "fTsumw" - ) - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h1.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fXaxis").edges(flow=True), - h2.member("fXaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h1.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].member("fYaxis").edges(flow=True), - h2.member("fYaxis").edges(flow=True), - ).all - assert np.equal( - file["name"].values(flow=True), - np.array(h1.values(flow=True) + h2.values(flow=True)), - ).all - - -def break_bins(): - h1 = ROOT.TH1F("name", "", 8, 0.0, 10.0) - data1 = [11.5, 12.0, 9.0, 8.1, 6.4, 6.32, 5.3, 3.0] - for i in range(len(data1)): - h1.Fill(i, data1[i]) - - outHistFile = ROOT.TFile.Open("tests/file1dim1break.root", "RECREATE") - outHistFile.cd() - h1.Write() - outHistFile.Close() - h1 = uproot.from_pyroot(h1) - - h2 = ROOT.TH1F("name", "", 10, 0.0, 10.0) - data2 = [21.5, 10.0, 9.0, 8.2, 6.8, 6.32, 5.3, 3.0, 2.0, 1.0] - - for i in range(len(data2)): - h2.Fill(i, data2[i]) - - outHistFile = ROOT.TFile.Open("tests/file2dim1break.root", "RECREATE") - outHistFile.cd() - h2.Write() - outHistFile.Close() - h2 = uproot.from_pyroot(h2) - - od.root.hadd( - "tests/place2break.root", - ["tests/file1dim1break.root", "tests/file2dim1break.root"], - force=True, - ) diff --git a/tests/test_package.py b/tests/test_package.py index 7abc07f..eb76eb3 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -2,8 +2,8 @@ import importlib.metadata -import odapt as m +import hepconvert as m def test_version(): - assert importlib.metadata.version("odapt") == m.__version__ + assert importlib.metadata.version("hepconvert") == m.__version__ diff --git a/tests/test_parquet_to_root.py b/tests/test_parquet_to_root.py index 4f7f3e4..3a6e490 100644 --- a/tests/test_parquet_to_root.py +++ b/tests/test_parquet_to_root.py @@ -4,7 +4,7 @@ import pytest import uproot -from odapt.parquet_to_root import parquet_to_root +from hepconvert.parquet_to_root import parquet_to_root skhep_testdata = pytest.importorskip("skhep_testdata") diff --git a/tests/test_root_to_parquet.py b/tests/test_root_to_parquet.py index 92717a2..3eaa837 100644 --- a/tests/test_root_to_parquet.py +++ b/tests/test_root_to_parquet.py @@ -4,7 +4,7 @@ import pytest import uproot -import odapt as od +import hepconvert skhep_testdata = pytest.importorskip("skhep_testdata") @@ -12,13 +12,13 @@ def HZZ_test(): f = uproot.open(skhep_testdata.data_path("uproot-HZZ.root")) original = f["events"].arrays() - od.root_to_parquet( + hepconvert.root_to_parquet( in_file=skhep_testdata.data_path("uproot-HZZ.root"), out_file="test.parquet", step_size="100 MB", force=True, ) - from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test.parquet") + from_parquet = ak.from_parquet("/Users/zobil/Documents/hepconvert/test.parquet") for key in f["events"].keys(): assert ak.all(from_parquet[0][key] == original[key]) @@ -26,14 +26,14 @@ def HZZ_test(): def specify_tree(): f = uproot.open(skhep_testdata.data_path("uproot-HZZ.root")) original = f["events"].arrays() - od.root_to_parquet( + hepconvert.root_to_parquet( in_file=skhep_testdata.data_path("uproot-HZZ.root"), out_file="test.parquet", tree="events", step_size="100 MB", force=True, ) - from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test.parquet") + from_parquet = ak.from_parquet("/Users/zobil/Documents/hepconvert/test.parquet") for key in f["events"].keys(): assert ak.all(from_parquet[0][key] == original[key]) @@ -41,19 +41,19 @@ def specify_tree(): def Zmumu_test(): f = uproot.open(skhep_testdata.data_path("uproot-Zmumu.root")) original = f["events"].arrays() - od.root_to_parquet( + hepconvert.root_to_parquet( in_file=skhep_testdata.data_path("uproot-Zmumu.root"), out_file="test1.parquet", step_size="100 MB", ) - from_parquet = ak.from_parquet("/Users/zobil/Documents/odapt/test1.parquet") + from_parquet = ak.from_parquet("/Users/zobil/Documents/hepconvert/test1.parquet") for key in f["events"].keys(): assert ak.all(from_parquet[0][key] == original[key]) def break_trees(): with pytest.raises(AttributeError): - od.root_to_parquet( + hepconvert.root_to_parquet( in_file=skhep_testdata.data_path("uproot-hepdata-example.root"), out_file="test2.parquet", step_size="100 MB", diff --git a/tests/test_ttree_merge.py b/tests/test_ttree_merge.py deleted file mode 100644 index c854ae0..0000000 --- a/tests/test_ttree_merge.py +++ /dev/null @@ -1,130 +0,0 @@ -from __future__ import annotations - -import awkward as ak -import numpy as np -import pytest -import uproot - -from odapt import merge - -skhep_testdata = pytest.importorskip("skhep_testdata") - - -def test_simple(): - merge.hadd_and_merge( - "od_test_simple.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - ], - counter_name=lambda counted: "N" + counted, - ) - odapt_file = uproot.open("od_test_hist.root") - hadd_file = uproot.open( - "/Users/zobil/Documents/odapt/src/odapt/operations/HZZ-hadd.root" - ) - assert ak.all(odapt_file.keys() == hadd_file.keys()) - for key in odapt_file["events"]: - assert ak.all( - odapt_file["events"].arrays()[key] == hadd_file["events"].arrays()[key] - ) - - -def test_hists(): - merge.hadd_and_merge( - "od_test_hists.root", - [ - skhep_testdata.data_path("uproot-hepdata-example.root"), - skhep_testdata.data_path("uproot-hepdata-example.root"), - ], - step_size=100, - counter_name=lambda counted: "N" + counted, - ) - odapt_file = uproot.open("od_test_hists.root") - hadd_file = uproot.open( - "/Users/zobil/Documents/odapt/src/odapt/operations/hadd-hepdata.root" - ) - - assert ak.all(odapt_file["hpx"].values() == hadd_file["hpx"].values()) - - -def test_force(): - uproot.recreate("od_test_force.root") - merge.hadd_and_merge( - "od_test_force.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - "nonexistent_file.root", - ], - force=False, - ) - with pytest.raises(FileExistsError) as excinfo: - merge.hadd_and_merge( - "od_test_force.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - "nonexistent_file.root", - ], - force=False, - ) - assert "file exists " in str(excinfo.value) - try: - merge.hadd_and_merge( - "od_test_force.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - "nonexistent_file.root", - ], - force=True, - ) - except FileExistsError: - pytest.fail("Error with force argument") - - -def test_skip_bad_files(): - merge.hadd_and_merge( - "od_test_skip_files.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - "nonexistent_file.root", - ], - skip_bad_files=True, - ) - - with pytest.raises(FileNotFoundError) as excinfo: - merge.hadd_and_merge( - "od_test_skip_files.root", - [ - skhep_testdata.data_path("uproot-HZZ.root"), - skhep_testdata.data_path("uproot-HZZ.root"), - "nonexistent_file.root", - ], - skip_bad_files=False, - ) - assert "does not exist or is corrupt." in str(excinfo.value) - - -def realistic_data(): - merge.hadd_and_merge( - "test_existing_file.root", - [ - skhep_testdata.data_path("nanoAOD_2015_CMS_Open_Data_ttbar.root"), - skhep_testdata.data_path("nanoAOD_2015_CMS_Open_Data_ttbar.root"), - skhep_testdata.data_path("nanoAOD_2015_CMS_Open_Data_ttbar.root"), - ], - step_size="100 MB", - ) - - odapt_file = uproot.open("test_existing_file.root") - hadd_file = uproot.open( - "/Users/zobil/Documents/odapt/tests/samples/test_existing.root" - ) - for key in hadd_file["Events"]: - assert np.equal( - odapt_file["Events"].arrays()[key].to_numpy, - hadd_file["Events"].arrays()[key].to_numpy, - ).all