From b44d7dba8a9464eb42535bb98b57aa874f42e81d Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 1 Dec 2020 15:41:51 -0600 Subject: [PATCH] The great name change: uproot4 -> uproot. (#211) * The great name change: uproot4 -> uproot. * Black and Flake8. * Added builder for uproot4 thin package (untested) and bump Awkward version requirement. * Try again. * Actually ask for awkward>=1.0.0rc1 in the workflow. * Add uproot.interpretation.identify. --- .github/ISSUE_TEMPLATE/bug-report.md | 6 +- .github/ISSUE_TEMPLATE/documentation.md | 2 +- .github/ISSUE_TEMPLATE/feature-request.md | 2 +- .github/workflows/build-test.yml | 2 +- .gitignore | 4 +- build-uproot4.sh | 70 +++ docs-sphinx/basic.rst | 130 ++-- docs-sphinx/index.rst | 38 +- docs-sphinx/make_changelog.py | 2 +- docs-sphinx/prepare_docstrings.py | 58 +- docs-sphinx/requirements.txt | 2 +- docs-sphinx/uproot3-to-4.rst | 106 ++-- requirements-dev.txt | 2 +- setup.cfg | 2 +- setup.py | 4 +- tests/test_0001-source-class.py | 71 +-- tests/test_0006-notify-when-downloaded.py | 30 +- tests/test_0007-single-chunk-interface.py | 30 +- tests/test_0008-start-interpretation.py | 17 +- tests/test_0009-nested-directories.py | 5 +- tests/test_0010-start-streamers.py | 5 +- ...st_0011-generate-classes-from-streamers.py | 5 +- tests/test_0013-rntuple-anchor.py | 8 +- tests/test_0014-all-ttree-versions.py | 90 +-- tests/test_0016-interpretations.py | 14 +- ...st_0017-multi-basket-multi-branch-fetch.py | 65 +- tests/test_0018-array-fetching-interface.py | 61 +- tests/test_0022-number-of-branches.py | 19 +- tests/test_0023-more-interpretations-1.py | 43 +- tests/test_0028-fallback-to-read-streamer.py | 4 +- tests/test_0029-more-string-types.py | 42 +- tests/test_0031-test-stl-containers.py | 70 +-- tests/test_0033-more-interpretations-2.py | 38 +- tests/test_0034-generic-objects-in-ttrees.py | 274 ++++---- tests/test_0035-datatype-generality.py | 8 +- tests/test_0043-iterate-function.py | 34 +- tests/test_0044-concatenate-function.py | 14 +- tests/test_0045-lazy-arrays-1.py | 36 +- tests/test_0046-histograms-bh-hist.py | 23 +- .../test_0053-parents-should-not-be-bases.py | 10 +- ...st_0058-detach-model-objects-from-files.py | 14 +- tests/test_0066-fix-http-fallback-freeze.py | 4 +- tests/test_0067-common-entry-offsets.py | 8 +- tests/test_0081-dont-parse-colons.py | 64 +- ...wise-splitting-not-implemented-messages.py | 8 +- tests/test_0088-read-with-http.py | 8 +- tests/test_0099-read-from-file-object.py | 4 +- tests/test_0112-fix-pandas-with-cut.py | 4 +- tests/test_0118-fix-name-fetch-again.py | 28 +- tests/test_0123-atlas-issues.py | 10 +- ...rn-unknown-emptyarrays-into-known-types.py | 8 +- ...0167-use-the-common-histogram-interface.py | 12 +- ...72-allow-allocators-in-vector-typenames.py | 4 +- ...est_0173-empty-and-multiprocessing-bugs.py | 8 +- .../test_0182-complain-about-missing-files.py | 11 +- tests/test_0194-fix-lost-cuts-in-iterate.py | 4 +- tests/test_versions.py | 6 +- uproot/__init__.py | 218 +++++++ {uproot4 => uproot}/_util.py | 204 +++--- {uproot4 => uproot}/behaviors/TAxis.py | 0 {uproot4 => uproot}/behaviors/TBranch.py | 585 +++++++++--------- .../behaviors/TBranchElement.py | 10 +- {uproot4 => uproot}/behaviors/TH1.py | 24 +- {uproot4 => uproot}/behaviors/TH2.py | 18 +- {uproot4 => uproot}/behaviors/TH2Poly.py | 6 +- {uproot4 => uproot}/behaviors/TH3.py | 19 +- {uproot4 => uproot}/behaviors/TProfile.py | 23 +- {uproot4 => uproot}/behaviors/TProfile2D.py | 22 +- {uproot4 => uproot}/behaviors/TProfile3D.py | 22 +- {uproot4 => uproot}/behaviors/TTree.py | 28 +- {uproot4 => uproot}/behaviors/__init__.py | 6 +- {uproot4 => uproot}/cache.py | 8 +- {uproot4 => uproot}/compression.py | 50 +- {uproot4 => uproot}/const.py | 0 {uproot4 => uproot}/containers.py | 237 ++++--- {uproot4 => uproot}/deserialization.py | 124 ++-- {uproot4 => uproot}/dynamic.py | 14 +- {uproot4 => uproot}/exceptions.py | 10 +- {uproot4 => uproot}/extras.py | 12 +- .../interpretation/__init__.py | 60 +- {uproot4 => uproot}/interpretation/grouped.py | 27 +- .../interpretation/identify.py | 258 ++++---- {uproot4 => uproot}/interpretation/jagged.py | 49 +- {uproot4 => uproot}/interpretation/library.py | 268 ++++---- .../interpretation/numerical.py | 77 ++- {uproot4 => uproot}/interpretation/objects.py | 185 +++--- {uproot4 => uproot}/interpretation/strings.py | 57 +- uproot/language/__init__.py | 24 + {uproot4 => uproot}/language/python.py | 20 +- {uproot4 => uproot}/model.py | 482 +++++++-------- {uproot4 => uproot}/models/RNTuple.py | 9 +- {uproot4 => uproot}/models/TArray.py | 44 +- {uproot4 => uproot}/models/TAtt.py | 130 ++-- {uproot4 => uproot}/models/TBasket.py | 41 +- {uproot4 => uproot}/models/TBranch.py | 76 +-- {uproot4 => uproot}/models/THashList.py | 10 +- {uproot4 => uproot}/models/TLeaf.py | 125 ++-- {uproot4 => uproot}/models/TList.py | 16 +- {uproot4 => uproot}/models/TNamed.py | 25 +- {uproot4 => uproot}/models/TObjArray.py | 27 +- {uproot4 => uproot}/models/TObjString.py | 18 +- {uproot4 => uproot}/models/TObject.py | 34 +- {uproot4 => uproot}/models/TRef.py | 43 +- {uproot4 => uproot}/models/TString.py | 10 +- {uproot4 => uproot}/models/TTree.py | 89 ++- {uproot4 => uproot}/models/__init__.py | 22 +- {uproot4 => uproot}/reading.py | 558 ++++++++--------- {uproot4 => uproot}/source/__init__.py | 6 +- {uproot4 => uproot}/source/chunk.py | 98 ++- {uproot4 => uproot}/source/cursor.py | 145 +++-- {uproot4 => uproot}/source/file.py | 62 +- {uproot4 => uproot}/source/futures.py | 98 +-- {uproot4 => uproot}/source/http.py | 106 ++-- {uproot4 => uproot}/source/object.py | 30 +- {uproot4 => uproot}/source/xrootd.py | 66 +- {uproot4 => uproot}/streamers.py | 269 ++++---- {uproot4 => uproot}/version.py | 2 +- uproot4/__init__.py | 210 ------- uproot4/language/__init__.py | 24 - 119 files changed, 3532 insertions(+), 3659 deletions(-) create mode 100644 build-uproot4.sh create mode 100644 uproot/__init__.py rename {uproot4 => uproot}/_util.py (75%) rename {uproot4 => uproot}/behaviors/TAxis.py (100%) rename {uproot4 => uproot}/behaviors/TBranch.py (84%) rename {uproot4 => uproot}/behaviors/TBranchElement.py (65%) rename {uproot4 => uproot}/behaviors/TH1.py (92%) rename {uproot4 => uproot}/behaviors/TH2.py (90%) rename {uproot4 => uproot}/behaviors/TH2Poly.py (84%) rename {uproot4 => uproot}/behaviors/TH3.py (89%) rename {uproot4 => uproot}/behaviors/TProfile.py (93%) rename {uproot4 => uproot}/behaviors/TProfile2D.py (82%) rename {uproot4 => uproot}/behaviors/TProfile3D.py (84%) rename {uproot4 => uproot}/behaviors/TTree.py (76%) rename {uproot4 => uproot}/behaviors/__init__.py (86%) rename {uproot4 => uproot}/cache.py (96%) rename {uproot4 => uproot}/compression.py (84%) rename {uproot4 => uproot}/const.py (100%) rename {uproot4 => uproot}/containers.py (82%) rename {uproot4 => uproot}/deserialization.py (78%) rename {uproot4 => uproot}/dynamic.py (56%) rename {uproot4 => uproot}/exceptions.py (89%) rename {uproot4 => uproot}/extras.py (96%) rename {uproot4 => uproot}/interpretation/__init__.py (69%) rename {uproot4 => uproot}/interpretation/grouped.py (80%) rename {uproot4 => uproot}/interpretation/identify.py (78%) rename {uproot4 => uproot}/interpretation/jagged.py (88%) rename {uproot4 => uproot}/interpretation/library.py (81%) rename {uproot4 => uproot}/interpretation/numerical.py (88%) rename {uproot4 => uproot}/interpretation/objects.py (71%) rename {uproot4 => uproot}/interpretation/strings.py (86%) create mode 100644 uproot/language/__init__.py rename {uproot4 => uproot}/language/python.py (95%) rename {uproot4 => uproot}/model.py (71%) rename {uproot4 => uproot}/models/RNTuple.py (83%) rename {uproot4 => uproot}/models/TArray.py (75%) rename {uproot4 => uproot}/models/TAtt.py (71%) rename {uproot4 => uproot}/models/TBasket.py (86%) rename {uproot4 => uproot}/models/TBranch.py (91%) rename {uproot4 => uproot}/models/THashList.py (83%) rename {uproot4 => uproot}/models/TLeaf.py (76%) rename {uproot4 => uproot}/models/TList.py (82%) rename {uproot4 => uproot}/models/TNamed.py (72%) rename {uproot4 => uproot}/models/TObjArray.py (78%) rename {uproot4 => uproot}/models/TObjString.py (80%) rename {uproot4 => uproot}/models/TObject.py (73%) rename {uproot4 => uproot}/models/TRef.py (80%) rename {uproot4 => uproot}/models/TString.py (85%) rename {uproot4 => uproot}/models/TTree.py (88%) rename {uproot4 => uproot}/models/__init__.py (66%) rename {uproot4 => uproot}/reading.py (78%) rename {uproot4 => uproot}/source/__init__.py (75%) rename {uproot4 => uproot}/source/chunk.py (74%) rename {uproot4 => uproot}/source/cursor.py (76%) rename {uproot4 => uproot}/source/file.py (74%) rename {uproot4 => uproot}/source/futures.py (71%) rename {uproot4 => uproot}/source/http.py (83%) rename {uproot4 => uproot}/source/object.py (74%) rename {uproot4 => uproot}/source/xrootd.py (81%) rename {uproot4 => uproot}/streamers.py (83%) rename {uproot4 => uproot}/version.py (95%) delete mode 100644 uproot4/__init__.py delete mode 100644 uproot4/language/__init__.py diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 043c2daa6..92ac3c70c 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -13,9 +13,9 @@ Note that we'll be closing the issue as soon as a solution is proposed. This is Please attach a small ROOT file that reproduces the issue! If small and public, you can drag-and-drop it into the issue. If large, you can put it on some large-file service (e.g. Dropbox). In general, we can't access XRootD URLs (most are not public). -Include the version number (and update if necessary, if you're not using the [latest version](https://pypi.org/project/uproot4/)). +Include the version number (and update if necessary, if you're not using the [latest version](https://pypi.org/project/uproot/)). ```python ->>> import uproot4 ->>> uproot4.__version__ +>>> import uproot +>>> uproot.__version__ ``` diff --git a/.github/ISSUE_TEMPLATE/documentation.md b/.github/ISSUE_TEMPLATE/documentation.md index a334f4a97..5e9cc5582 100644 --- a/.github/ISSUE_TEMPLATE/documentation.md +++ b/.github/ISSUE_TEMPLATE/documentation.md @@ -7,7 +7,7 @@ assignees: '' --- -On the [tutorials site](https://uproot4.readthedocs.io/)? +On the [tutorials site](https://uproot.readthedocs.io/)? In the Python docstrings? (They're presented on the same website.) diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md index 226f60778..09b059c8a 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -11,6 +11,6 @@ What you're looking for might already be possible as a combination of existing f Here are some links to documentation, to help you in your search. - * [The tutorials site](https://uproot4.readthedocs.io/) + * [The tutorials site](https://uproot.readthedocs.io/) * [StackOverflow: [uproot] tag](https://stackoverflow.com/questions/tagged/uproot) * [Gitter: Scikit-HEP/uproot room](https://gitter.im/Scikit-HEP/uproot) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2cf50086c..b0b3456e9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -50,7 +50,7 @@ jobs: - name: "Install Awkward" run: | conda env list - pip install awkward1 + pip install "awkward>=1.0.0rc1" conda list - name: "Install XRootD" diff --git a/.gitignore b/.gitignore index a5e8c79f0..14432331c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Sphinx documentation docs-sphinx/_build -docs-sphinx/uproot4.rst -docs-sphinx/uproot4.*.rst +docs-sphinx/uproot.rst +docs-sphinx/uproot.*.rst docs-sphinx/*.toctree # Byte-compiled / optimized / DLL files diff --git a/build-uproot4.sh b/build-uproot4.sh new file mode 100644 index 000000000..91a45075d --- /dev/null +++ b/build-uproot4.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +set -e + +rm -rf build dist +mkdir build +mkdir build/uproot4 + +cat > build/uproot4/__init__.py << EOF +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +from __future__ import absolute_import + +from uproot import * +EOF + +cat > build/uproot4-setup.py << EOF + +import setuptools +from setuptools import setup + +def get_version(): + g = {} + exec(open(os.path.join("uproot", "version.py")).read(), g) + return g["__version__"] + +setup(name = "uproot4", + packages = ["uproot4"], + package_dir = {"": "build"}, + version = get_version(), + author = "Jim Pivarski", + author_email = "pivarski@princeton.edu", + maintainer = "Jim Pivarski", + maintainer_email = "pivarski@princeton.edu", + description = "ROOT I/O in pure Python and NumPy.", + long_description = open("README.md").read(), + long_description_content_type = "text/markdown", + url = "https://github.com/scikit-hep/uproot4", + download_url = "https://github.com/scikit-hep/uproot4/releases", + license = "BSD 3-clause", + python_requires = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", + install_requires = ["uproot>=4.0.0rc1"], + classifiers = [ +# "Development Status :: 1 - Planning", +# "Development Status :: 2 - Pre-Alpha", +# "Development Status :: 3 - Alpha", +# "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", +# "Development Status :: 6 - Mature", +# "Development Status :: 7 - Inactive", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Information Analysis", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Software Development", + "Topic :: Utilities", + ]) +EOF diff --git a/docs-sphinx/basic.rst b/docs-sphinx/basic.rst index ad8ca9501..11a8333df 100644 --- a/docs-sphinx/basic.rst +++ b/docs-sphinx/basic.rst @@ -4,36 +4,36 @@ Getting started guide Opening a file -------------- -Open a ROOT file for reading with the `uproot4.open `__ function. +Open a ROOT file for reading with the `uproot.open `__ function. .. code-block:: python - >>> import uproot4 - >>> file = uproot4.open("path/to/dataset.root") + >>> import uproot + >>> file = uproot.open("path/to/dataset.root") -The `uproot4.open `__ function can also be used like this: +The `uproot.open `__ function can also be used like this: .. code-block:: python - >>> with uproot4.open("path/to/dataset.root") as file: + >>> with uproot.open("path/to/dataset.root") as file: ... do_something... to automatically close the file after leaving the ``with`` block. The path-name argument can be a local file (as above), a URL ("``http://``" or "``https://``"), or XRootD ("``root://``") if you have the `Python interface to XRootD `__ installed. It can also be a Python file-like object with ``read`` and ``seek`` methods, but such objects can't be read in parallel. -The `uproot4.open `__ function has many options, including alternate handlers for each input type, ``num_workers`` to control parallel reading, and caches (``object_cache`` and ``array_cache``). The defaults attempt to optimize parallel processing, caching, and batching of remote requests, but better performance can often be obtained by tuning these parameters. +The `uproot.open `__ function has many options, including alternate handlers for each input type, ``num_workers`` to control parallel reading, and caches (``object_cache`` and ``array_cache``). The defaults attempt to optimize parallel processing, caching, and batching of remote requests, but better performance can often be obtained by tuning these parameters. Finding objects in a file ------------------------- -The object returned by `uproot4.open `__ represents a TDirectory inside the file (``/``). +The object returned by `uproot.open `__ represents a TDirectory inside the file (``/``). .. code-block:: python - >>> file = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") + >>> file = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") >>> file -This object is a Python `Mapping `__, which means that you can get a list of contents with :py:meth:`~uproot4.reading.ReadOnlyDirectory.keys`. +This object is a Python `Mapping `__, which means that you can get a list of contents with :py:meth:`~uproot.reading.ReadOnlyDirectory.keys`. .. code-block:: python @@ -53,9 +53,9 @@ and extract an item (read it from the file) with square brackets. The cycle numb >>> file["one/two/tree"] -Data, including nested TDirectories, are not read from disk until they are explicitly requested with square brackets (or another `Mapping `__ function, like :py:meth:`~uproot4.reading.ReadOnlyDirectory.values` or :py:meth:`~uproot4.reading.ReadOnlyDirectory.items`). +Data, including nested TDirectories, are not read from disk until they are explicitly requested with square brackets (or another `Mapping `__ function, like :py:meth:`~uproot.reading.ReadOnlyDirectory.values` or :py:meth:`~uproot.reading.ReadOnlyDirectory.items`). -You can get the names of classes without reading the objects by using :py:meth:`~uproot4.reading.ReadOnlyDirectory.classnames`. +You can get the names of classes without reading the objects by using :py:meth:`~uproot.reading.ReadOnlyDirectory.classnames`. .. code-block:: python @@ -67,7 +67,7 @@ As a shortcut, you can open a file and jump straight to the object by separating .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events @@ -80,7 +80,7 @@ Uproot can read most types of objects, but only a few of them have been overload .. code-block:: python - >>> file = uproot4.open("https://scikit-hep.org/uproot3/examples/hepdata-example.root") + >>> file = uproot.open("https://scikit-hep.org/uproot3/examples/hepdata-example.root") >>> file.classnames() {'hpx': 'TH1F', 'hpxpy': 'TH2F', 'hprof': 'TProfile', 'ntuple': 'TNtuple'} @@ -104,9 +104,9 @@ Classes unknown to Uproot can be accessed through their members (raw C++ members >>> file["hpx"].member("fName") 'hpx' -But some classes, like :py:class:`~uproot4.behaviors.TH1.TH1`, :py:class:`~uproot4.behaviors.TProfile.TProfile`, and :py:class:`~uproot4.behaviors.TH2.TH2`, have high-level "behaviors" defined in :py:mod:`uproot4.behaviors` to make them easier to use. +But some classes, like :py:class:`~uproot.behaviors.TH1.TH1`, :py:class:`~uproot.behaviors.TProfile.TProfile`, and :py:class:`~uproot.behaviors.TH2.TH2`, have high-level "behaviors" defined in :py:mod:`uproot.behaviors` to make them easier to use. -Histograms have :py:meth:`~uproot4.behaviors.TH1.TH1.edges`, :py:meth:`~uproot4.behaviors.TH1.TH1.values`, and :py:meth:`~uproot4.behaviors.TH1.TH1.values_errors` methods to extract histogram axes and bin contents directly into NumPy arrays. (Keep in mind that a histogram axis with *N* bins has *N + 1* edges, and that the edges include underflow and overflow as ``-np.inf`` and ``np.inf`` endpoints.) +Histograms have :py:meth:`~uproot.behaviors.TH1.TH1.edges`, :py:meth:`~uproot.behaviors.TH1.TH1.values`, and :py:meth:`~uproot.behaviors.TH1.TH1.values_errors` methods to extract histogram axes and bin contents directly into NumPy arrays. (Keep in mind that a histogram axis with *N* bins has *N + 1* edges, and that the edges include underflow and overflow as ``-np.inf`` and ``np.inf`` endpoints.) .. code-block:: python @@ -229,7 +229,7 @@ Since Uproot is an I/O library, it intentionally does not have methods for plott >>> file["hpxpy"].to_hist() # Traceback (most recent call last): - # File "/home/jpivarski/irishep/uproot4/uproot4/extras.py", line 237, in hist + # File "/home/jpivarski/irishep/uproot/uproot/extras.py", line 237, in hist # import hist # ModuleNotFoundError: No module named 'hist' # @@ -237,9 +237,9 @@ Since Uproot is an I/O library, it intentionally does not have methods for plott # # Traceback (most recent call last): # File "", line 1, in - # File "/home/jpivarski/irishep/uproot4/uproot4/behaviors/TH2.py", line 127, in to_hist - # return uproot4.extras.hist().Hist(self.to_boost()) - # File "/home/jpivarski/irishep/uproot4/uproot4/extras.py", line 239, in hist + # File "/home/jpivarski/irishep/uproot/uproot/behaviors/TH2.py", line 127, in to_hist + # return uproot.extras.hist().Hist(self.to_boost()) + # File "/home/jpivarski/irishep/uproot/uproot/extras.py", line 239, in hist # raise ImportError( # ImportError: install the 'hist' package with: # @@ -256,11 +256,11 @@ For histogramming, I recommend Inspecting a TBranches of a TTree --------------------------------- -:py:class:`~uproot4.behaviors.TTree.TTree`, with the lists of :py:class:`~uproot4.behaviors.TBranch.TBranch` it contains, are Uproot's most important "overloaded behaviors." Like :py:class:`~uproot4.reading.ReadOnlyDirectory`, a TTree is a `Mapping `__, though it maps TBranch names to the (already read) :py:class:`~uproot4.behaviors.TBranch.TBranch` objects it contains. Since TBranches can contain more TBranches, both of these are subclasses of a general :py:class:`~uproot4.behaviors.TBranch.HasBranches`. +:py:class:`~uproot.behaviors.TTree.TTree`, with the lists of :py:class:`~uproot.behaviors.TBranch.TBranch` it contains, are Uproot's most important "overloaded behaviors." Like :py:class:`~uproot.reading.ReadOnlyDirectory`, a TTree is a `Mapping `__, though it maps TBranch names to the (already read) :py:class:`~uproot.behaviors.TBranch.TBranch` objects it contains. Since TBranches can contain more TBranches, both of these are subclasses of a general :py:class:`~uproot.behaviors.TBranch.HasBranches`. .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events.keys() ['Type', 'Run', 'Event', 'E1', 'px1', 'py1', 'pz1', 'pt1', 'eta1', 'phi1', 'Q1', 'E2', 'px2', @@ -281,7 +281,7 @@ Inspecting a TBranches of a TTree >>> events["M"] -Like a TDirectory's :py:meth:`~uproot4.reading.ReadOnlyDirectory.classnames`, you can access the TBranch data types without reading data by calling :py:meth:`~uproot4.behaviors.TBranch.HasBranches.typenames`. +Like a TDirectory's :py:meth:`~uproot.reading.ReadOnlyDirectory.classnames`, you can access the TBranch data types without reading data by calling :py:meth:`~uproot.behaviors.TBranch.HasBranches.typenames`. .. code-block:: python @@ -291,7 +291,7 @@ Like a TDirectory's :py:meth:`~uproot4.reading.ReadOnlyDirectory.classnames`, yo 'Q1': 'int32_t', 'E2': 'double', 'px2': 'double', 'py2': 'double', 'pz2': 'double', 'pt2': 'double', 'eta2': 'double', 'phi2': 'double', 'Q2': 'int32_t', 'M': 'double'} -In an interactive session, it's often more convenient to call :py:meth:`~uproot4.behaviors.TBranch.HasBranches.show`. +In an interactive session, it's often more convenient to call :py:meth:`~uproot.behaviors.TBranch.HasBranches.show`. .. code-block:: python @@ -324,11 +324,11 @@ The third column, ``interpretation``, indicates how data in the TBranch will be Reading a TBranch as an array ----------------------------- -A TBranch may be turned into an array with the :py:meth:`~uproot4.behaviors.TBranch.TBranch.array` method. The array is not read from disk until this method is called (or other array-fetching methods described below). +A TBranch may be turned into an array with the :py:meth:`~uproot.behaviors.TBranch.TBranch.array` method. The array is not read from disk until this method is called (or other array-fetching methods described below). .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events["M"].array() @@ -364,7 +364,7 @@ If you don't have the specified library (including the default, Awkward), you'll >>> events["M"].array(library="cp") Traceback (most recent call last): - File "/home/jpivarski/irishep/uproot4/uproot4/extras.py", line 60, in cupy + File "/home/jpivarski/irishep/uproot/uproot/extras.py", line 60, in cupy import cupy ModuleNotFoundError: No module named 'cupy' @@ -380,16 +380,16 @@ If you don't have the specified library (including the default, Awkward), you'll (CuPy can only be used on computers with GPUs.) -The :py:meth:`~uproot4.behaviors.TBranch.TBranch.array` method has many options, including limitations on reading (``entry_start`` and ``entry_stop``), parallelization (``decompression_executor`` and ``interpretation_executor``), and caching (``array_cache``). For details, see the reference documentation for :py:meth:`~uproot4.behaviors.TBranch.TBranch.array`. +The :py:meth:`~uproot.behaviors.TBranch.TBranch.array` method has many options, including limitations on reading (``entry_start`` and ``entry_stop``), parallelization (``decompression_executor`` and ``interpretation_executor``), and caching (``array_cache``). For details, see the reference documentation for :py:meth:`~uproot.behaviors.TBranch.TBranch.array`. Reading multiple TBranches as a group of arrays ----------------------------------------------- -To read more than one TBranch, you could use the :py:meth:`~uproot4.behaviors.TBranch.TBranch.array` method from the previous section multiple times, but you could also use :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` (plural) on the TTree itself. +To read more than one TBranch, you could use the :py:meth:`~uproot.behaviors.TBranch.TBranch.array` method from the previous section multiple times, but you could also use :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays` (plural) on the TTree itself. .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> momentum = events.arrays(["px1", "py1", "pz1"]) >>> momentum @@ -459,13 +459,13 @@ Even though you can extract individual arrays from these objects, they're read, Filtering TBranches ------------------- -If no arguments are passed to :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, *all* TBranches will be read. If your file has many TBranches, this might not be desirable or possible. You can select specific TBranches by name, as in the previous section, but you can also use a filter (``filter_name``, ``filter_typename``, or ``filter_branch``) to select TBranches by name, type, or other attributes. +If no arguments are passed to :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, *all* TBranches will be read. If your file has many TBranches, this might not be desirable or possible. You can select specific TBranches by name, as in the previous section, but you can also use a filter (``filter_name``, ``filter_typename``, or ``filter_branch``) to select TBranches by name, type, or other attributes. -The :py:meth:`~uproot4.behaviors.TBranch.HasBranches.keys`, :py:meth:`~uproot4.behaviors.TBranch.HasBranches.values`, :py:meth:`~uproot4.behaviors.TBranch.HasBranches.items`, and :py:meth:`~uproot4.behaviors.TBranch.HasBranches.typenames` methods take the same arguments, so you can test your filters before reading any data. +The :py:meth:`~uproot.behaviors.TBranch.HasBranches.keys`, :py:meth:`~uproot.behaviors.TBranch.HasBranches.values`, :py:meth:`~uproot.behaviors.TBranch.HasBranches.items`, and :py:meth:`~uproot.behaviors.TBranch.HasBranches.typenames` methods take the same arguments, so you can test your filters before reading any data. .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events.keys(filter_name="px*") ['px1', 'px2'] @@ -485,11 +485,11 @@ The :py:meth:`~uproot4.behaviors.TBranch.HasBranches.keys`, :py:meth:`~uproot4.b Computing expressions and cuts ------------------------------ -The first argument of :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, which we used above to pass explicit TBranch names, +The first argument of :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, which we used above to pass explicit TBranch names, .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events.arrays(["px1", "py1", "pz1"]) @@ -527,7 +527,7 @@ Note that expressions are *not*, in general, computed more quickly if expressed but perhaps more convenient. If what you want to compute requires more than one expression, you'll have to move it out of strings into Python. -The default ``language`` is :py:class:`~uproot4.language.python.PythonLanguage`, but other languages, like ROOT's `TTree::Draw syntax `_ are foreseen *in the future*. Thus, implicit loops (e.g. ``Sum$(...)``) have to be translated to their Awkward equivalents and ``ROOT::Math`` functions have to be translated to their NumPy equivalents. +The default ``language`` is :py:class:`~uproot.language.python.PythonLanguage`, but other languages, like ROOT's `TTree::Draw syntax `_ are foreseen *in the future*. Thus, implicit loops (e.g. ``Sum$(...)``) have to be translated to their Awkward equivalents and ``ROOT::Math`` functions have to be translated to their NumPy equivalents. Nested data structures ---------------------- @@ -536,7 +536,7 @@ Not all datasets have one value per entry. In particle physics, we often have di .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/HZZ.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/HZZ.root:events") >>> events.show() name | typename | interpretation ---------------------+--------------------------+------------------------------- @@ -680,11 +680,11 @@ In general, array-based workflows must iterate over batches with an optimized st Procedural workflows, which operate on one entry (e.g. one particle physics collision event) at a time can be seen as an extreme of the latter, in which the batch size is one. -The :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` method has an interface like :py:meth:`~uproot4.behaviors.TBranch.TBranch.arrays`, except that takes a ``step_size`` parameter and iterates over batches of that size, rather than returning a single array group. +The :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate` method has an interface like :py:meth:`~uproot.behaviors.TBranch.TBranch.arrays`, except that takes a ``step_size`` parameter and iterates over batches of that size, rather than returning a single array group. .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> for batch in events.iterate(step_size=500): ... print(repr(batch)) @@ -711,7 +711,7 @@ For this reason, it's better to set the ``step_size`` to a number of bytes, such -(but much larger in a real case). Here, ``"50 kB"`` corresponds to 667 entries (with the last step being the remainder). It's possible to calculate the number of entries for a given memory size outside of iteration using :py:meth:`~uproot4.behaviors.TBranch.HasBranches.num_entries_for`. +(but much larger in a real case). Here, ``"50 kB"`` corresponds to 667 entries (with the last step being the remainder). It's possible to calculate the number of entries for a given memory size outside of iteration using :py:meth:`~uproot.behaviors.TBranch.HasBranches.num_entries_for`. .. code-block:: python @@ -727,7 +727,7 @@ For this reason, it's better to set the ``step_size`` to a number of bytes, such The number of entries for ``"50 kB"`` depends strongly on which TBranches are being requested. It's the memory size, not the number of entries, that matters most when tuning a workflow for a computer with limited memory. -See the :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` documentation for more, including a ``report=True`` option to get a :py:class:`~uproot4.behaviors.TBranch.Report` with each batch of data with entry numbers for bookkeeping. +See the :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate` documentation for more, including a ``report=True`` option to get a :py:class:`~uproot.behaviors.TBranch.Report` with each batch of data with entry numbers for bookkeeping. .. code-block:: python @@ -739,7 +739,7 @@ See the :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` documentation Report(, 1334, 2001) Report(, 2001, 2304) -Just as ``library="np"`` and ``library="pd"`` can be used to get NumPy and Pandas output in :py:meth:`~uproot4.behaviors.TBranch.TBranch.array` and :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, it can be used to yield NumPy arrays and Pandas DataFrames iteratively: +Just as ``library="np"`` and ``library="pd"`` can be used to get NumPy and Pandas output in :py:meth:`~uproot.behaviors.TBranch.TBranch.array` and :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, it can be used to yield NumPy arrays and Pandas DataFrames iteratively: .. code-block:: python @@ -780,34 +780,34 @@ Iterating over many files Large datasets usually consist of many files, and abstractions like `ROOT's TChain `__ simplify multi-file workflows by making a collection of files look like a single file. -Uproot's :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` takes a step in the opposite direction: it breaks single-file access into batches, and designing a workflow around batches is like designing a workflow around files. To apply such an interface to many files, all that is needed is a way to express the list of files. +Uproot's :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate` takes a step in the opposite direction: it breaks single-file access into batches, and designing a workflow around batches is like designing a workflow around files. To apply such an interface to many files, all that is needed is a way to express the list of files. -The `uproot4.iterate `__ function (as opposed to the `HasBranches.iterate `__ method) takes a list of files as its first argument: +The `uproot.iterate `__ function (as opposed to the `HasBranches.iterate `__ method) takes a list of files as its first argument: .. code-block:: python - >>> for batch in uproot4.iterate(["dir1/*.root:events", "dir2/*.root:events"]): + >>> for batch in uproot.iterate(["dir1/*.root:events", "dir2/*.root:events"]): ... do_something... As with the single-file method, you'll want to restrict the set of TBranches to include only those you use. (See `Filtering TBranches <#filtering-tbranches>`__ above.) -The specification of file names has to include paths to the ``TTree`` objects (more generally, :py:class:`~uproot4.behaviors.TBranch.HasBranches` objects), so the colon (``:``) separating file path and object path `described above <#finding-objects-in-a-file>` is more than just a convenience in this case. Since it is possible for file paths to include colons as part of the file or directory name, the following alternate syntax can also be used: +The specification of file names has to include paths to the ``TTree`` objects (more generally, :py:class:`~uproot.behaviors.TBranch.HasBranches` objects), so the colon (``:``) separating file path and object path `described above <#finding-objects-in-a-file>` is more than just a convenience in this case. Since it is possible for file paths to include colons as part of the file or directory name, the following alternate syntax can also be used: .. code-block:: python - >>> for batch in uproot4.iterate([{"dir1/*.root": "events"}, {"dir2/*.root": "events"}]): + >>> for batch in uproot.iterate([{"dir1/*.root": "events"}, {"dir2/*.root": "events"}]): ... do_something... -If the ``step_size`` (same meaning as in previous section) is smaller than the file size, the last batch of each file will likely be smaller than the rest: batches from one file are not mixed with batches from another file. Thus, the largest meaningful ``step_size`` is the number of entries in the file (:py:attr:`~uproot4.behaviors.TBranch.HasBranches.num_entries`). See the next section for concatenating small files. +If the ``step_size`` (same meaning as in previous section) is smaller than the file size, the last batch of each file will likely be smaller than the rest: batches from one file are not mixed with batches from another file. Thus, the largest meaningful ``step_size`` is the number of entries in the file (:py:attr:`~uproot.behaviors.TBranch.HasBranches.num_entries`). See the next section for concatenating small files. -In multi-file iteration, the :py:class:`~uproot4.behaviors.TBranch.Report` returned by ``report=True`` distinguishes between global entry numbers (:py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_start` and :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_stop`), which start once at the beginning of iteration, and TTree entry numbers (:py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_start` and :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_stop`), which restart at the beginning of each TTree. The :py:attr:`~uproot4.behaviors.TBranch.Report.tree`, :py:attr:`~uproot4.behaviors.TBranch.Report.file`, and :py:attr:`~uproot4.behaviors.TBranch.Report.file_path` attributes are also more useful in multi-file iteration. +In multi-file iteration, the :py:class:`~uproot.behaviors.TBranch.Report` returned by ``report=True`` distinguishes between global entry numbers (:py:attr:`~uproot.behaviors.TBranch.Report.global_entry_start` and :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_stop`), which start once at the beginning of iteration, and TTree entry numbers (:py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_start` and :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_stop`), which restart at the beginning of each TTree. The :py:attr:`~uproot.behaviors.TBranch.Report.tree`, :py:attr:`~uproot.behaviors.TBranch.Report.file`, and :py:attr:`~uproot.behaviors.TBranch.Report.file_path` attributes are also more useful in multi-file iteration. Reading many files into big arrays ---------------------------------- -Although it iterates over multiple files, the `uproot4.iterate `__ function is not a direct analogy of `ROOT's TChain `__ because it does not make multi-file workflows look like single-file (non-iterating) workflows. +Although it iterates over multiple files, the `uproot.iterate `__ function is not a direct analogy of `ROOT's TChain `__ because it does not make multi-file workflows look like single-file (non-iterating) workflows. -The simplest way to access many files is to concatenate them into one array. The `uproot4.concatenate `__ function is a multi-file analogue of the `HasBranches.arrays `__ method, in that it returns a single array group. +The simplest way to access many files is to concatenate them into one array. The `uproot.concatenate `__ function is a multi-file analogue of the `HasBranches.arrays `__ method, in that it returns a single array group. .. code-block:: python @@ -822,14 +822,14 @@ The arrays of all files have been entirely read into memory. In general, this is If your computer has enough memory to do this, then it will likely be the fastest way to process the data, and it's certainly easier than accumulating partial results in a loop. However, if you're working on a small subsample that will be scaled up to a bigger analysis, then it would be a bad idea to develop your analysis with this interface. You would likely need to restructure it as a loop later. -(As a multi-file function, `uproot4.concatenate `__ specifies file paths and TTree object paths just like `uproot4.iterate `__.) +(As a multi-file function, `uproot.concatenate `__ specifies file paths and TTree object paths just like `uproot.iterate `__.) Reading on demand with lazy arrays ---------------------------------- -Lazy-loading is a third way to access multi-file datasets, like `uproot4.iterate `__ and `uproot4.concatenate `__ above. As such, it's a third analogy with `ROOT's TChain `__. +Lazy-loading is a third way to access multi-file datasets, like `uproot.iterate `__ and `uproot.concatenate `__ above. As such, it's a third analogy with `ROOT's TChain `__. -The interface to `uproot4.lazy `__ is like `uproot4.concatenate `__ in that it returns a single object, not an iterator that you have to iterate through, but it is like `uproot4.iterate `__ in that the data are not loaded immediately and do not need to reside in memory all at once. +The interface to `uproot.lazy `__ is like `uproot.concatenate `__ in that it returns a single object, not an iterator that you have to iterate through, but it is like `uproot.iterate `__ in that the data are not loaded immediately and do not need to reside in memory all at once. .. code-block:: python @@ -837,7 +837,7 @@ The interface to `uproot4.lazy `__ is like >>> array -When `uproot4.lazy `__ is called, it opens all of the specified files and TTree metadata, but none of the TBranch data. It uses the TBranch names and types, as well as the TTree :py:attr:`~uproot4.behaviors.TTree.TTree.num_entries`, to define the data type and prepare batches for reading. Only when you access items in the array, such as printing them to the screen or performing a calculation on them, are the relevant TBranches read (in batches). +When `uproot.lazy `__ is called, it opens all of the specified files and TTree metadata, but none of the TBranch data. It uses the TBranch names and types, as well as the TTree :py:attr:`~uproot.behaviors.TTree.TTree.num_entries`, to define the data type and prepare batches for reading. Only when you access items in the array, such as printing them to the screen or performing a calculation on them, are the relevant TBranches read (in batches). This lazy-loading uses an Awkward Array feature, so ``library="ak"`` is the only library option. @@ -845,7 +845,7 @@ The fact that the data are being loaded on demand is (intentionally) hidden; one .. code-block:: python - >>> array = uproot4.lazy("https://scikit-hep.org/uproot3/examples/Zmumu.root:events", + >>> array = uproot.lazy("https://scikit-hep.org/uproot3/examples/Zmumu.root:events", ... step_size=100) >>> array.cache @@ -896,7 +896,7 @@ Performing a calculation on these two fields, ``array.px1`` and ``array.py1``, l >>> array.cache -Although lazy arrays combine the convenience of `uproot4.concatenate `__ with the gradual loading of `uproot4.iterate `__, it is not always the most efficient way to process data. Derived quantities are fully resident in memory, and most data analyses compute more quantities than they read. +Although lazy arrays combine the convenience of `uproot.concatenate `__ with the gradual loading of `uproot.iterate `__, it is not always the most efficient way to process data. Derived quantities are fully resident in memory, and most data analyses compute more quantities than they read. Moreover, if a lazy array is larger than its cache, reading the last batches will cause the first batches to be evicted from the cache. If it is accessed again, the first batches will need to be fully re-read, which evicts the last batches, guaranteeing that data will never be found in the cache when it's needed. @@ -909,11 +909,11 @@ For example, in a calculation like this: if the three TBranches ``px1``, ``py1``, ``pz1`` don't entirely fit into their shared cache or individual caches, then none of the data loaded while computing ``p`` will be available to compute ``pt``. Small enough caches can guarantee file re-reading, which would be the slowest step in simple calculations like the above. -On the other hand, if you make the cache(s) large enough to accommodate all the arrays you'll be loading, then you might as well load them entirely into memory (with `uproot4.concatenate `__). Avoiding the overhead of managing lazy batch-loading can only streamline a workflow. +On the other hand, if you make the cache(s) large enough to accommodate all the arrays you'll be loading, then you might as well load them entirely into memory (with `uproot.concatenate `__). Avoiding the overhead of managing lazy batch-loading can only streamline a workflow. So when are lazy arrays useful? -Lazy arrays are especially useful for exploring a large dataset in a convenient way. If you don't know which TBranches you will be looking at, lazy arrays save you the upfront cost of reading them all, if that were even possible. You can perform calculations interactively without having to set up iterative loops, developing the pieces of a data analysis that will later be incorporated into an efficient loop based on `uproot4.iterate `__. +Lazy arrays are especially useful for exploring a large dataset in a convenient way. If you don't know which TBranches you will be looking at, lazy arrays save you the upfront cost of reading them all, if that were even possible. You can perform calculations interactively without having to set up iterative loops, developing the pieces of a data analysis that will later be incorporated into an efficient loop based on `uproot.iterate `__. Caching and memory management ----------------------------- @@ -924,7 +924,7 @@ The ``object_cache`` stores a number of objects like TDirectories, histograms, a .. code-block:: python - >>> file = uproot4.open("https://scikit-hep.org/uproot3/examples/hepdata-example.root") + >>> file = uproot.open("https://scikit-hep.org/uproot3/examples/hepdata-example.root") >>> histogram = file["hpx"] >>> (histogram, histogram) (, ) @@ -942,7 +942,7 @@ The ``array_cache`` stores array outputs up to a maximum number of bytes. The ar .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> array = events["px1"].array() >>> (array, array) (, @@ -958,7 +958,7 @@ and have the same performance, assuming that the caches are not overrun. -By default, each file has a separate cache of ``100`` objects and ``"100 MB"`` of arrays. However, these can be overridden by passing an ``object_cache`` or ``array_cache`` argument to `uproot4.open `__ or setting the :py:attr:`~uproot4.reading.ReadOnlyFile.object_cache` and :py:attr:`~uproot4.reading.ReadOnlyFile.array_cache` properties. +By default, each file has a separate cache of ``100`` objects and ``"100 MB"`` of arrays. However, these can be overridden by passing an ``object_cache`` or ``array_cache`` argument to `uproot.open `__ or setting the :py:attr:`~uproot.reading.ReadOnlyFile.object_cache` and :py:attr:`~uproot.reading.ReadOnlyFile.array_cache` properties. Any `MutableMapping `__ will do (including a plain dict, which would keep objects forever), or you can set them to ``None`` to prevent caching. @@ -967,10 +967,10 @@ Parallel processing Data are or can be read in parallel in each of the following three stages. -- Physically reading bytes from disk or remote sources: the parallel processing or single-thread background processing is handled by the specific :py:class:`~uproot4.source.chunk.Source` type, which can be influenced with `uproot4.open `__ options (particularly ``num_workers`` and ``num_fallback_workers``). -- Decompressing TBasket (:py:class:`~uproot4.models.TBasket.Model_TBasket`) data: depends on the ``decompression_executor``. -- Interpreting decompressed data with an array :py:class:`~uproot4.interpretation.Interpretation`: depends on the ``interpretation_executor``. +- Physically reading bytes from disk or remote sources: the parallel processing or single-thread background processing is handled by the specific :py:class:`~uproot.source.chunk.Source` type, which can be influenced with `uproot.open `__ options (particularly ``num_workers`` and ``num_fallback_workers``). +- Decompressing TBasket (:py:class:`~uproot.models.TBasket.Model_TBasket`) data: depends on the ``decompression_executor``. +- Interpreting decompressed data with an array :py:class:`~uproot.interpretation.Interpretation`: depends on the ``interpretation_executor``. -Like the caches, the default values for the last two are global ``uproot4.decompression_executor`` and ``uproot4.interpretation_executor`` objects. The default ``decompression_executor`` is a :py:class:`~uproot4..source.futures.ThreadPoolExecutor` with as many workers as your computer has CPU cores. Decompression workloads are executed in compiled extensions with the `Python GIL `__ released, so they can afford to run with full parallelism. The default ``interpretation_executor`` is a :py:class:`~uproot4.source.futures.TrivialExecutor` that behaves like an distributed executor, but actually runs sequentially. Most interpretation workflows are not computationally intensive or are currently implemented in Python, so they would not currently benefit from parallelism. +Like the caches, the default values for the last two are global ``uproot.decompression_executor`` and ``uproot.interpretation_executor`` objects. The default ``decompression_executor`` is a :py:class:`~uproot..source.futures.ThreadPoolExecutor` with as many workers as your computer has CPU cores. Decompression workloads are executed in compiled extensions with the `Python GIL `__ released, so they can afford to run with full parallelism. The default ``interpretation_executor`` is a :py:class:`~uproot.source.futures.TrivialExecutor` that behaves like an distributed executor, but actually runs sequentially. Most interpretation workflows are not computationally intensive or are currently implemented in Python, so they would not currently benefit from parallelism. If, however, you're working in an environment that puts limits on parallel processing (e.g. the CMS LPC or informal university computers), you may want to modify the defaults, either locally through a ``decompression_executor`` or ``interpretation_executor`` function parameter, or globally by replacing the global object. diff --git a/docs-sphinx/index.rst b/docs-sphinx/index.rst index f54e5b8f5..5f2128af6 100644 --- a/docs-sphinx/index.rst +++ b/docs-sphinx/index.rst @@ -5,43 +5,41 @@ basic uproot3-to-4 -.. include:: uproot4.toctree +.. include:: uproot.toctree -.. include:: uproot4.reading.toctree +.. include:: uproot.reading.toctree -.. include:: uproot4.behaviors.toctree +.. include:: uproot.behaviors.toctree -.. include:: uproot4.model.toctree +.. include:: uproot.model.toctree -.. include:: uproot4.streamers.toctree +.. include:: uproot.streamers.toctree -.. include:: uproot4.cache.toctree +.. include:: uproot.cache.toctree -.. include:: uproot4.compression.toctree +.. include:: uproot.compression.toctree -.. include:: uproot4.deserialization.toctree +.. include:: uproot.deserialization.toctree -.. include:: uproot4.source.toctree +.. include:: uproot.source.toctree -.. include:: uproot4.interpretation.toctree +.. include:: uproot.interpretation.toctree -.. include:: uproot4.containers.toctree +.. include:: uproot.containers.toctree -.. include:: uproot4.language.toctree +.. include:: uproot.language.toctree -.. include:: uproot4.models.toctree +.. include:: uproot.models.toctree -.. include:: uproot4.const.toctree +.. include:: uproot.const.toctree -.. include:: uproot4.extras.toctree +.. include:: uproot.exceptions.toctree -.. include:: uproot4.version.toctree +.. include:: uproot.extras.toctree .. toctree:: :hidden: - uproot4.dynamic - .. |br| raw:: html
@@ -59,13 +57,13 @@ Usually, you'll want to install Uproot with `Awkward Array `__ and `CuPy `__, which, like Awkward, would need to be explicitly installed. diff --git a/docs-sphinx/make_changelog.py b/docs-sphinx/make_changelog.py index f3b47a289..c404c991b 100644 --- a/docs-sphinx/make_changelog.py +++ b/docs-sphinx/make_changelog.py @@ -1,4 +1,4 @@ -# # BSD 3-Clause License; see https://github.com/jpivarski/awkward-1.0/blob/master/LICENSE +# # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE # import math # import json diff --git a/docs-sphinx/prepare_docstrings.py b/docs-sphinx/prepare_docstrings.py index 8a9fa95ab..50ac529f0 100644 --- a/docs-sphinx/prepare_docstrings.py +++ b/docs-sphinx/prepare_docstrings.py @@ -8,25 +8,25 @@ order = [ - "uproot4", - "uproot4.reading", - "uproot4.behaviors", - "uproot4.model", - "uproot4.streamers", - "uproot4.cache", - "uproot4.compression", - "uproot4.deserialization", - "uproot4.source", - "uproot4.interpretation", - "uproot4.containers", - "uproot4.language", - "uproot4.models", - "uproot4.const", - "uproot4.extras", - "uproot4.version", + "uproot", + "uproot.reading", + "uproot.behaviors", + "uproot.model", + "uproot.streamers", + "uproot.cache", + "uproot.compression", + "uproot.deserialization", + "uproot.source", + "uproot.interpretation", + "uproot.containers", + "uproot.language", + "uproot.models", + "uproot.const", + "uproot.exceptions", + "uproot.extras", ] -toctree = open("uproot4.toctree", "w") +toctree = open("uproot.toctree", "w") toctree.write( """.. toctree:: :caption: Reference @@ -58,7 +58,7 @@ def handle_module(modulename, module): ensure(modulename, modulename + ".rst", content) toctree.write(" " + modulename + "\n") - if modulename != "uproot4" and all( + if modulename != "uproot" and all( not x.startswith("_") for x in modulename.split(".") ): @@ -90,14 +90,14 @@ def line_order(obj): methods = {} mro = list(cls.__mro__) - import uproot4 - if hasattr(uproot4, cls.__name__): - title = "uproot4." + cls.__name__ + import uproot + if hasattr(uproot, cls.__name__): + title = "uproot." + cls.__name__ else: title = classname for index, basecls in enumerate(mro): - if basecls.__module__.startswith("uproot4."): + if basecls.__module__.startswith("uproot."): def good(obj): if inspect.ismethod(obj) or inspect.isfunction(obj): @@ -106,7 +106,7 @@ def good(obj): module, name = obj.fget.__module__, obj.fget.__name__ else: module, name = "", "" - if module.startswith("uproot4."): + if module.startswith("uproot."): if index + 1 >= len(mro) or obj is not getattr( mro[index + 1], name, None ): @@ -135,7 +135,7 @@ def good(obj): def prettymro(c): fullname = c.__module__ + "." + c.__name__ - if c.__module__.startswith("uproot4."): + if c.__module__.startswith("uproot."): return "#. :doc:`" + fullname + "`" else: return "#. ``" + fullname + "``" @@ -161,9 +161,9 @@ def prettymro(c): def handle_function(functionname, cls): - import uproot4 - if hasattr(uproot4, cls.__name__): - title = "uproot4." + cls.__name__ + import uproot + if hasattr(uproot, cls.__name__): + title = "uproot." + cls.__name__ else: title = functionname @@ -179,7 +179,7 @@ def handle_function(functionname, cls): for modulename in order: module = importlib.import_module(modulename) - if modulename != "uproot4": + if modulename != "uproot": toctree = open(modulename + ".toctree", "w") toctree.write( """.. toctree:: @@ -189,7 +189,7 @@ def handle_function(functionname, cls): ) handle_module(modulename, module) - if module.__file__.endswith("__init__.py") and modulename != "uproot4": + if module.__file__.endswith("__init__.py") and modulename != "uproot": for submodulename in sorted( [ modulename + "." + name diff --git a/docs-sphinx/requirements.txt b/docs-sphinx/requirements.txt index dcbd81cbe..095fa406e 100644 --- a/docs-sphinx/requirements.txt +++ b/docs-sphinx/requirements.txt @@ -1,2 +1,2 @@ sphinx>=2.4.4 -uproot4 +uproot diff --git a/docs-sphinx/uproot3-to-4.rst b/docs-sphinx/uproot3-to-4.rst index 448f1e50d..74b281e13 100644 --- a/docs-sphinx/uproot3-to-4.rst +++ b/docs-sphinx/uproot3-to-4.rst @@ -5,7 +5,7 @@ The Uproot 3 → 4 transition was primarily motivated by Awkward Array 0 → 1. Thus, it was also a good time to introduce interface changes to Uproot itself—such as presenting C++ strings as Python 3 ``str``, rather than uninterpreted ``bytes``. -Fundamental changes were also required to streamline remote reading (HTTP and XRootD), so Uproot 4 was distributed as a separate project in parallel with Uproot 3 (like Awkward 1 and 0). For the latter half of 2020, adventurous users and downstream developers could install `uproot4 `__ as a separate project. +Fundamental changes were also required to streamline remote reading (HTTP and XRootD), so Uproot 4 was distributed as a separate project in parallel with Uproot 3 (like Awkward 1 and 0). For the latter half of 2020, adventurous users and downstream developers could install `uproot `__ as a separate project. .. image:: https://raw.githubusercontent.com/scikit-hep/uproot4/jpivarski/write-cheat-sheet/docs-img/diagrams/uproot-awkward-timeline.png :width: 100% @@ -17,32 +17,32 @@ This document is to help users of Uproot 3 get started on Uproot 4. Opening a file -------------- -The "open" function is still named :func:`uproot4.open `, and it still recognizes local files, HTTP, and XRootD by the URL prefix (or lack thereof). +The "open" function is still named :func:`uproot.open `, and it still recognizes local files, HTTP, and XRootD by the URL prefix (or lack thereof). .. code-block:: python - >>> import uproot4 - >>> local_file = uproot4.open("local/file.root") - >>> http_file = uproot4.open("https://server.net/file.root") - >>> xrootd_file = uproot4.open("root://server.net/file.root") + >>> import uproot + >>> local_file = uproot.open("local/file.root") + >>> http_file = uproot.open("https://server.net/file.root") + >>> xrootd_file = uproot.open("root://server.net/file.root") But whereas Uproot 3 took a handler (local/HTTP/XRootD) and options as a class instance, handlers are specified in Uproot 4 by passing a class and options are free-standing arguments. .. code-block:: python - >>> file = uproot4.open("file.root", - ... file_handler=uproot4.MultithreadedFileSource, + >>> file = uproot.open("file.root", + ... file_handler=uproot.MultithreadedFileSource, ... num_workers=10) - >>> file = uproot4.open("https://server.net/file.root", - ... http_handler=uproot4.MultithreadedHTTPSource, + >>> file = uproot.open("https://server.net/file.root", + ... http_handler=uproot.MultithreadedHTTPSource, ... timeout=3.0) - >>> file = uproot4.open("root://server.net/file.root", - ... xrootd_handler=uproot4.MultithreadedXRootDSource, + >>> file = uproot.open("root://server.net/file.root", + ... xrootd_handler=uproot.MultithreadedXRootDSource, ... num_workers=5) -As in Uproot 3, there is a function for iterating over many files, :func:`uproot4.iterate `, and for lazily opening files, :func:`uproot4.lazy ` (replacing ``uproot3.lazyarray`` and ``uproot3.lazyarrays``). Uproot 4 has an additional function for reading many files into one array (not lazily): :func:`uproot4.concatenate `. +As in Uproot 3, there is a function for iterating over many files, :func:`uproot.iterate `, and for lazily opening files, :func:`uproot.lazy ` (replacing ``uproot3.lazyarray`` and ``uproot3.lazyarrays``). Uproot 4 has an additional function for reading many files into one array (not lazily): :func:`uproot.concatenate `. -Array-reading differences are covered in `Reading arrays <#reading-arrays>`__, below. File-opening differences are illustrated well enough with :func:`uproot4.open `. +Array-reading differences are covered in `Reading arrays <#reading-arrays>`__, below. File-opening differences are illustrated well enough with :func:`uproot.open `. New features """""""""""" @@ -51,30 +51,30 @@ Files can now truly be closed (long story), so the ``with`` syntax is recommende .. code-block:: python - >>> with uproot4.open("file.root") as file: + >>> with uproot.open("file.root") as file: ... do_something(file) -Python file objects can be passed to :func:`uproot4.open ` in place of a filename string. +Python file objects can be passed to :func:`uproot.open ` in place of a filename string. .. code-block:: python >>> import tarfile >>> with tarfile.open("file.tar.gz", "r") as tar: - ... with uproot4.open(tar) as file: + ... with uproot.open(tar) as file: ... do_something(file) There's a filename syntax for opening a file and pulling one object out of it. This is primarily for convenience but was strongly requested (`#79 `__). .. code-block:: python - >>> histogram = uproot4.open("file.root:path/to/histogram") + >>> histogram = uproot.open("file.root:path/to/histogram") So what if the filename has a colon (``:``) in it? (Note: URLs are properly handled.) You have two options: (1) ``pathlib.Path`` objects are never parsed for the colon separator and (2) you can also express the separation with a dict. .. code-block:: python - >>> histogram = uproot4.open(pathlib.Path("real:colon.root"))["histogram"] - >>> histogram = uproot4.open({"real:colon.root": "histogram"}) + >>> histogram = uproot.open(pathlib.Path("real:colon.root"))["histogram"] + >>> histogram = uproot.open({"real:colon.root": "histogram"}) Error messages about missing files will remind you of the options. @@ -82,10 +82,10 @@ If you want to use this with a context manager (``with`` statement), closing the .. code-block:: python - >>> with uproot4.open("file.root:events") as tree: + >>> with uproot.open("file.root:events") as tree: ... do_something(tree) ... - >>> with uproot4.open("file.root")["events"] as tree: + >>> with uproot.open("file.root")["events"] as tree: ... do_something(tree) Caches in Uproot 3 were strictly opt-in, but Uproot 4 provides a default: ``object_cache`` for extracted objects (histograms, TTrees) and ``array_cache`` for TTree data as arrays. @@ -93,9 +93,9 @@ Caches in Uproot 3 were strictly opt-in, but Uproot 4 provides a default: ``obje Removed features """""""""""""""" -Uproot 4 does not have functions for specialized protocols like ``uproot3.http`` and ``uproot4.xrootd``. Pass URLs with the appropriate scheme to the :func:`uproot4.open ` function. +Uproot 4 does not have functions for specialized protocols like ``uproot3.http`` and ``uproot.xrootd``. Pass URLs with the appropriate scheme to the :func:`uproot.open ` function. -Uproot 4 does not have specialized functions for reading data into Pandas DataFrames, like ``uproot3.pandas.iterate``. Use the normal :func:`uproot4.iterate ` and :meth:`~uproot4.behaviors.TBranch.TBranch.array`, :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, and :meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` functions with ``library="pd"`` to select Pandas as an output container. +Uproot 4 does not have specialized functions for reading data into Pandas DataFrames, like ``uproot3.pandas.iterate``. Use the normal :func:`uproot.iterate ` and :meth:`~uproot.behaviors.TBranch.TBranch.array`, :meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, and :meth:`~uproot.behaviors.TBranch.HasBranches.iterate` functions with ``library="pd"`` to select Pandas as an output container. Not yet implemented features """""""""""""""""""""""""""" @@ -109,22 +109,22 @@ Internal differences * Remote sources are now read in exact byte ranges (Uproot 3 rounded to equal-sized chunks). -* All the byte ranges associated with a single call to :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` are batched in a single request (HTTP multi-part GET or XRootD vector-read) to minimize the latency of requests. +* All the byte ranges associated with a single call to :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` are batched in a single request (HTTP multi-part GET or XRootD vector-read) to minimize the latency of requests. Navigating a file ----------------- -Whereas Uproot 3 merged the functions of "file" and "directory," Uproot 4 has two distinct types: :class:`~uproot4.reading.ReadOnlyFile` and :class:`~uproot4.reading.ReadOnlyDirectory`. The :func:`uproot4.open ` function returns a :class:`~uproot4.reading.ReadOnlyDirectory`, which is used to look up objects. +Whereas Uproot 3 merged the functions of "file" and "directory," Uproot 4 has two distinct types: :class:`~uproot.reading.ReadOnlyFile` and :class:`~uproot.reading.ReadOnlyDirectory`. The :func:`uproot.open ` function returns a :class:`~uproot.reading.ReadOnlyDirectory`, which is used to look up objects. .. code-block:: python - >>> directory = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") + >>> directory = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") >>> directory >>> directory["one/two/tree"] -The :class:`~uproot4.reading.ReadOnlyFile`, on the other hand, is responsible for the physical :class:`~uproot4.source.chunk.Source`, the ROOT file headers, streamers (``TStreamerInfo``), and therefore class definitions. +The :class:`~uproot.reading.ReadOnlyFile`, on the other hand, is responsible for the physical :class:`~uproot.source.chunk.Source`, the ROOT file headers, streamers (``TStreamerInfo``), and therefore class definitions. .. code-block:: python @@ -149,13 +149,13 @@ The :class:`~uproot4.reading.ReadOnlyFile`, on the other hand, is responsible fo TList (v5): TSeqCollection (v0) >>> directory.file.class_named("TTree") - + -Like Uproot 3, :class:`~uproot4.reading.ReadOnlyDirectory` presents (and can accept) cycle numbers after a semicolon (``;``) and interprets slash (``/``) as a directory separator. Unlike Uproot 3, keys are presented as Python 3 ``str``, not ``bytes``, and the directory separator can extract a TTree's branches. +Like Uproot 3, :class:`~uproot.reading.ReadOnlyDirectory` presents (and can accept) cycle numbers after a semicolon (``;``) and interprets slash (``/``) as a directory separator. Unlike Uproot 3, keys are presented as Python 3 ``str``, not ``bytes``, and the directory separator can extract a TTree's branches. .. code-block:: python - >>> directory = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") + >>> directory = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") >>> directory >>> directory.keys() @@ -173,19 +173,19 @@ Like Uproot 3, :class:`~uproot4.reading.ReadOnlyDirectory` presents (and can acc >>> directory["three/tree/evt/I32"] -In Uproot 3, directories could often be duck-typed as a mapping, but in Uproot 4, :class:`~uproot4.reading.ReadOnlyDirectory` formally satisfies the ``Mapping`` protocol. As in Uproot 3, the :meth:`~uproot4.reading.ReadOnlyDirectory.keys`, :meth:`~uproot4.reading.ReadOnlyDirectory.values`, and :meth:`~uproot4.reading.ReadOnlyDirectory.items` take options, but some defaults have changed: +In Uproot 3, directories could often be duck-typed as a mapping, but in Uproot 4, :class:`~uproot.reading.ReadOnlyDirectory` formally satisfies the ``Mapping`` protocol. As in Uproot 3, the :meth:`~uproot.reading.ReadOnlyDirectory.keys`, :meth:`~uproot.reading.ReadOnlyDirectory.values`, and :meth:`~uproot.reading.ReadOnlyDirectory.items` take options, but some defaults have changed: * ``recursive=True`` is the new default (directories are recursively searched). There are no ``allkeys``, ``allvalues``, ``allitems`` methods for recursion. * ``filter_name=None`` can be None, a string, a glob string, a regex in ``"/pattern/i"`` syntax, a function of str → bool, or an iterable of the above. * ``filter_classname=None`` has the same options. -The ``filter_name`` and ``filter_classname`` mechanism is now uniform for :class:`~uproot4.reading.ReadOnlyDirectory` and TTrees (:class:`~uproot4.behaviors.TBranch.HasBranches`), though the latter is named ``filter_typename`` for TTrees. +The ``filter_name`` and ``filter_classname`` mechanism is now uniform for :class:`~uproot.reading.ReadOnlyDirectory` and TTrees (:class:`~uproot.behaviors.TBranch.HasBranches`), though the latter is named ``filter_typename`` for TTrees. -Uproot 3's ``ROOTDirectory.classes`` and ``ROOTDirectory.allclasses``, which returned a list of 2-tuples of name, class object pairs, has become :meth:`~uproot4.reading.ReadOnlyDirectory.classnames` in Uproot 4, which returns a dict mapping names to C++ class names. +Uproot 3's ``ROOTDirectory.classes`` and ``ROOTDirectory.allclasses``, which returned a list of 2-tuples of name, class object pairs, has become :meth:`~uproot.reading.ReadOnlyDirectory.classnames` in Uproot 4, which returns a dict mapping names to C++ class names. .. code-block:: python - >>> directory = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") + >>> directory = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") >>> directory.classnames() {'one': 'TDirectory', 'one/two': 'TDirectory', @@ -194,28 +194,28 @@ Uproot 3's ``ROOTDirectory.classes`` and ``ROOTDirectory.allclasses``, which ret 'three': 'TDirectory', 'three/tree': 'TTree'} -This :meth:`~uproot4.reading.ReadOnlyDirectory.classnames` method has the same options as :meth:`~uproot4.reading.ReadOnlyDirectory.keys`, :meth:`~uproot4.reading.ReadOnlyDirectory.values`, and :meth:`~uproot4.reading.ReadOnlyDirectory.items`, but like :meth:`~uproot4.reading.ReadOnlyDirectory.keys` (only), it doesn't initiate any data-reading. +This :meth:`~uproot.reading.ReadOnlyDirectory.classnames` method has the same options as :meth:`~uproot.reading.ReadOnlyDirectory.keys`, :meth:`~uproot.reading.ReadOnlyDirectory.values`, and :meth:`~uproot.reading.ReadOnlyDirectory.items`, but like :meth:`~uproot.reading.ReadOnlyDirectory.keys` (only), it doesn't initiate any data-reading. -To get the class object, use the :class:`~uproot4.reading.ReadOnlyFile` or :meth:`~uproot4.reading.ReadOnlyDirectory.class_of`. +To get the class object, use the :class:`~uproot.reading.ReadOnlyFile` or :meth:`~uproot.reading.ReadOnlyDirectory.class_of`. .. code-block:: python - >>> directory = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") + >>> directory = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root") >>> directory.file.class_named("TTree") - + >>> directory.class_of("one/two/tree") - + In Uproot 4, requesting a class object *might* cause the file to read streamers (``TStreamerInfo``). Examining TTrees ---------------- -As in Uproot 3, TTrees have a :meth:`~uproot4.behaviors.TBranch.HasBranches.show` method. +As in Uproot 3, TTrees have a :meth:`~uproot.behaviors.TBranch.HasBranches.show` method. .. code-block:: python - >>> tree = uproot4.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root:three/tree") + >>> tree = uproot.open("https://scikit-hep.org/uproot3/examples/nesteddirs.root:three/tree") >>> tree.show() name | typename | interpretation ---------------------+--------------------------+------------------------------- @@ -263,7 +263,7 @@ As in Uproot 3, TTrees have a :meth:`~uproot4.behaviors.TBranch.HasBranches.show evt/StlVecStr | std::vector | AsObjects(AsVector(True, As... evt/End | TString | AsStrings() -However, this and other TTree-like behaviors are defined on a :class:`~uproot4.behaviors.TBranch.HasBranches` class, which encompasses both :class:`~uproot4.behaviors.TTree.TTree` and :class:`~uproot4.behaviors.TBranch.TBranch`. This :meth:`~uproot4.behaviors.TBranch.HasBranches` satisfies the ``Mapping`` protocol, and so do any nested branches: +However, this and other TTree-like behaviors are defined on a :class:`~uproot.behaviors.TBranch.HasBranches` class, which encompasses both :class:`~uproot.behaviors.TTree.TTree` and :class:`~uproot.behaviors.TBranch.TBranch`. This :meth:`~uproot.behaviors.TBranch.HasBranches` satisfies the ``Mapping`` protocol, and so do any nested branches: .. code-block:: python @@ -272,30 +272,30 @@ However, this and other TTree-like behaviors are defined on a :class:`~uproot4.b >>> tree["evt"].keys() ['Beg', 'I16', 'I32', 'I64', ..., 'End'] -In addition to an :class:`~uproot4.interpretation.Interpretation`, each :class:`~uproot4.behaviors.TBranch.TBranch` also has a C++ :meth:`~uproot4.behaviors.TBranch.TBranch.typename`, as shown above. Uproot 4 has a typename parser, and is able to interpret more types, including nested STL containers. +In addition to an :class:`~uproot.interpretation.Interpretation`, each :class:`~uproot.behaviors.TBranch.TBranch` also has a C++ :meth:`~uproot.behaviors.TBranch.TBranch.typename`, as shown above. Uproot 4 has a typename parser, and is able to interpret more types, including nested STL containers. -In addition to the standard ``Mapping`` methods, :meth:`~uproot4.behaviors.TBranch.HasBranches.keys`, :meth:`~uproot4.behaviors.TBranch.HasBranches.values`, and :meth:`~uproot4.behaviors.TBranch.HasBranches.items`, :class:`~uproot4.behaviors.TBranch.HasBranches` has a :meth:`~uproot4.behaviors.TBranch.HasBranches.typenames` that returns str → str of branch names to their types. They have the same arguments: +In addition to the standard ``Mapping`` methods, :meth:`~uproot.behaviors.TBranch.HasBranches.keys`, :meth:`~uproot.behaviors.TBranch.HasBranches.values`, and :meth:`~uproot.behaviors.TBranch.HasBranches.items`, :class:`~uproot.behaviors.TBranch.HasBranches` has a :meth:`~uproot.behaviors.TBranch.HasBranches.typenames` that returns str → str of branch names to their types. They have the same arguments: * ``recursive=True`` is the new default (directories are recursively searched). There are no ``allkeys``, ``allvalues``, ``allitems`` methods for recursion. * ``filter_name=None`` can be None, a string, a glob string, a regex in ``"/pattern/i"`` syntax, a function of str → bool, or an iterable of the above. * ``filter_typename`` with the same options. -* ``filter_branch``, which can be None, :class:`~uproot4.behaviors.TBranch.TBranch` → bool, :class:`~uproot4.interpretation.Interpretation`, or None, to select by branch data. +* ``filter_branch``, which can be None, :class:`~uproot.behaviors.TBranch.TBranch` → bool, :class:`~uproot.interpretation.Interpretation`, or None, to select by branch data. Reading arrays -------------- -TTrees in Uproot 3 have ``array`` and ``arrays`` methods, which differ in how the resulting arrays are returned. In Uproot 4, :meth:`~uproot4.behaviors.TBranch.TBranch.array` and :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` have more differences: +TTrees in Uproot 3 have ``array`` and ``arrays`` methods, which differ in how the resulting arrays are returned. In Uproot 4, :meth:`~uproot.behaviors.TBranch.TBranch.array` and :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` have more differences: -* :meth:`~uproot4.behaviors.TBranch.TBranch.array` is a :class:`~uproot4.behaviors.TBranch.TBranch` method, but :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` is a :class:`~uproot4.behaviors.TBranch.HasBranches` method (which, admittedly, can overlap on a branch that has branches). -* :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` can take a set of computable ``expressions`` and a ``cut``, but :meth:`~uproot4.behaviors.TBranch.TBranch.array` never involves computation. The ``aliases`` and ``language`` arguments are also related to computation. -* Only :meth:`~uproot4.behaviors.TBranch.TBranch.array` can override the default :class:`~uproot4.interpretation.Interpretation` (it is the more low-level method). -* :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` has the same ``filter_name``, ``filter_typename``, ``filter_branch`` as :meth:`~uproot4.behaviors.TBranch.HasBranches.keys`. Since the ``expressions`` are now computable and glob wildcards (``*``) would be interpreted as multiplication, ``filter_name`` is the best way to select branches to read via a naming convention. +* :meth:`~uproot.behaviors.TBranch.TBranch.array` is a :class:`~uproot.behaviors.TBranch.TBranch` method, but :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` is a :class:`~uproot.behaviors.TBranch.HasBranches` method (which, admittedly, can overlap on a branch that has branches). +* :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` can take a set of computable ``expressions`` and a ``cut``, but :meth:`~uproot.behaviors.TBranch.TBranch.array` never involves computation. The ``aliases`` and ``language`` arguments are also related to computation. +* Only :meth:`~uproot.behaviors.TBranch.TBranch.array` can override the default :class:`~uproot.interpretation.Interpretation` (it is the more low-level method). +* :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` has the same ``filter_name``, ``filter_typename``, ``filter_branch`` as :meth:`~uproot.behaviors.TBranch.HasBranches.keys`. Since the ``expressions`` are now computable and glob wildcards (``*``) would be interpreted as multiplication, ``filter_name`` is the best way to select branches to read via a naming convention. Some examples of simple reading and computing expressions: .. code-block:: python - >>> events = uproot4.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") + >>> events = uproot.open("https://scikit-hep.org/uproot3/examples/Zmumu.root:events") >>> events["px1"].array() @@ -340,7 +340,7 @@ In Uproot 3, you could specify whether the output is a dict of arrays, a tuple o (Uproot 3 chooses between NumPy and Awkward Array based on the type of the data. Since NumPy arrays and Awkward Arrays have different methods and properties, it's safer to write scripts with a deterministic output type.) -**Note:** Awkward Array is not one of Uproot 4's formal requirements. If you don't have ``awkward1`` installed, :meth:`~uproot4.behaviors.TBranch.TBranch.array` and :meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` will raise errors explaining how to install Awkward Array or switch to ``library="np"``. These errors might be hidden in automated testing, so be careful if you use that! +**Note:** Awkward Array is not one of Uproot 4's formal requirements. If you don't have ``awkward`` installed, :meth:`~uproot.behaviors.TBranch.TBranch.array` and :meth:`~uproot.behaviors.TBranch.HasBranches.arrays` will raise errors explaining how to install Awkward Array or switch to ``library="np"``. These errors might be hidden in automated testing, so be careful if you use that! The ``how`` argument can be used to repackage arrays into dicts or tuples, and has special meanings for some libraries. diff --git a/requirements-dev.txt b/requirements-dev.txt index 7b47204ba..c0c3ddab2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ pandas -awkward1 +awkward>=1.0.0rc1 boost_histogram hist diff --git a/setup.cfg b/setup.cfg index 33917df10..999fe58ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [flake8] ignore = E203, W503, E501, E266, N max-complexity = 100 -exclude = tests, setup.py, uproot4/__init__.py +exclude = tests, setup.py, uproot/__init__.py [tool:pytest] markers = diff --git a/setup.py b/setup.py index 71699884e..f1d70231a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def get_version(): g = {} - exec(open(os.path.join("uproot4", "version.py")).read(), g) + exec(open(os.path.join("uproot", "version.py")).read(), g) return g["__version__"] @@ -19,7 +19,7 @@ def get_version(): install_requires = open("requirements.txt").read().strip().split("\n") -setup(name = "uproot4", +setup(name = "uproot", packages = find_packages(exclude = ["tests"]), scripts = [], version = get_version(), diff --git a/tests/test_0001-source-class.py b/tests/test_0001-source-class.py index dbb801317..6f0042f6c 100644 --- a/tests/test_0001-source-class.py +++ b/tests/test_0001-source-class.py @@ -17,13 +17,7 @@ import numpy import pytest -import uproot4 -import uproot4.source.futures -import uproot4.source.cursor -import uproot4.source.chunk -import uproot4.source.file -import uproot4.source.http -import uproot4.source.xrootd +import uproot def tobytes(x): @@ -40,7 +34,7 @@ def test_file(tmpdir): tmp.write(b"****** ...+++++++!!!!!@@@@@") for num_workers in [1, 2]: - source = uproot4.source.file.MultithreadedFileSource( + source = uproot.source.file.MultithreadedFileSource( filename, num_workers=num_workers ) with source as tmp: @@ -69,7 +63,7 @@ def test_file_fail(tmpdir): for num_workers in [1, 2]: with pytest.raises(Exception): - uproot4.source.file.MultithreadedFileSource( + uproot.source.file.MultithreadedFileSource( filename + "-does-not-exist", num_workers=num_workers ) @@ -80,7 +74,7 @@ def test_memmap(tmpdir): with open(filename, "wb") as tmp: tmp.write(b"****** ...+++++++!!!!!@@@@@") - source = uproot4.source.file.MemmapSource(filename, num_fallback_workers=1) + source = uproot.source.file.MemmapSource(filename, num_fallback_workers=1) with source as tmp: notifications = queue.Queue() chunks = tmp.chunks( @@ -105,12 +99,12 @@ def test_memmap_fail(tmpdir): tmp.write(b"****** ...+++++++!!!!!@@@@@") with pytest.raises(Exception): - uproot4.source.file.MultithreadedFileSource(filename + "-does-not-exist") + uproot.source.file.MultithreadedFileSource(filename + "-does-not-exist") @pytest.mark.network def test_http(): - source = uproot4.source.http.HTTPSource( + source = uproot.source.http.HTTPSource( "https://example.com", timeout=10, num_fallback_workers=1 ) with source as tmp: @@ -122,7 +116,7 @@ def test_http(): assert len(three) == 200 assert source.fallback is None - source = uproot4.source.http.MultithreadedHTTPSource( + source = uproot.source.http.MultithreadedHTTPSource( "https://example.com", num_workers=1, timeout=10 ) with source as tmp: @@ -132,21 +126,22 @@ def test_http(): def colons_and_ports(): - assert uproot4._util.file_object_path_split("https://example.com:443") == ( + assert uproot._util.file_object_path_split("https://example.com:443") == ( "https://example.com:443", None, ) - assert uproot4._util.file_object_path_split( - "https://example.com:443/something" - ) == ("https://example.com:443/something", None) - assert uproot4._util.file_object_path_split( + assert uproot._util.file_object_path_split("https://example.com:443/something") == ( + "https://example.com:443/something", + None, + ) + assert uproot._util.file_object_path_split( "https://example.com:443/something:else" ) == ("https://example.com:443/something", "else") @pytest.mark.network def test_http_port(): - source = uproot4.source.http.HTTPSource( + source = uproot.source.http.HTTPSource( "https://example.com:443", timeout=10, num_fallback_workers=1 ) with source as tmp: @@ -157,7 +152,7 @@ def test_http_port(): assert len(two) == 5 assert len(three) == 200 - source = uproot4.source.http.MultithreadedHTTPSource( + source = uproot.source.http.MultithreadedHTTPSource( "https://example.com:443", num_workers=1, timeout=10 ) with source as tmp: @@ -168,14 +163,14 @@ def test_http_port(): @pytest.mark.network def test_http_size(): - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", timeout=10, num_fallback_workers=1, ) as source: size1 = source.num_bytes - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", num_workers=1, timeout=10 ) as source: size2 = source.num_bytes @@ -185,14 +180,14 @@ def test_http_size(): @pytest.mark.network def test_http_size_port(): - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://scikit-hep.org:443/uproot3/examples/Zmumu.root", timeout=10, num_fallback_workers=1, ) as source: size1 = source.num_bytes - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://scikit-hep.org:443/uproot3/examples/Zmumu.root", num_workers=1, timeout=10, @@ -204,7 +199,7 @@ def test_http_size_port(): @pytest.mark.network def test_http_fail(): - source = uproot4.source.http.HTTPSource( + source = uproot.source.http.HTTPSource( "https://wonky.cern/does-not-exist", timeout=0.1, num_fallback_workers=1 ) with pytest.raises(Exception) as err: @@ -216,7 +211,7 @@ def test_http_fail(): @pytest.mark.network def test_no_multipart(): for num_workers in [1, 2]: - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", num_workers=num_workers, timeout=10, @@ -233,7 +228,7 @@ def test_no_multipart(): @pytest.mark.network def test_no_multipart_fail(): for num_workers in [1, 2]: - source = uproot4.source.http.MultithreadedHTTPSource( + source = uproot.source.http.MultithreadedHTTPSource( "https://wonky.cern/does-not-exist", num_workers=num_workers, timeout=0.1 ) with pytest.raises(Exception) as err: @@ -245,7 +240,7 @@ def test_no_multipart_fail(): @pytest.mark.network def test_fallback(): for num_workers in [1, 2]: - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", timeout=10, num_fallback_workers=num_workers, @@ -263,7 +258,7 @@ def test_fallback(): @pytest.mark.xrootd def test_xrootd(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", num_workers=1, timeout=20, @@ -282,7 +277,7 @@ def test_xrootd(): def test_xrootd_deadlock(): pytest.importorskip("XRootD") # Attach this file to the "test_xrootd_deadlock" function so it leaks - pytest.uproot_test_xrootd_deadlock_f = uproot4.source.xrootd.XRootDResource( + pytest.uproot_test_xrootd_deadlock_f = uproot.source.xrootd.XRootDResource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=20, ) @@ -293,7 +288,7 @@ def test_xrootd_deadlock(): def test_xrootd_fail(): pytest.importorskip("XRootD") with pytest.raises(Exception) as err: - source = uproot4.source.xrootd.MultithreadedXRootDSource( + source = uproot.source.xrootd.MultithreadedXRootDSource( "root://wonky.cern/does-not-exist", num_workers=1, timeout=1 ) @@ -302,7 +297,7 @@ def test_xrootd_fail(): @pytest.mark.xrootd def test_xrootd_vectorread(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.XRootDSource( + with uproot.source.xrootd.XRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=10, max_num_elements=None, @@ -321,7 +316,7 @@ def test_xrootd_vectorread(): def test_xrootd_vectorread_fail(): pytest.importorskip("XRootD") with pytest.raises(Exception) as err: - source = uproot4.source.xrootd.XRootDSource( + source = uproot.source.xrootd.XRootDSource( "root://wonky.cern/does-not-exist", timeout=1, max_num_elements=None ) @@ -330,7 +325,7 @@ def test_xrootd_vectorread_fail(): @pytest.mark.xrootd def test_xrootd_size(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.XRootDSource( + with uproot.source.xrootd.XRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=10, max_num_elements=None, @@ -338,7 +333,7 @@ def test_xrootd_size(): size1 = source.num_bytes pytest.importorskip("XRootD") - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=10, num_workers=1, @@ -359,10 +354,10 @@ def test_cursor_debug(): numpy.array([123, 123], "u1"), ] ) - future = uproot4.source.futures.TrivialFuture(data) + future = uproot.source.futures.TrivialFuture(data) - chunk = uproot4.source.chunk.Chunk(None, 0, len(data), future) - cursor = uproot4.source.cursor.Cursor(0) + chunk = uproot.source.chunk.Chunk(None, 0, len(data), future) + cursor = uproot.source.cursor.Cursor(0) output = StringIO() cursor.debug(chunk, offset=3, dtype=">f4", stream=output) diff --git a/tests/test_0006-notify-when-downloaded.py b/tests/test_0006-notify-when-downloaded.py index 95131c20c..3ce070897 100644 --- a/tests/test_0006-notify-when-downloaded.py +++ b/tests/test_0006-notify-when-downloaded.py @@ -17,13 +17,7 @@ import numpy import pytest -import uproot4 -import uproot4.source.futures -import uproot4.source.cursor -import uproot4.source.chunk -import uproot4.source.file -import uproot4.source.http -import uproot4.source.xrootd +import uproot def test_file(tmpdir): @@ -32,7 +26,7 @@ def test_file(tmpdir): tmp.write(b"****** ...+++++++!!!!!@@@@@") notifications = queue.Queue() - with uproot4.source.file.MultithreadedFileSource(filename, num_workers=1) as source: + with uproot.source.file.MultithreadedFileSource(filename, num_workers=1) as source: chunks = source.chunks( [(0, 6), (6, 10), (10, 13), (13, 20), (20, 25), (25, 30)], notifications=notifications, @@ -49,7 +43,7 @@ def test_file_workers(tmpdir): tmp.write(b"****** ...+++++++!!!!!@@@@@") notifications = queue.Queue() - with uproot4.source.file.MultithreadedFileSource(filename, num_workers=5) as source: + with uproot.source.file.MultithreadedFileSource(filename, num_workers=5) as source: chunks = source.chunks( [(0, 6), (6, 10), (10, 13), (13, 20), (20, 25), (25, 30)], notifications=notifications, @@ -66,7 +60,7 @@ def test_memmap(tmpdir): tmp.write(b"****** ...+++++++!!!!!@@@@@") notifications = queue.Queue() - with uproot4.source.file.MemmapSource(filename, num_fallback_workers=1) as source: + with uproot.source.file.MemmapSource(filename, num_fallback_workers=1) as source: chunks = source.chunks( [(0, 6), (6, 10), (10, 13), (13, 20), (20, 25), (25, 30)], notifications=notifications, @@ -80,7 +74,7 @@ def test_memmap(tmpdir): @pytest.mark.network def test_http_multipart(): notifications = queue.Queue() - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://example.com", timeout=10, num_fallback_workers=1 ) as source: chunks = source.chunks( @@ -95,7 +89,7 @@ def test_http_multipart(): @pytest.mark.network def test_http(): notifications = queue.Queue() - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://example.com", timeout=10, num_workers=1 ) as source: chunks = source.chunks( @@ -110,7 +104,7 @@ def test_http(): @pytest.mark.network def test_http_workers(): notifications = queue.Queue() - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://example.com", timeout=10, num_workers=2 ) as source: chunks = source.chunks( @@ -125,7 +119,7 @@ def test_http_workers(): @pytest.mark.network def test_http_fallback(): notifications = queue.Queue() - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", timeout=10, num_fallback_workers=1, @@ -142,7 +136,7 @@ def test_http_fallback(): @pytest.mark.network def test_http_fallback_workers(): notifications = queue.Queue() - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://scikit-hep.org/uproot3/examples/Zmumu.root", timeout=10, num_fallback_workers=5, @@ -161,7 +155,7 @@ def test_http_fallback_workers(): def test_xrootd(): pytest.importorskip("XRootD") notifications = queue.Queue() - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", num_workers=1, timeout=10, @@ -180,7 +174,7 @@ def test_xrootd(): def test_xrootd_workers(): pytest.importorskip("XRootD") notifications = queue.Queue() - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", num_workers=5, timeout=10, @@ -199,7 +193,7 @@ def test_xrootd_workers(): def test_xrootd_vectorread(): pytest.importorskip("XRootD") notifications = queue.Queue() - with uproot4.source.xrootd.XRootDSource( + with uproot.source.xrootd.XRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=10, max_num_elements=None, diff --git a/tests/test_0007-single-chunk-interface.py b/tests/test_0007-single-chunk-interface.py index 71d182ee1..c9ed66495 100644 --- a/tests/test_0007-single-chunk-interface.py +++ b/tests/test_0007-single-chunk-interface.py @@ -8,13 +8,7 @@ import numpy import pytest -import uproot4 -import uproot4.source.futures -import uproot4.source.cursor -import uproot4.source.chunk -import uproot4.source.file -import uproot4.source.http -import uproot4.source.xrootd +import uproot def tobytes(x): @@ -39,7 +33,7 @@ def test_file(tmpdir): ] for num_workers in [1, 2]: - with uproot4.source.file.MultithreadedFileSource( + with uproot.source.file.MultithreadedFileSource( filename, num_workers=num_workers ) as source: for i, (start, stop) in enumerate( @@ -49,7 +43,7 @@ def test_file(tmpdir): assert tobytes(chunk.raw_data) == expected[i] with pytest.raises(Exception): - uproot4.source.file.MultithreadedFileSource( + uproot.source.file.MultithreadedFileSource( filename + "-does-not-exist", num_workers=num_workers ) @@ -68,7 +62,7 @@ def test_memmap(tmpdir): b"@@@@@", ] - with uproot4.source.file.MemmapSource(filename, num_fallback_workers=1) as source: + with uproot.source.file.MemmapSource(filename, num_fallback_workers=1) as source: for i, (start, stop) in enumerate( [(0, 6), (6, 10), (10, 13), (13, 20), (20, 25), (25, 30)] ): @@ -76,7 +70,7 @@ def test_memmap(tmpdir): assert tobytes(chunk.raw_data) == expected[i] with pytest.raises(Exception): - uproot4.source.file.MemmapSource( + uproot.source.file.MemmapSource( filename + "-does-not-exist", num_fallback_workers=1 ) @@ -84,7 +78,7 @@ def test_memmap(tmpdir): @pytest.mark.network def test_http(): for num_workers in [1, 2]: - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://example.com", num_workers=num_workers, timeout=10 ) as source: for start, stop in [(0, 100), (50, 55), (200, 400)]: @@ -92,7 +86,7 @@ def test_http(): assert len(tobytes(chunk.raw_data)) == stop - start with pytest.raises(Exception): - with uproot4.source.http.MultithreadedHTTPSource( + with uproot.source.http.MultithreadedHTTPSource( "https://wonky.cern/does-not-exist", num_workers=num_workers, timeout=0.1, @@ -102,7 +96,7 @@ def test_http(): @pytest.mark.network def test_http_multipart(): - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://example.com", timeout=10, num_fallback_workers=1 ) as source: for start, stop in [(0, 100), (50, 55), (200, 400)]: @@ -110,7 +104,7 @@ def test_http_multipart(): assert len(tobytes(chunk.raw_data)) == stop - start with pytest.raises(Exception): - with uproot4.source.http.HTTPSource( + with uproot.source.http.HTTPSource( "https://wonky.cern/does-not-exist", timeout=0.1, num_fallback_workers=1 ) as source: tobytes(source.chunk(0, 100).raw_data) @@ -120,7 +114,7 @@ def test_http_multipart(): @pytest.mark.xrootd def test_xrootd(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", num_workers=1, timeout=10, @@ -138,7 +132,7 @@ def test_xrootd(): @pytest.mark.xrootd def test_xrootd_worker(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.MultithreadedXRootDSource( + with uproot.source.xrootd.MultithreadedXRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", num_workers=5, timeout=10, @@ -156,7 +150,7 @@ def test_xrootd_worker(): @pytest.mark.xrootd def test_xrootd_vectorread(): pytest.importorskip("XRootD") - with uproot4.source.xrootd.XRootDSource( + with uproot.source.xrootd.XRootDSource( "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root", timeout=10, max_num_elements=None, diff --git a/tests/test_0008-start-interpretation.py b/tests/test_0008-start-interpretation.py index c4c6729e7..3d0b9f109 100644 --- a/tests/test_0008-start-interpretation.py +++ b/tests/test_0008-start-interpretation.py @@ -8,12 +8,7 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.model -import uproot4.deserialization -import uproot4.reading -import uproot4.source.file -import uproot4.source.http +import uproot def tobytes(x): @@ -25,25 +20,25 @@ def tobytes(x): def test_classname_encoding(tmpdir): assert ( - uproot4.model.classname_encode("namespace::some.deep", 12) + uproot.model.classname_encode("namespace::some.deep", 12) == "Model_namespace_3a3a_some_2e_deep_3c_templated_2c20_thing_3e__v12" ) assert ( - uproot4.model.classname_encode("namespace::some.deep") + uproot.model.classname_encode("namespace::some.deep") == "Model_namespace_3a3a_some_2e_deep_3c_templated_2c20_thing_3e_" ) - assert uproot4.model.classname_decode( + assert uproot.model.classname_decode( "Model_namespace_3a3a_some_2e_deep_3c_templated_2c20_thing_3e__v12" ) == ("namespace::some.deep", 12) - assert uproot4.model.classname_decode( + assert uproot.model.classname_decode( "Model_namespace_3a3a_some_2e_deep_3c_templated_2c20_thing_3e_" ) == ("namespace::some.deep", None) def test_file_header(): filename = skhep_testdata.data_path("uproot-Zmumu.root") - file = uproot4.reading.ReadOnlyFile(filename) + file = uproot.reading.ReadOnlyFile(filename) assert repr(file.compression) == "ZLIB(4)" assert not file.is_64bit assert file.fNbytesInfo == 4447 diff --git a/tests/test_0009-nested-directories.py b/tests/test_0009-nested-directories.py index bb703f8ea..b4853e710 100644 --- a/tests/test_0009-nested-directories.py +++ b/tests/test_0009-nested-directories.py @@ -8,12 +8,11 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.reading +import uproot def test(): - with uproot4.open(skhep_testdata.data_path("uproot-nesteddirs.root")) as directory: + with uproot.open(skhep_testdata.data_path("uproot-nesteddirs.root")) as directory: assert directory.keys() == [ "one;1", "one/two;1", diff --git a/tests/test_0010-start-streamers.py b/tests/test_0010-start-streamers.py index 67392d559..b7155f8ce 100644 --- a/tests/test_0010-start-streamers.py +++ b/tests/test_0010-start-streamers.py @@ -9,8 +9,7 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.reading +import uproot from_ROOT = {} @@ -1119,7 +1118,7 @@ def drop_fbits(x): def test(): - with uproot4.open(skhep_testdata.data_path("uproot-histograms.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-histograms.root")) as f: streamers = f.file.streamers assert len(streamers) == 14 diff --git a/tests/test_0011-generate-classes-from-streamers.py b/tests/test_0011-generate-classes-from-streamers.py index 93d9f1198..603f87171 100644 --- a/tests/test_0011-generate-classes-from-streamers.py +++ b/tests/test_0011-generate-classes-from-streamers.py @@ -9,8 +9,7 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.reading +import uproot from_ROOT = {} @@ -160,7 +159,7 @@ def drop_fbits(x): def test(): - with uproot4.open(skhep_testdata.data_path("uproot-histograms.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-histograms.root")) as f: assert f.file.class_named("TH1", 7).member_names == [ "fNcells", "fXaxis", diff --git a/tests/test_0013-rntuple-anchor.py b/tests/test_0013-rntuple-anchor.py index 4766dca4c..109f1129f 100644 --- a/tests/test_0013-rntuple-anchor.py +++ b/tests/test_0013-rntuple-anchor.py @@ -14,12 +14,12 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): filename = skhep_testdata.data_path("uproot-ntpl001_staff.root") - with uproot4.open(filename) as f: + with uproot.open(filename) as f: obj = f["Staff"] assert obj.member("fVersion") == 0 assert obj.member("fSize") == 48 @@ -36,7 +36,7 @@ def test(): header_chunk = f.file.source.chunk(header_start, header_stop) print("HEADER") - cursor = uproot4.Cursor(header_start) + cursor = uproot.Cursor(header_start) cursor.debug(header_chunk, 80) print("\n") @@ -48,7 +48,7 @@ def test(): ) print("FOOTER") - cursor = uproot4.Cursor(footer_start) + cursor = uproot.Cursor(footer_start) cursor.debug(footer_chunk, 80) print("\n") diff --git a/tests/test_0014-all-ttree-versions.py b/tests/test_0014-all-ttree-versions.py index bdab4d5f3..e2375043e 100644 --- a/tests/test_0014-all-ttree-versions.py +++ b/tests/test_0014-all-ttree-versions.py @@ -14,213 +14,213 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_streamerless_read(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.23.02-uncompressed.root") ) as f: assert f["sample"].class_version == 16 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 11 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.24.00-uncompressed.root") ) as f: assert f["sample"].class_version == 16 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 11 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.25.02-uncompressed.root") ) as f: assert f["sample"].class_version == 17 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.26.00-uncompressed.root") ) as f: assert f["sample"].class_version == 18 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.27.02-uncompressed.root") ) as f: assert f["sample"].class_version == 18 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.28.00-uncompressed.root") ) as f: assert f["sample"].class_version == 18 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.29.02-uncompressed.root") ) as f: assert f["sample"].class_version == 18 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-5.30.00-uncompressed.root") ) as f: assert f["sample"].class_version == 19 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.08.04-uncompressed.root") ) as f: assert f["sample"].class_version == 19 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.10.05-uncompressed.root") ) as f: assert f["sample"].class_version == 19 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 12 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.14.00-uncompressed.root") ) as f: assert f["sample"].class_version == 20 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 13 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.16.00-uncompressed.root") ) as f: assert f["sample"].class_version == 20 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 13 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.18.00-uncompressed.root") ) as f: assert f["sample"].class_version == 20 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 13 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") ) as f: assert f["sample"].class_version == 20 - assert isinstance(f["sample"], uproot4.TTree) + assert isinstance(f["sample"], uproot.TTree) assert f["sample"].name == f["sample"].member("fName") for x in f["sample"].member("fBranches"): assert x.class_version == 13 - assert isinstance(x, uproot4.TBranch) + assert isinstance(x, uproot.TBranch) assert x.name == x.member("fName") for x in f["sample"].member("fLeaves"): assert x.class_version == 1 assert f.file._streamers is None - with uproot4.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root")) as f: assert f["t"].class_version == 19 assert f.file._streamers is None def test_list_streamers(): - with uproot4.open(skhep_testdata.data_path("uproot-histograms.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-histograms.root")) as f: assert f.file.streamer_dependencies("TNamed") == [ ("TString", 2), ("TObject", 1), diff --git a/tests/test_0016-interpretations.py b/tests/test_0016-interpretations.py index e9c419eea..83669b77c 100644 --- a/tests/test_0016-interpretations.py +++ b/tests/test_0016-interpretations.py @@ -14,11 +14,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_get_key(): - with uproot4.open(skhep_testdata.data_path("uproot-mc10events.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-mc10events.root")) as f: assert f["Events"].name == "Events" assert f["Events/Info"].name == "Info" assert f["Events/Info/evtNum"].name == "evtNum" @@ -33,7 +33,7 @@ def test_get_key(): def test_basket_data(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") ) as f: assert f["sample/i4"].basket_key(3).fSeekKey == 35042 @@ -49,7 +49,7 @@ def test_basket_data(): def test_compressed(): - with uproot4.open(skhep_testdata.data_path("uproot-mc10events.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-mc10events.root")) as f: basket = f["Events/Muon.q"].basket(0) assert basket.data.view(">i4").tolist() == [ -1, @@ -72,7 +72,7 @@ def test_compressed(): def test_read_all(): filename = skhep_testdata.data_path("uproot-issue327.root") - with uproot4.open(filename, minimal_ttree_metadata=False) as f: + with uproot.open(filename, minimal_ttree_metadata=False) as f: f["DstTree/fTracks.fCharge"] @@ -80,7 +80,7 @@ def test_read_all(): def test_recovery(mini): # flat array to recover: filename = skhep_testdata.data_path("uproot-issue21.root") - with uproot4.open( + with uproot.open( {"file:" + filename: "nllscan/mH"}, minimal_ttree_metadata=mini ) as branch: basket = branch.basket(0) @@ -106,7 +106,7 @@ def test_recovery(mini): # uproot-issue187.root fTreeV0: V0s.fV0pt MCparticles.nbodies # uproot-from-geant4.root Details: numgood, TrackedRays: Event phi filename = skhep_testdata.data_path("uproot-issue327.root") - with uproot4.open( + with uproot.open( {"file:" + filename: "DstTree/fTracks.fCharge"}, minimal_ttree_metadata=mini ) as branch: basket = branch.basket(0) diff --git a/tests/test_0017-multi-basket-multi-branch-fetch.py b/tests/test_0017-multi-basket-multi-branch-fetch.py index ab73bea67..ef2ad88ec 100644 --- a/tests/test_0017-multi-basket-multi-branch-fetch.py +++ b/tests/test_0017-multi-basket-multi-branch-fetch.py @@ -14,16 +14,13 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.interpretation.numerical -import uproot4.interpretation.library -import uproot4.source.futures +import uproot def test_any_basket(): - interpretation = uproot4.interpretation.numerical.AsDtype(">i4") + interpretation = uproot.interpretation.numerical.AsDtype(">i4") - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/i4"] as branch: assert branch.basket(0).array(interpretation, library="np").tolist() == [ @@ -69,12 +66,12 @@ def test_any_basket(): def test_stitching_arrays(): - interpretation = uproot4.interpretation.numerical.AsDtype("i8") + interpretation = uproot.interpretation.numerical.AsDtype("i8") expectation = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] basket_arrays = [[0, 1, 2, 3, 4], [5, 6], [], [7, 8, 9], [10], [11, 12, 13, 14]] basket_arrays = [numpy.array(x) for x in basket_arrays] entry_offsets = numpy.array([0, 5, 7, 7, 10, 11, 15]) - library = uproot4.interpretation.library._libraries["np"] + library = uproot.interpretation.library._libraries["np"] for start in range(16): for stop in range(15, -1, -1): @@ -96,7 +93,7 @@ def _names_entries_to_ranges_or_baskets(self, branch_names, entry_start, entry_s def test_names_entries_to_ranges_or_baskets(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: out = _names_entries_to_ranges_or_baskets(sample, ["i4"], 0, 30) @@ -111,22 +108,22 @@ def test_names_entries_to_ranges_or_baskets(): def test_ranges_or_baskets_to_arrays(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: branch = sample["i4"] ranges_or_baskets = _names_entries_to_ranges_or_baskets(sample, ["i4"], 0, 30) branchid_interpretation = { - branch.cache_key: uproot4.interpretation.numerical.AsDtype(">i4") + branch.cache_key: uproot.interpretation.numerical.AsDtype(">i4") } entry_start, entry_stop = (0, 30) - decompression_executor = uproot4.source.futures.TrivialExecutor() - interpretation_executor = uproot4.source.futures.TrivialExecutor() - library = uproot4.interpretation.library._libraries["np"] + decompression_executor = uproot.source.futures.TrivialExecutor() + interpretation_executor = uproot.source.futures.TrivialExecutor() + library = uproot.interpretation.library._libraries["np"] arrays = {} - uproot4.behaviors.TBranch._ranges_or_baskets_to_arrays( + uproot.behaviors.TBranch._ranges_or_baskets_to_arrays( sample, ranges_or_baskets, branchid_interpretation, @@ -173,15 +170,15 @@ def test_ranges_or_baskets_to_arrays(): @pytest.mark.parametrize( "file_handler", - [uproot4.source.file.MultithreadedFileSource, uproot4.source.file.MemmapSource], + [uproot.source.file.MultithreadedFileSource, uproot.source.file.MemmapSource], ) def test_branch_array_1(file_handler): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), file_handler=file_handler, )["sample/i4"] as branch: assert branch.array( - uproot4.interpretation.numerical.AsDtype(">i4"), library="np" + uproot.interpretation.numerical.AsDtype(">i4"), library="np" ).tolist() == [ -15, -14, @@ -218,15 +215,15 @@ def test_branch_array_1(file_handler): @pytest.mark.parametrize( "file_handler", - [uproot4.source.file.MultithreadedFileSource, uproot4.source.file.MemmapSource], + [uproot.source.file.MultithreadedFileSource, uproot.source.file.MemmapSource], ) def test_branch_array_2(file_handler): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), file_handler=file_handler, )["sample/i4"] as branch: assert branch.array( - uproot4.interpretation.numerical.AsDtype(">i4"), + uproot.interpretation.numerical.AsDtype(">i4"), entry_start=3, entry_stop=-5, library="np", @@ -258,18 +255,18 @@ def test_branch_array_2(file_handler): @pytest.mark.parametrize( "file_handler", - [uproot4.source.file.MultithreadedFileSource, uproot4.source.file.MemmapSource], + [uproot.source.file.MultithreadedFileSource, uproot.source.file.MemmapSource], ) def test_branch_array_3(file_handler): - executor = uproot4.ThreadPoolExecutor() - with uproot4.open( + executor = uproot.ThreadPoolExecutor() + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), file_handler=file_handler, interpretation_executor=executor, decompression_executor=executor, )["sample/i4"] as branch: assert branch.array( - uproot4.interpretation.numerical.AsDtype(">i4"), + uproot.interpretation.numerical.AsDtype(">i4"), entry_start=3, entry_stop=-5, library="np", @@ -301,19 +298,19 @@ def test_branch_array_3(file_handler): @pytest.mark.parametrize( "file_handler", - [uproot4.source.file.MultithreadedFileSource, uproot4.source.file.MemmapSource], + [uproot.source.file.MultithreadedFileSource, uproot.source.file.MemmapSource], ) def test_branch_array_4(file_handler): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), file_handler=file_handler, )["sample/i4"] as branch: with pytest.raises(ValueError): - branch.array(uproot4.interpretation.numerical.AsDtype(">i8"), library="np") + branch.array(uproot.interpretation.numerical.AsDtype(">i8"), library="np") def test_cache(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), object_cache=100, array_cache="100 MB", @@ -326,27 +323,27 @@ def test_cache(): ) i4 = f["sample/i4"] assert list(f.file.array_cache) == [] - i4.array(uproot4.interpretation.numerical.AsDtype(">i4"), library="np") + i4.array(uproot.interpretation.numerical.AsDtype(">i4"), library="np") assert list(f.file.array_cache) == [ "db4be408-93ad-11ea-9027-d201a8c0beef:/sample;1:i4(16):i4:AsDtype(Bi4(),Li4()):0-30:np" ] with pytest.raises(OSError): i4.array( - uproot4.interpretation.numerical.AsDtype(">i4"), entry_start=3, library="np" + uproot.interpretation.numerical.AsDtype(">i4"), entry_start=3, library="np" ) def test_pandas(): pandas = pytest.importorskip("pandas") - executor = uproot4.ThreadPoolExecutor() - with uproot4.open( + executor = uproot.ThreadPoolExecutor() + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), interpretation_executor=executor, decompression_executor=executor, )["sample/i4"] as branch: series = branch.array( - uproot4.interpretation.numerical.AsDtype(">i4"), + uproot.interpretation.numerical.AsDtype(">i4"), entry_start=3, entry_stop=-5, library="pd", diff --git a/tests/test_0018-array-fetching-interface.py b/tests/test_0018-array-fetching-interface.py index 8ea1f4974..134601227 100644 --- a/tests/test_0018-array-fetching-interface.py +++ b/tests/test_0018-array-fetching-interface.py @@ -9,14 +9,11 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.interpretation.library -import uproot4.interpretation.jagged -import uproot4.interpretation.numerical +import uproot def test_leaf_interpretation(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert repr(sample["n"].interpretation) == """AsDtype('>i4')""" @@ -91,9 +88,9 @@ def test_leaf_interpretation(): def test_compute(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), object_cache=100, array_cache="100 MB", @@ -141,18 +138,18 @@ def test_compute(): def test_arrays(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") - interp_i4 = uproot4.interpretation.numerical.AsDtype(">i4") - interp_f4 = uproot4.interpretation.numerical.AsDtype(">f4") - interp_Ai4 = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">i4") + interp_i4 = uproot.interpretation.numerical.AsDtype(">i4") + interp_f4 = uproot.interpretation.numerical.AsDtype(">f4") + interp_Ai4 = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">i4") ) - interp_Af8 = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">f8") + interp_Af8 = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">f8") ) - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root"), object_cache=100, array_cache="100 MB", @@ -636,11 +633,11 @@ def test_arrays(): def test_jagged(): - interpretation = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">i2") + interpretation = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">i2") ) - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/Ai2"] as branch: result = branch.array(interpretation, library="np") @@ -708,17 +705,17 @@ def test_jagged(): def test_jagged_awkward(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") - interpretation = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">i2") + interpretation = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">i2") ) - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/Ai2"] as branch: result = branch.array(interpretation) - assert awkward1.to_list(result) == [ + assert awkward.to_list(result) == [ [], [-15], [-15, -13], @@ -755,11 +752,11 @@ def test_jagged_awkward(): def test_jagged_pandas(): pandas = pytest.importorskip("pandas") - interpretation = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">i2") + interpretation = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">i2") ) - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/Ai2"] as branch: result = branch.array(interpretation, library="pd") @@ -890,13 +887,13 @@ def test_jagged_pandas(): def test_stl_vector(): - interpretation = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype(">i4"), header_bytes=10 + interpretation = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype(">i4"), header_bytes=10 ) - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/StlVecI32"] as branch: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/StlVecI32" + ] as branch: result = branch.array(interpretation, library="np") result = [[int(y) for y in x] for x in result] assert result == [ @@ -1006,7 +1003,7 @@ def test_stl_vector(): def test_pandas_merge(): pandas = pytest.importorskip("pandas", minversion="0.21.0") - group = uproot4.interpretation.library.Pandas().group + group = uproot.interpretation.library.Pandas().group name_interp_branch = [("a", None), ("b", None), ("c", None)] a = pandas.Series([1, 2, 3, 4, 5]) diff --git a/tests/test_0022-number-of-branches.py b/tests/test_0022-number-of-branches.py index f7322f621..541c39060 100644 --- a/tests/test_0022-number-of-branches.py +++ b/tests/test_0022-number-of-branches.py @@ -9,14 +9,11 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.interpretation.library -import uproot4.interpretation.jagged -import uproot4.interpretation.numerical +import uproot def test_branchname(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert sample.arrays("i4", library="np")["i4"].tolist() == list(range(-15, 15)) @@ -52,7 +49,7 @@ def test_branchname(): def test_tuple_branchname(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: arrays = sample.arrays(["i4", "i8"], library="np", how=tuple) @@ -67,7 +64,7 @@ def test_tuple_branchname(): def test_interpretation(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert sample["i2"].array(">u2", library="np").tolist() == list( @@ -99,7 +96,7 @@ def test_interpretation(): def test_compute(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert sample.arrays("i4 + 100", library="np")["i4 + 100"].tolist() == list( @@ -127,7 +124,7 @@ def test_compute(): def test_cut(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert sample.arrays("i4 + 100", cut="i4 > 0", library="np")[ @@ -146,7 +143,7 @@ def test_cut(): def test_aliases(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert sample.arrays( @@ -193,7 +190,7 @@ def test_aliases(): def test_jagged(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as sample: assert [x.tolist() for x in sample.arrays("Ai4", library="np")["Ai4"]] == [ diff --git a/tests/test_0023-more-interpretations-1.py b/tests/test_0023-more-interpretations-1.py index 31074971e..15bc44c2f 100644 --- a/tests/test_0023-more-interpretations-1.py +++ b/tests/test_0023-more-interpretations-1.py @@ -9,40 +9,37 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.interpretation.library -import uproot4.interpretation.jagged -import uproot4.interpretation.numerical +import uproot def test_formula_with_dot(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as tree: assert tree.arrays("P3.Py - 50", library="np")["P3.Py - 50"].tolist() == list( range(-50, 50) ) def test_formula_with_slash(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as tree: assert tree.arrays("get('evt/P3/P3.Py') - 50", library="np")[ "get('evt/P3/P3.Py') - 50" ].tolist() == list(range(-50, 50)) def test_formula_with_missing(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as tree: with pytest.raises(KeyError): tree.arrays("wonky", library="np") def test_strings1(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample/str"] as branch: result = branch.array(library="np") @@ -50,9 +47,9 @@ def test_strings1(): def test_strings4(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/StlVecStr"] as branch: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/StlVecStr" + ] as branch: result = branch.array(library="np") assert [result.tolist() for x in result] == [ ["vec-{0:03d}".format(i)] * (i % 10) for i in range(100) @@ -60,7 +57,7 @@ def test_strings4(): def test_strings4(): - with uproot4.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ "tree/evt" ] as branch: result = branch.array(library="np") @@ -70,7 +67,7 @@ def test_strings4(): def test_strings4(): - with uproot4.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root"))[ "t/x" ] as branch: result = branch.array(library="np") @@ -84,7 +81,7 @@ def test_strings4(): def test_double32(): - with uproot4.open(skhep_testdata.data_path("uproot-demo-double32.root"))["T"] as t: + with uproot.open(skhep_testdata.data_path("uproot-demo-double32.root"))["T"] as t: fD64 = t["fD64"].array(library="np") fF32 = t["fF32"].array(library="np") fI32 = t["fI32"].array(library="np") @@ -101,7 +98,7 @@ def test_double32(): def test_double32_2(): - with uproot4.open(skhep_testdata.data_path("uproot-issue187.root"))["fTreeV0"] as t: + with uproot.open(skhep_testdata.data_path("uproot-issue187.root"))["fTreeV0"] as t: assert numpy.all(t["fMultiplicity"].array(library="np") == -1) assert t["V0s.fEtaPos"].array(library="np")[-3].tolist() == [ -0.390625, @@ -110,7 +107,7 @@ def test_double32_2(): def test_double32_3(): - with uproot4.open(skhep_testdata.data_path("uproot-issue232.root"))["fTreeV0"] as t: + with uproot.open(skhep_testdata.data_path("uproot-issue232.root"))["fTreeV0"] as t: assert t["V0Hyper.fNsigmaHe3Pos"].array(library="np")[-1].tolist() == [ 19.38658905029297, 999.0, @@ -122,7 +119,7 @@ def test_double32_3(): def test_double32_float16(): - with uproot4.open(skhep_testdata.data_path("uproot-double32-float16.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-double32-float16.root"))[ "tree" ] as t: assert repr(t["double32_32"].interpretation) == "AsDouble32(-2.71, 10.0, 32)" diff --git a/tests/test_0028-fallback-to-read-streamer.py b/tests/test_0028-fallback-to-read-streamer.py index 8012d616b..9464b65c2 100644 --- a/tests/test_0028-fallback-to-read-streamer.py +++ b/tests/test_0028-fallback-to-read-streamer.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_fallback_reading(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") ) as f: f["tree:evt/P3/P3.Py"] diff --git a/tests/test_0029-more-string-types.py b/tests/test_0029-more-string-types.py index 06e23c9f3..6fb20cf93 100644 --- a/tests/test_0029-more-string-types.py +++ b/tests/test_0029-more-string-types.py @@ -9,23 +9,23 @@ import pytest import skhep_testdata -import uproot4 -from uproot4.interpretation.identify import parse_typename -from uproot4.containers import AsString -from uproot4.containers import AsVector -from uproot4.containers import AsSet -from uproot4.containers import AsMap +import uproot +from uproot.interpretation.identify import parse_typename +from uproot.containers import AsString +from uproot.containers import AsVector +from uproot.containers import AsSet +from uproot.containers import AsMap def test_parse_typename(): - assert parse_typename("TTree") is uproot4.classes["TTree"] + assert parse_typename("TTree") is uproot.classes["TTree"] assert parse_typename("string") == AsString(False) assert parse_typename("std::string") == AsString(False) assert parse_typename("std :: string") == AsString(False) assert parse_typename("char*") == AsString(False, length_bytes="4") assert parse_typename("char *") == AsString(False, length_bytes="4") assert parse_typename("TString") == AsString(False) - assert parse_typename("vector") == AsVector(True, uproot4.classes["TTree"]) + assert parse_typename("vector") == AsVector(True, uproot.classes["TTree"]) assert parse_typename("vector") == AsVector(True, ">i4") assert parse_typename("vector") == AsVector(True, "?") assert parse_typename("vector") == AsVector(True, AsString(False)) @@ -88,9 +88,9 @@ def test_parse_typename(): def test_strings1(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as tree: result = tree["Beg"].array(library="np") assert result.tolist() == ["beg-{0:03d}".format(i) for i in range(100)] @@ -99,7 +99,7 @@ def test_strings1(): def test_map_string_string_in_object(): - with uproot4.open(skhep_testdata.data_path("uproot-issue431.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-issue431.root")) as f: head = f["Head"] assert head.member("map") == { "DAQ": "394", @@ -140,7 +140,7 @@ def test_map_string_string_in_object(): def test_map_long_int_in_object(): - with uproot4.open(skhep_testdata.data_path("uproot-issue283.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-issue283.root")) as f: map_long_int = f["config/detector"].member("ChannelIDMap") assert (map_long_int.keys().min(), map_long_int.keys().max()) == ( 46612627560, @@ -150,7 +150,7 @@ def test_map_long_int_in_object(): def test_top_level_vectors(): - with uproot4.open(skhep_testdata.data_path("uproot-issue38a.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue38a.root"))[ "ntupler/tree" ] as tree: assert [x.tolist() for x in tree["v_int16"].array(library="np")] == [[1, 2, 3]] @@ -172,7 +172,7 @@ def test_top_level_vectors(): def test_strings1(): - with uproot4.open(skhep_testdata.data_path("uproot-issue31.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue31.root"))[ "T/name" ] as branch: result = branch.array(library="np") @@ -180,16 +180,16 @@ def test_strings1(): def test_strings2(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/Str"] as branch: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/Str" + ] as branch: result = branch.array(library="np") assert result.tolist() == ["evt-{0:03d}".format(i) for i in range(100)] def test_strings3(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/StdStr"] as branch: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/StdStr" + ] as branch: result = branch.array(library="np") assert result.tolist() == ["std-{0:03d}".format(i) for i in range(100)] diff --git a/tests/test_0031-test-stl-containers.py b/tests/test_0031-test-stl-containers.py index 83cb77f6d..5abf9920b 100644 --- a/tests/test_0031-test-stl-containers.py +++ b/tests/test_0031-test-stl-containers.py @@ -9,18 +9,18 @@ import pytest import skhep_testdata -import uproot4 -from uproot4.interpretation.numerical import AsDtype -from uproot4.interpretation.jagged import AsJagged -from uproot4.interpretation.objects import AsObjects -from uproot4.containers import AsString -from uproot4.containers import AsVector -from uproot4.containers import AsSet -from uproot4.containers import AsMap +import uproot +from uproot.interpretation.numerical import AsDtype +from uproot.interpretation.jagged import AsJagged +from uproot.interpretation.objects import AsObjects +from uproot.containers import AsString +from uproot.containers import AsVector +from uproot.containers import AsSet +from uproot.containers import AsMap def test_typename(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert tree["vector_int32"].interpretation == AsJagged(AsDtype(">i4"), 10) @@ -95,7 +95,7 @@ def test_typename(): def test_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert tree["string"].array(library="np").tolist() == [ @@ -108,7 +108,7 @@ def test_string(): def test_tstring(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert tree["tstring"].array(library="np").tolist() == [ @@ -121,7 +121,7 @@ def test_tstring(): def test_vector_int32(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["vector_int32"].array(library="np")] == [ @@ -134,7 +134,7 @@ def test_vector_int32(): def test_vector_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["vector_string"].array(library="np")] == [ @@ -147,7 +147,7 @@ def test_vector_string(): def test_vector_tstring(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["vector_tstring"].array(library="np")] == [ @@ -160,7 +160,7 @@ def test_vector_tstring(): def test_vector_vector_int32(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -175,7 +175,7 @@ def test_vector_vector_int32(): def test_vector_vector_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -201,7 +201,7 @@ def test_vector_vector_string(): def test_vector_set_int32(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["vector_set_int32"].array(library="np")] == [ @@ -220,7 +220,7 @@ def test_vector_set_int32(): def test_vector_set_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["vector_set_string"].array(library="np")] == [ @@ -244,7 +244,7 @@ def test_vector_set_string(): def test_set_int32(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["set_int32"].array(library="np")] == [ @@ -257,7 +257,7 @@ def test_set_int32(): def test_set_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["set_string"].array(library="np")] == [ @@ -270,7 +270,7 @@ def test_set_string(): def test_map_int32_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["map_int32_int16"].array(library="np")] == [ @@ -283,7 +283,7 @@ def test_map_int32_int16(): def test_map_int32_vector_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -298,7 +298,7 @@ def test_map_int32_vector_int16(): def test_map_int32_vector_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -324,7 +324,7 @@ def test_map_int32_vector_string(): def test_map_int32_set_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -345,7 +345,7 @@ def test_map_int32_set_int16(): def test_map_int32_set_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -371,7 +371,7 @@ def test_map_int32_set_string(): def test_map_string_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["map_string_int16"].array(library="np")] == [ @@ -384,7 +384,7 @@ def test_map_string_int16(): def test_map_string_vector_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -405,7 +405,7 @@ def test_map_string_vector_int16(): def test_map_string_vector_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -431,7 +431,7 @@ def test_map_string_vector_string(): def test_map_string_set_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -457,7 +457,7 @@ def test_map_string_set_int16(): def test_map_string_set_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -487,7 +487,7 @@ def test_map_string_set_string(): def test_map_int32_vector_vector_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -514,7 +514,7 @@ def test_map_int32_vector_vector_int16(): def test_map_int32_vector_set_int16(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [ @@ -550,7 +550,7 @@ def test_map_int32_vector_set_int16(): def test_map_string_string(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["map_string_string"].array(library="np")] == [ @@ -569,7 +569,7 @@ def test_map_string_string(): def test_map_string_tstring(): - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert [x.tolist() for x in tree["map_string_tstring"].array(library="np")] == [ @@ -588,7 +588,7 @@ def test_map_string_tstring(): def test_map_int_struct(): - with uproot4.open(skhep_testdata.data_path("uproot-issue468.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue468.root"))[ "Geant4Data/Geant4Data./Geant4Data.particles" ] as branch: assert ( diff --git a/tests/test_0033-more-interpretations-2.py b/tests/test_0033-more-interpretations-2.py index 290341b0c..e55c6554e 100644 --- a/tests/test_0033-more-interpretations-2.py +++ b/tests/test_0033-more-interpretations-2.py @@ -10,15 +10,15 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_awkward_strings(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["string"].array(library="ak")) == [ + assert awkward.to_list(tree["string"].array(library="ak")) == [ "one", "two", "three", @@ -29,7 +29,7 @@ def test_awkward_strings(): def test_pandas_strings(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: assert tree["string"].array(library="pd").values.tolist() == [ @@ -42,7 +42,7 @@ def test_pandas_strings(): def test_leaflist_numpy(): - with uproot4.open(skhep_testdata.data_path("uproot-leaflist.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-leaflist.root"))[ "tree/leaflist" ] as branch: result = branch.array(library="np") @@ -58,13 +58,13 @@ def test_leaflist_numpy(): def test_leaflist_awkward(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-leaflist.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-leaflist.root"))[ "tree/leaflist" ] as branch: result = branch.array(library="ak") - assert str(awkward1.type(result)) == '5 * {"x": float64, "y": int32, "z": int8}' - assert awkward1.to_list(result) == [ + assert str(awkward.type(result)) == '5 * {"x": float64, "y": int32, "z": int8}' + assert awkward.to_list(result) == [ {"x": 1.1, "y": 1, "z": 97}, {"x": 2.2, "y": 2, "z": 98}, {"x": 3.3, "y": 3, "z": 99}, @@ -75,7 +75,7 @@ def test_leaflist_awkward(): def test_leaflist_pandas(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-leaflist.root"))["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-leaflist.root"))["tree"] as tree: result = tree["leaflist"].array(library="pd") if distutils.version.LooseVersion( @@ -114,7 +114,7 @@ def test_leaflist_pandas(): def test_fixed_width(): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as tree: assert tree["ai4"].array(library="np").tolist() == [ @@ -124,18 +124,18 @@ def test_fixed_width(): def test_fixed_width_awkward(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open( + awkward = pytest.importorskip("awkward") + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as tree: - assert awkward1.to_list(tree["ai4"].array(library="ak")) == [ + assert awkward.to_list(tree["ai4"].array(library="ak")) == [ [i, i + 1, i + 2] for i in range(-14, 16) ] def test_fixed_width_pandas(): pandas = pytest.importorskip("pandas") - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root") )["sample"] as tree: result = tree["ai4"].array(library="pd") @@ -153,9 +153,9 @@ def test_fixed_width_pandas(): def test_fixed_width_pandas_2(): pandas = pytest.importorskip("pandas") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as tree: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as tree: result = tree["ArrayI32[10]"].array(library="pd") assert list(result.columns) == ["[" + str(i) + "]" for i in range(10)] for i in range(10): diff --git a/tests/test_0034-generic-objects-in-ttrees.py b/tests/test_0034-generic-objects-in-ttrees.py index 9b563f1a0..908cad427 100644 --- a/tests/test_0034-generic-objects-in-ttrees.py +++ b/tests/test_0034-generic-objects-in-ttrees.py @@ -9,13 +9,13 @@ import pytest import skhep_testdata -import uproot4 -from uproot4.interpretation.numerical import AsDtype -from uproot4.interpretation.jagged import AsJagged +import uproot +from uproot.interpretation.numerical import AsDtype +from uproot.interpretation.jagged import AsJagged def test_histograms_outside_of_ttrees(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: contents = numpy.asarray(f["hpx"].bases[-1]) assert (contents.min(), contents.max()) == (0.0, 2417.0) @@ -29,7 +29,7 @@ def test_histograms_outside_of_ttrees(): def test_gohep_nosplit_file(): - with uproot4.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ "tree/evt" ] as branch: result = branch.array(library="np", entry_start=5, entry_stop=6)[0] @@ -126,14 +126,14 @@ def test_gohep_nosplit_file(): def test_TLorentzVectors_show(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: tree.show() def test_TVector2(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["MET"].array(library="np", entry_stop=1)[0] @@ -144,7 +144,7 @@ def test_TVector2(): def test_vector_TLorentzVector(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["muonp4"].array(library="np", entry_stop=1)[0] @@ -163,7 +163,7 @@ def test_vector_TLorentzVector(): def test_strided(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: assert tree.file.class_named("TLorentzVector", "max").strided_interpretation( @@ -189,7 +189,7 @@ def test_strided(): def test_read_strided_TVector2(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: interp = tree.file.class_named("TVector2", "max").strided_interpretation( @@ -206,13 +206,13 @@ def test_read_strided_TVector2(): def test_read_strided_TLorentzVector(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: interp = tree.file.class_named("TLorentzVector", "max").strided_interpretation( tree.file ) - interp = uproot4.interpretation.jagged.AsJagged(interp, header_bytes=10) + interp = uproot.interpretation.jagged.AsJagged(interp, header_bytes=10) assert tree["muonp4"].interpretation == interp @@ -232,19 +232,19 @@ def test_read_strided_TLorentzVector(): def test_strided_awkward(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["MET"].array(library="ak") - if not uproot4._util.py35 and not uproot4._util.py2: + if not uproot._util.py35 and not uproot._util.py2: assert ( - repr(awkward1.type(result)) + repr(awkward.type(result)) == '2421 * TVector2["fX": float64, "fY": float64]' ) - assert awkward1.to_list(result["fX"][:10]) == [ + assert awkward.to_list(result["fX"][:10]) == [ 5.912771224975586, 24.76520347595215, -25.78508758544922, @@ -256,7 +256,7 @@ def test_strided_awkward(): 42.416194915771484, -1.9144694805145264, ] - assert awkward1.to_list(result["fY"][:10]) == [ + assert awkward.to_list(result["fY"][:10]) == [ 2.5636332035064697, -16.349109649658203, 16.237131118774414, @@ -271,15 +271,15 @@ def test_strided_awkward(): def test_jagged_strided_awkward(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["muonp4"].array(library="ak") - if not uproot4._util.py35 and not uproot4._util.py2: + if not uproot._util.py35 and not uproot._util.py2: assert ( - repr(awkward1.type(result)) + repr(awkward.type(result)) == '2421 * var * TLorentzVector["fP": TVector3["fX": float64, ' '"fY": float64, "fZ": float64], "fE": float64]' ) @@ -291,13 +291,13 @@ def test_jagged_strided_awkward(): def test_jagged_awkward_1(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/evt/SliceU64"] as branch: + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/evt/SliceU64" + ] as branch: assert branch.interpretation == AsJagged(AsDtype(">u8"), header_bytes=1) result = branch.array(library="ak", entry_stop=6) - assert awkward1.to_list(result) == [ + assert awkward.to_list(result) == [ [], [1], [2, 2], @@ -308,13 +308,13 @@ def test_jagged_awkward_1(): def test_jagged_awkward_2(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/evt/StlVecF64"] as branch: + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/evt/StlVecF64" + ] as branch: assert branch.interpretation == AsJagged(AsDtype(">f8"), header_bytes=10) result = branch.array(library="ak", entry_stop=6) - assert awkward1.to_list(result) == [ + assert awkward.to_list(result) == [ [], [1], [2, 2], @@ -325,8 +325,8 @@ def test_jagged_awkward_2(): def test_general_awkward_form(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ "tree/evt" ] as branch: assert json.loads( @@ -685,11 +685,11 @@ def test_general_awkward_form(): def test_jagged_awkward_3(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree/evt/StlVecStr"] as branch: - assert awkward1.to_list(branch.array(library="ak")[:6, :3]) == [ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree/evt/StlVecStr" + ] as branch: + assert awkward.to_list(branch.array(library="ak")[:6, :3]) == [ [], ["vec-001"], ["vec-002", "vec-002"], @@ -700,11 +700,11 @@ def test_jagged_awkward_3(): def test_awkward_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["string"].array(library="ak")) == [ + assert awkward.to_list(tree["string"].array(library="ak")) == [ "one", "two", "three", @@ -714,11 +714,11 @@ def test_awkward_string(): def test_awkward_tstring(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["tstring"].array(library="ak")) == [ + assert awkward.to_list(tree["tstring"].array(library="ak")) == [ "one", "two", "three", @@ -728,11 +728,11 @@ def test_awkward_tstring(): def test_awkward_vector_int32(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["vector_int32"].array(library="ak")) == [ + assert awkward.to_list(tree["vector_int32"].array(library="ak")) == [ [1], [1, 2], [1, 2, 3], @@ -742,11 +742,11 @@ def test_awkward_vector_int32(): def test_awkward_vector_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["vector_string"].array(library="ak")) == [ + assert awkward.to_list(tree["vector_string"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -756,11 +756,11 @@ def test_awkward_vector_string(): def test_awkward_vector_tstring(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["vector_tstring"].array(library="ak")) == [ + assert awkward.to_list(tree["vector_tstring"].array(library="ak")) == [ ["one"], ["one", "two"], ["one", "two", "three"], @@ -770,11 +770,11 @@ def test_awkward_vector_tstring(): def test_awkward_vector_vector_int32(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["vector_vector_int32"].array(library="ak")) == [ + assert awkward.to_list(tree["vector_vector_int32"].array(library="ak")) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -784,11 +784,11 @@ def test_awkward_vector_vector_int32(): def test_awkward_vector_vector_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - assert awkward1.to_list(tree["vector_vector_string"].array(library="ak")) == [ + assert awkward.to_list(tree["vector_vector_string"].array(library="ak")) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -809,19 +809,19 @@ def test_awkward_vector_vector_string(): def test_awkward_map_int32_int16(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip(tree["map_int32_int16"].array(library="ak")) - assert awkward1.to_list(keys) == [ + keys, values = awkward.unzip(tree["map_int32_int16"].array(library="ak")) + assert awkward.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [1], [1, 2], [1, 2, 3], @@ -831,21 +831,19 @@ def test_awkward_map_int32_int16(): def test_awkward_map_int32_vector_int16(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip( - tree["map_int32_vector_int16"].array(library="ak") - ) - assert awkward1.to_list(keys) == [ + keys, values = awkward.unzip(tree["map_int32_vector_int16"].array(library="ak")) + assert awkward.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], @@ -855,21 +853,21 @@ def test_awkward_map_int32_vector_int16(): def test_awkward_map_int32_vector_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip( + keys, values = awkward.unzip( tree["map_int32_vector_string"].array(library="ak") ) - assert awkward1.to_list(keys) == [ + assert awkward.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two"], ["one", "two", "three"]], @@ -890,19 +888,19 @@ def test_awkward_map_int32_vector_string(): def test_awkward_map_string_int16(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip(tree["map_string_int16"].array(library="ak")) - assert awkward1.to_list(keys) == [ + keys, values = awkward.unzip(tree["map_string_int16"].array(library="ak")) + assert awkward.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [1], [1, 2], [1, 3, 2], @@ -912,21 +910,21 @@ def test_awkward_map_string_int16(): def test_awkward_map_string_vector_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip( + keys, values = awkward.unzip( tree["map_string_vector_string"].array(library="ak") ) - assert awkward1.to_list(keys) == [ + assert awkward.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [["one"]], [["one"], ["one", "two"]], [["one"], ["one", "two", "three"], ["one", "two"]], @@ -947,21 +945,21 @@ def test_awkward_map_string_vector_string(): def test_awkward_map_int32_vector_vector_int16(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip( + keys, values = awkward.unzip( tree["map_int32_vector_vector_int16"].array(library="ak") ) - assert awkward1.to_list(keys) == [ + assert awkward.to_list(keys) == [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ [[[1]]], [[[1]], [[1], [1, 2]]], [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]]], @@ -982,19 +980,19 @@ def test_awkward_map_int32_vector_vector_int16(): def test_awkward_map_string_string(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip(tree["map_string_string"].array(library="ak")) - assert awkward1.to_list(keys) == [ + keys, values = awkward.unzip(tree["map_string_string"].array(library="ak")) + assert awkward.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"], @@ -1004,19 +1002,19 @@ def test_awkward_map_string_string(): def test_awkward_map_string_tstring(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-stl_containers.root"))[ "tree" ] as tree: - keys, values = awkward1.unzip(tree["map_string_tstring"].array(library="ak")) - assert awkward1.to_list(keys) == [ + keys, values = awkward.unzip(tree["map_string_tstring"].array(library="ak")) + assert awkward.to_list(keys) == [ ["one"], ["one", "two"], ["one", "three", "two"], ["four", "one", "three", "two"], ["five", "four", "one", "three", "two"], ] - assert awkward1.to_list(values) == [ + assert awkward.to_list(values) == [ ["ONE"], ["ONE", "TWO"], ["ONE", "THREE", "TWO"], @@ -1026,8 +1024,8 @@ def test_awkward_map_string_tstring(): def test_awkward_map_int_struct(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-issue468.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-issue468.root"))[ "Geant4Data/Geant4Data./Geant4Data.particles" ] as branch: assert ( @@ -1035,15 +1033,15 @@ def test_awkward_map_int_struct(): "Model_BDSOutputROOTGeant4Data_3a3a_ParticleInfo))" ) result = branch.array(library="ak") - if not uproot4._util.py35 and not uproot4._util.py2: + if not uproot._util.py35 and not uproot._util.py2: assert ( - repr(awkward1.type(result)) + repr(awkward.type(result)) == '1 * [var * (int64, struct[["charge", "mass", "name"], ' '[int64, float64, string], parameters={"__record__": ' '"BDSOutputROOTGeant4Data::ParticleInfo"}]), ' 'parameters={"__array__": "sorted_map"}]' ) - assert awkward1.to_list(result[0, "0"]) == [ + assert awkward.to_list(result[0, "0"]) == [ -1000020040, -1000020030, -1000010030, @@ -1075,7 +1073,7 @@ def test_awkward_map_int_struct(): 1000020030, 1000020040, ] - assert awkward1.to_list(result[0, "1", "name"]) == [ + assert awkward.to_list(result[0, "1", "name"]) == [ "anti_alpha", "anti_He3", "anti_triton", @@ -1107,7 +1105,7 @@ def test_awkward_map_int_struct(): "He3", "alpha", ] - assert awkward1.to_list(result[0, "1", "charge"]) == [ + assert awkward.to_list(result[0, "1", "charge"]) == [ -2, -2, -1, @@ -1139,7 +1137,7 @@ def test_awkward_map_int_struct(): 2, 2, ] - assert awkward1.to_list(result[0, "1", "mass"]) == [ + assert awkward.to_list(result[0, "1", "mass"]) == [ 3.727379, 2.808391, 2.808921, @@ -1174,59 +1172,59 @@ def test_awkward_map_int_struct(): def test_awkward_nosplit_file(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root"))[ "tree/evt" ] as branch: result = branch.array(library="ak", entry_stop=5) - assert awkward1.to_list(result["Beg"]) == [ + assert awkward.to_list(result["Beg"]) == [ "beg-000", "beg-001", "beg-002", "beg-003", "beg-004", ] - assert awkward1.to_list(result["I16"]) == [0, 1, 2, 3, 4] - assert awkward1.to_list(result["F32"]) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward1.to_list(result["Str"]) == [ + assert awkward.to_list(result["I16"]) == [0, 1, 2, 3, 4] + assert awkward.to_list(result["F32"]) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert awkward.to_list(result["Str"]) == [ "evt-000", "evt-001", "evt-002", "evt-003", "evt-004", ] - assert awkward1.to_list(result["P3", "Px"]) == [-1, 0, 1, 2, 3] - assert awkward1.to_list(result["P3", "Py"]) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward1.to_list(result["P3", "Pz"]) == [-1, 0, 1, 2, 3] - assert awkward1.to_list(result["ArrayI32"]) == [ + assert awkward.to_list(result["P3", "Px"]) == [-1, 0, 1, 2, 3] + assert awkward.to_list(result["P3", "Py"]) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert awkward.to_list(result["P3", "Pz"]) == [-1, 0, 1, 2, 3] + assert awkward.to_list(result["ArrayI32"]) == [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4, 4, 4, 4, 4], ] - assert awkward1.to_list(result["StdStr"]) == [ + assert awkward.to_list(result["StdStr"]) == [ "std-000", "std-001", "std-002", "std-003", "std-004", ] - assert awkward1.to_list(result["SliceI64"]) == [ + assert awkward.to_list(result["SliceI64"]) == [ [], [1], [2, 2], [3, 3, 3], [4, 4, 4, 4], ] - assert awkward1.to_list(result["StlVecStr"]) == [ + assert awkward.to_list(result["StlVecStr"]) == [ [], ["vec-001"], ["vec-002", "vec-002"], ["vec-003", "vec-003", "vec-003"], ["vec-004", "vec-004", "vec-004", "vec-004"], ] - assert awkward1.to_list(result["End"]) == [ + assert awkward.to_list(result["End"]) == [ "end-000", "end-001", "end-002", @@ -1237,7 +1235,7 @@ def test_awkward_nosplit_file(): def test_pandas_TVector2(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["MET"].array(library="pd") @@ -1248,7 +1246,7 @@ def test_pandas_TVector2(): def test_pandas_vector_TLorentzVector(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-HZZ-objects.root"))[ "events" ] as tree: result = tree["muonp4"].array(library="pd") @@ -1272,12 +1270,12 @@ def test_pandas_vector_TLorentzVector(): def test_map_string_TVector3(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-issue494.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-issue494.root"))[ "Model/Model.scoringMeshTranslation" ] as branch: result = branch.array(library="ak") - assert awkward1.to_list(result["0"]) == [ + assert awkward.to_list(result["0"]) == [ [ "global_mesh", "mesh_foil1", @@ -1300,7 +1298,7 @@ def test_map_string_TVector3(): "mesh_t7", ] ] - assert awkward1.to_list(result["1"]) == [ + assert awkward.to_list(result["1"]) == [ [ {"fX": 0.0, "fY": 0.0, "fZ": 0.074}, {"fX": 0.0, "fY": 0.04, "fZ": 0.048509515}, @@ -1326,28 +1324,28 @@ def test_map_string_TVector3(): def test_gohep_output_file(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-issue413.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-issue413.root"))[ "mytree" ] as tree: - assert awkward1.to_list(tree["I32"].array()) == [0, 1, 2, 3, 4] - assert awkward1.to_list(tree["F64"].array()) == [0.0, 1.0, 2.0, 3.0, 4.0] - assert awkward1.to_list(tree["Str"].array()) == [ + assert awkward.to_list(tree["I32"].array()) == [0, 1, 2, 3, 4] + assert awkward.to_list(tree["F64"].array()) == [0.0, 1.0, 2.0, 3.0, 4.0] + assert awkward.to_list(tree["Str"].array()) == [ "evt-0", "evt-1", "evt-2", "evt-3", "evt-4", ] - assert awkward1.to_list(tree["ArrF64"].array()) == [ + assert awkward.to_list(tree["ArrF64"].array()) == [ [0.0, 1.0, 2.0, 3.0, 4.0], [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0], [3.0, 4.0, 5.0, 6.0, 7.0], [4.0, 5.0, 6.0, 7.0, 8.0], ] - assert awkward1.to_list(tree["N"].array()) == [0, 1, 2, 3, 4] - assert awkward1.to_list(tree["SliF64"].array()) == [ + assert awkward.to_list(tree["N"].array()) == [0, 1, 2, 3, 4] + assert awkward.to_list(tree["SliF64"].array()) == [ [], [1.0], [2.0, 3.0], diff --git a/tests/test_0035-datatype-generality.py b/tests/test_0035-datatype-generality.py index 36aae690c..04e6b5cd0 100644 --- a/tests/test_0035-datatype-generality.py +++ b/tests/test_0035-datatype-generality.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_TH2_in_ttree(): - with uproot4.open(skhep_testdata.data_path("uproot-issue-tbranch-of-th2.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue-tbranch-of-th2.root"))[ "g4SimHits/tree" ] as tree: assert ( @@ -20,7 +20,7 @@ def test_TH2_in_ttree(): def test_iofeatures_offsets(): - with uproot4.open(skhep_testdata.data_path("uproot-small-dy-withoffsets.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-small-dy-withoffsets.root"))[ "tree/Muon_pt" ] as withoffsets: muonpt1 = withoffsets.array(library="np", entry_start=10, entry_stop=20) @@ -37,7 +37,7 @@ def test_iofeatures_offsets(): [51.9132194519043, 31.930095672607422], ] - with uproot4.open(skhep_testdata.data_path("uproot-small-dy-nooffsets.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-small-dy-nooffsets.root"))[ "tree/Muon_pt" ] as nooffsets: muonpt2 = nooffsets.array(library="np", entry_start=10, entry_stop=20) diff --git a/tests/test_0043-iterate-function.py b/tests/test_0043-iterate-function.py index 5d1421e0d..a23e3e4a8 100644 --- a/tests/test_0043-iterate-function.py +++ b/tests/test_0043-iterate-function.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_num_entries_for(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: + with uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: assert events.num_entries_for("1 kB") == 12 assert events.num_entries_for("10 kB") == 116 assert events.num_entries_for("0.1 MB") == 1157 @@ -18,9 +18,7 @@ def test_num_entries_for(): def test_num_entries_for_2(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: assert events.num_entries_for("1 kB") == 13 assert events.num_entries_for("10 kB") == 133 assert events.num_entries_for("0.1 MB") == 1333 @@ -28,9 +26,7 @@ def test_num_entries_for_2(): def test_iterate_1(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: for i, arrays in enumerate(events.iterate(step_size="0.1 MB", library="np")): if i == 0: assert len(arrays["px1"]) == 1333 @@ -41,9 +37,7 @@ def test_iterate_1(): def test_iterate_2(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: for i, arrays in enumerate(events.iterate("px1", step_size=1000, library="np")): if i == 0: assert len(arrays["px1"]) == 1000 @@ -78,9 +72,7 @@ def test_iterate_2(): def test_iterate_pandas_1(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: for i, arrays in enumerate(events.iterate("px1", step_size=1000, library="pd")): if i == 0: assert arrays["px1"].index.values[0] == 0 @@ -97,7 +89,7 @@ def test_iterate_pandas_1(): def test_iterate_pandas_2(): pandas = pytest.importorskip("pandas") - with uproot4.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: + with uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: for i, arrays in enumerate( events.iterate("Muon_Px", step_size=1000, library="pd") ): @@ -115,9 +107,7 @@ def test_iterate_pandas_2(): def test_iterate_report_1(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: for i, (arrays, report) in enumerate( events.iterate("px1", step_size=1000, report=True, library="np") ): @@ -138,7 +128,7 @@ def test_iterate_report_1(): def test_iterate_report_2(): - with uproot4.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: + with uproot.open(skhep_testdata.data_path("uproot-HZZ.root"))["events"] as events: for i, (arrays, report) in enumerate( events.iterate("Muon_Px", step_size=1000, report=True, library="np") ): @@ -163,7 +153,7 @@ def test_function_iterate(): "6.20.04", "*" ) expect = 0 - for arrays, report in uproot4.iterate( + for arrays, report in uproot.iterate( {files: "sample"}, "i8", report=True, library="np" ): assert arrays["i8"][:5].tolist() == [-15, -14, -13, -12, -11] @@ -178,7 +168,7 @@ def test_function_iterate_pandas(): "6.20.04", "*" ) expect = 0 - for arrays, report in uproot4.iterate( + for arrays, report in uproot.iterate( {files: "sample"}, "i8", report=True, library="pd" ): assert arrays["i8"].values[:5].tolist() == [-15, -14, -13, -12, -11] @@ -194,7 +184,7 @@ def test_function_iterate_pandas_2(): "HZZ", "HZZ-{uncompressed,zlib,lz4}" ) expect = 0 - for arrays, report in uproot4.iterate( + for arrays, report in uproot.iterate( {files: "events"}, "Muon_Px", report=True, library="pd" ): assert arrays["Muon_Px"].index.values[0] == (expect, 0) diff --git a/tests/test_0044-concatenate-function.py b/tests/test_0044-concatenate-function.py index e07f662be..1f3b6c30c 100644 --- a/tests/test_0044-concatenate-function.py +++ b/tests/test_0044-concatenate-function.py @@ -6,26 +6,26 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_concatenate_numpy(): files = skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) - arrays = uproot4.concatenate({files: "sample"}, ["i8", "f8"], library="np") + arrays = uproot.concatenate({files: "sample"}, ["i8", "f8"], library="np") assert len(arrays["i8"]) == 420 assert len(arrays["f8"]) == 420 def test_concatenate_awkward(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") files = skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) - arrays = uproot4.concatenate({files: "sample"}, ["i8", "f8"], library="ak") - assert isinstance(arrays, awkward1.Array) - assert set(awkward1.fields(arrays)) == set(["i8", "f8"]) + arrays = uproot.concatenate({files: "sample"}, ["i8", "f8"], library="ak") + assert isinstance(arrays, awkward.Array) + assert set(awkward.fields(arrays)) == set(["i8", "f8"]) assert len(arrays) == 420 @@ -34,7 +34,7 @@ def test_concatenate_pandas(): files = skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) - arrays = uproot4.concatenate({files: "sample"}, ["i8", "f8"], library="pd") + arrays = uproot.concatenate({files: "sample"}, ["i8", "f8"], library="pd") assert isinstance(arrays, pandas.DataFrame) assert set(arrays.columns.tolist()) == set(["i8", "f8"]) assert len(arrays) == 420 diff --git a/tests/test_0045-lazy-arrays-1.py b/tests/test_0045-lazy-arrays-1.py index 1e472a35a..e8ac68f62 100644 --- a/tests/test_0045-lazy-arrays-1.py +++ b/tests/test_0045-lazy-arrays-1.py @@ -6,13 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_array_cast(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ - "events" - ] as events: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))["events"] as events: assert numpy.array(events["px1"])[:5].tolist() == [ -41.1952876442, 35.1180497674, @@ -23,8 +21,8 @@ def test_array_cast(): def test_branch_pluralization(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root"))[ "events/px1" ] as px1: assert px1.array(library="np")[:5].tolist() == [ @@ -71,7 +69,7 @@ def test_branch_pluralization(): assert False for i, arrays in enumerate( - uproot4.iterate({skhep_testdata.data_path("uproot-Zmumu.root"): "events/px1"}) + uproot.iterate({skhep_testdata.data_path("uproot-Zmumu.root"): "events/px1"}) ): if i == 0: assert arrays["px1"][:5].tolist() == [ @@ -102,18 +100,18 @@ def test_branch_pluralization(): def test_awkward(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") files = skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) cache = {} - array = uproot4.lazy({files: "sample"}, array_cache=cache) + array = uproot.lazy({files: "sample"}, array_cache=cache) assert len(cache) == 0 - assert awkward1.to_list(array[:5, "i4"]) == [-15, -14, -13, -12, -11] + assert awkward.to_list(array[:5, "i4"]) == [-15, -14, -13, -12, -11] assert len(cache) == 1 - assert awkward1.to_list(array[:5, "ai4"]) == [ + assert awkward.to_list(array[:5, "ai4"]) == [ [-14, -13, -12], [-13, -12, -11], [-12, -11, -10], @@ -122,7 +120,7 @@ def test_awkward(): ] assert len(cache) == 2 - assert awkward1.to_list(array[:5, "Ai4"]) == [ + assert awkward.to_list(array[:5, "Ai4"]) == [ [], [-15], [-15, -13], @@ -131,7 +129,7 @@ def test_awkward(): ] assert len(cache) == 3 - assert awkward1.to_list(array[:5, "str"]) == [ + assert awkward.to_list(array[:5, "str"]) == [ "hey-0", "hey-1", "hey-2", @@ -142,17 +140,17 @@ def test_awkward(): def test_awkward_pluralization(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") files = skhep_testdata.data_path("uproot-sample-6.20.04-uncompressed.root").replace( "6.20.04", "*" ) - array = uproot4.lazy({files: "sample"}) - assert awkward1.to_list(array[:5, "i4"]) == [-15, -14, -13, -12, -11] + array = uproot.lazy({files: "sample"}) + assert awkward.to_list(array[:5, "i4"]) == [-15, -14, -13, -12, -11] def test_lazy_called_on_nonexistent_file(): - awkward1 = pytest.importorskip("awkward1") + awkward = pytest.importorskip("awkward") filename = "nonexistent_file.root" - with pytest.raises(uproot4._util._FileNotFoundError) as excinfo: - uproot4.lazy(filename) + with pytest.raises(uproot._util._FileNotFoundError) as excinfo: + uproot.lazy(filename) assert filename in str(excinfo.value) diff --git a/tests/test_0046-histograms-bh-hist.py b/tests/test_0046-histograms-bh-hist.py index bb180869f..4960fdc86 100644 --- a/tests/test_0046-histograms-bh-hist.py +++ b/tests/test_0046-histograms-bh-hist.py @@ -6,12 +6,11 @@ import pytest import skhep_testdata -import uproot4 -import uproot4.behaviors.TProfile +import uproot def test_numpy_1d(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: values, edges = f["hpx"].to_numpy(flow=True) assert values.tolist() == [ 2.0, @@ -228,7 +227,7 @@ def test_numpy_1d(): def test_numpy_2d(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: values, xedges, yedges = f["hpxpy"].to_numpy(flow=True) assert values.tolist() == [ @@ -2180,7 +2179,7 @@ def test_numpy_2d(): def test_numpy_profile(): # python -c 'import ROOT, skhep_testdata; f = ROOT.TFile(skhep_testdata.data_path("uproot-hepdata-example.root")); h = f.Get("hprof"); h.SetErrorOption("g"); print(repr(h.GetErrorOption())); print([h.GetBinError(i) for i in range(102)])' - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: obj = f["hprof"] assert obj.axis().edges(flow=True).tolist() == [ @@ -2500,7 +2499,7 @@ def test_numpy_profile(): ] assert obj.errors( - flow=True, error_mode=uproot4.behaviors.TProfile._kERRORSPREAD + flow=True, error_mode=uproot.behaviors.TProfile._kERRORSPREAD ).tolist() == [ 0.34300708770751953, 1.0495176315307617, @@ -2607,7 +2606,7 @@ def test_numpy_profile(): ] assert obj.errors( - flow=True, error_mode=uproot4.behaviors.TProfile._kERRORSPREADI + flow=True, error_mode=uproot.behaviors.TProfile._kERRORSPREADI ).tolist() == [ 0.2425426377130359, 0.7421210342302459, @@ -2714,7 +2713,7 @@ def test_numpy_profile(): ] assert obj.errors( - flow=True, error_mode=uproot4.behaviors.TProfile._kERRORSPREADG + flow=True, error_mode=uproot.behaviors.TProfile._kERRORSPREADG ).tolist() == [ 0.7071067811865475, 0.7071067811865475, @@ -2823,23 +2822,23 @@ def test_numpy_profile(): def test_boost_1d(): boost_histogram = pytest.importorskip("boost_histogram") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: f["hpx"].to_boost() def test_boost_2d(): boost_histogram = pytest.importorskip("boost_histogram") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: f["hpxpy"].to_boost() def test_hist_1d(): hist = pytest.importorskip("hist") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: f["hpx"].to_hist() def test_hist_2d(): hist = pytest.importorskip("hist") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: f["hpxpy"].to_hist() diff --git a/tests/test_0053-parents-should-not-be-bases.py b/tests/test_0053-parents-should-not-be-bases.py index f8a159a2a..74fb6a462 100644 --- a/tests/test_0053-parents-should-not-be-bases.py +++ b/tests/test_0053-parents-should-not-be-bases.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_TRefArray(): - with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: + with uproot.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: array = t["GenJet.Particles"].array(entry_stop=1, library="np")[0] assert len(array) == 7 assert array[0].refs.tolist() == [ @@ -85,8 +85,8 @@ def test_TRefArray(): def test_awkward_TRefArray(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: assert t["GenJet.Particles"].array(entry_stop=1)[0].tolist() == [ { "fName": "", @@ -335,7 +335,7 @@ def test_awkward_TRefArray(): def test_same_names(): - with uproot4.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: + with uproot.open(skhep_testdata.data_path("uproot-issue513.root"))["Delphes"] as t: one, two = t.values(filter_name="Particle_size") assert ( one.cache_key diff --git a/tests/test_0058-detach-model-objects-from-files.py b/tests/test_0058-detach-model-objects-from-files.py index dba057217..dd106092e 100644 --- a/tests/test_0058-detach-model-objects-from-files.py +++ b/tests/test_0058-detach-model-objects-from-files.py @@ -10,18 +10,18 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_detachment(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: assert getattr(f["hpx"].file, "file_path", None) is not None assert getattr(f["hpx"].file, "source", None) is None assert getattr(f["ntuple"].file, "file_path", None) is not None assert getattr(f["ntuple"].file, "source", None) is not None - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-small-evnt-tree-nosplit.root") ) as f: array = f["tree/evt"].array(library="np", entry_stop=1) @@ -29,7 +29,7 @@ def test_detachment(): assert getattr(array[0].file, "source", None) is None assert isinstance( - f.file.streamer_named("Event").file, uproot4.reading.DetachedFile + f.file.streamer_named("Event").file, uproot.reading.DetachedFile ) assert ( str(f.file.streamer_named("Event").file_uuid) @@ -38,7 +38,7 @@ def test_detachment(): def test_copy(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: original = f["hpx"] original_file_path = original.file.file_path @@ -49,7 +49,7 @@ def test_copy(): def test_pickle(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: original = f["hpx"] original_file_path = original.file.file_path @@ -61,7 +61,7 @@ def test_pickle(): def test_pickle_boost(): boost_histogram = pytest.importorskip("boost_histogram") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: original = f["hpx"] original_boost = original.to_boost() diff --git a/tests/test_0066-fix-http-fallback-freeze.py b/tests/test_0066-fix-http-fallback-freeze.py index b406d07e6..6022e0aae 100644 --- a/tests/test_0066-fix-http-fallback-freeze.py +++ b/tests/test_0066-fix-http-fallback-freeze.py @@ -5,12 +5,12 @@ import numpy import pytest -import uproot4 +import uproot @pytest.mark.network def test(): - with uproot4.open( + with uproot.open( {"http://scikit-hep.org/uproot3/examples/HZZ.root": "events"} ) as t: t["MET_px"].array(library="np") diff --git a/tests/test_0067-common-entry-offsets.py b/tests/test_0067-common-entry-offsets.py index 1af484fe9..2e3d4440e 100644 --- a/tests/test_0067-common-entry-offsets.py +++ b/tests/test_0067-common-entry-offsets.py @@ -5,16 +5,16 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_common_offsets(): # this file has terrible branch alignment - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: assert f["ntuple;1"].common_entry_offsets() == [0, 75000] # this file has just one branch - with uproot4.open(skhep_testdata.data_path("uproot-foriter.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-foriter.root")) as f: assert f["foriter;1"].common_entry_offsets() == [ 0, 6, @@ -27,7 +27,7 @@ def test_common_offsets(): 46, ] - with uproot4.open(skhep_testdata.data_path("uproot-small-dy-nooffsets.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-small-dy-nooffsets.root")) as f: assert f["tree;1"].common_entry_offsets() == [0, 200, 400, 501] assert f["tree;1"].common_entry_offsets(["Jet_pt"]) == [0, 200, 397, 400, 501] assert f["tree;1"].common_entry_offsets(["Jet_pt", "nJet"]) == [ diff --git a/tests/test_0081-dont-parse-colons.py b/tests/test_0081-dont-parse-colons.py index 1e86fa18b..992832c9a 100644 --- a/tests/test_0081-dont-parse-colons.py +++ b/tests/test_0081-dont-parse-colons.py @@ -5,62 +5,62 @@ import pytest import skhep_testdata -import uproot4 +import uproot -pytest.importorskip("awkward1") +pytest.importorskip("awkward") def test_open(): assert isinstance( - uproot4.open(skhep_testdata.data_path("uproot-issue63.root")), - uproot4.reading.ReadOnlyDirectory, + uproot.open(skhep_testdata.data_path("uproot-issue63.root")), + uproot.reading.ReadOnlyDirectory, ) assert isinstance( - uproot4.open( + uproot.open( {skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"} ), - uproot4.behaviors.TTree.TTree, + uproot.behaviors.TTree.TTree, ) with pytest.raises(ValueError): - uproot4.open([skhep_testdata.data_path("uproot-issue63.root")]) + uproot.open([skhep_testdata.data_path("uproot-issue63.root")]) def test_lazy(): with pytest.raises(ValueError): - uproot4.lazy(skhep_testdata.data_path("uproot-issue63.root")) + uproot.lazy(skhep_testdata.data_path("uproot-issue63.root")) with pytest.raises(ValueError): - uproot4.lazy( + uproot.lazy( {skhep_testdata.data_path("uproot-issue63.root"): "blah"}, allow_missing=True, ) - uproot4.lazy({skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}) - uproot4.lazy( + uproot.lazy({skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}) + uproot.lazy( { skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal", skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_Fake_nominal", } ) - uproot4.lazy([{skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}]) - uproot4.lazy( + uproot.lazy([{skhep_testdata.data_path("uproot-issue63.root"): "WtLoop_nominal"}]) + uproot.lazy( {skhep_testdata.data_path("uproot-issue63.root") + "*": "WtLoop_nominal"} ) - uproot4.lazy( + uproot.lazy( [{skhep_testdata.data_path("uproot-issue63.root") + "*": "WtLoop_nominal"}] ) def test_concatenate(): with pytest.raises(ValueError): - uproot4.concatenate(skhep_testdata.data_path("uproot-issue63.root")) + uproot.concatenate(skhep_testdata.data_path("uproot-issue63.root")) assert ( len( - uproot4.concatenate( + uproot.concatenate( {skhep_testdata.data_path("uproot-issue63.root"): "blah"}, allow_missing=True, ) @@ -72,21 +72,21 @@ def test_concatenate(): "6.16.00", "*" ) - uproot4.concatenate(files, "Ai8") - uproot4.concatenate({files: "sample"}, "Ai8") - uproot4.concatenate([files], "Ai8") - uproot4.concatenate([{files: "sample"}], "Ai8") + uproot.concatenate(files, "Ai8") + uproot.concatenate({files: "sample"}, "Ai8") + uproot.concatenate([files], "Ai8") + uproot.concatenate([{files: "sample"}], "Ai8") def test_iterate(): with pytest.raises(ValueError): - for arrays in uproot4.iterate(skhep_testdata.data_path("uproot-issue63.root")): + for arrays in uproot.iterate(skhep_testdata.data_path("uproot-issue63.root")): pass assert ( len( list( - uproot4.iterate( + uproot.iterate( {skhep_testdata.data_path("uproot-issue63.root"): "blah"}, allow_missing=True, ) @@ -99,13 +99,13 @@ def test_iterate(): "6.16.00", "*" ) - for arrays in uproot4.iterate(files, "Ai8"): + for arrays in uproot.iterate(files, "Ai8"): pass - for arrays in uproot4.iterate({files: "sample"}, "Ai8"): + for arrays in uproot.iterate({files: "sample"}, "Ai8"): pass - for arrays in uproot4.iterate([files], "Ai8"): + for arrays in uproot.iterate([files], "Ai8"): pass - for arrays in uproot4.iterate([{files: "sample"}], "Ai8"): + for arrays in uproot.iterate([{files: "sample"}], "Ai8"): pass @@ -114,28 +114,28 @@ def test_iterate(): def test_open_colon(): assert isinstance( - uproot4.open( + uproot.open( skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal" ), - uproot4.behaviors.TTree.TTree, + uproot.behaviors.TTree.TTree, ) with pytest.raises(FileNotFoundError): - uproot4.open( + uproot.open( pathlib.Path( skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal" ) ) with pytest.raises(FileNotFoundError): - uproot4.open( + uproot.open( {skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal": None} ) def test_lazy_colon(): - uproot4.lazy(skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal") - uproot4.lazy( + uproot.lazy(skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal") + uproot.lazy( [ skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_nominal", skhep_testdata.data_path("uproot-issue63.root") + ":WtLoop_Fake_nominal", diff --git a/tests/test_0087-memberwise-splitting-not-implemented-messages.py b/tests/test_0087-memberwise-splitting-not-implemented-messages.py index 050813b5d..2177a256c 100644 --- a/tests/test_0087-memberwise-splitting-not-implemented-messages.py +++ b/tests/test_0087-memberwise-splitting-not-implemented-messages.py @@ -5,12 +5,12 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_issue510b(): with pytest.raises(NotImplementedError): - with uproot4.open(skhep_testdata.data_path("uproot-issue510b.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue510b.root"))[ "EDepSimEvents" ] as t: t["Event"]["Trajectories.Points"].array(library="np") @@ -18,7 +18,7 @@ def test_issue510b(): def test_issue403(): with pytest.raises(NotImplementedError): - with uproot4.open(skhep_testdata.data_path("uproot-issue403.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue403.root"))[ "Model" ] as t: t["Model.collimatorInfo"].array(library="np") @@ -26,7 +26,7 @@ def test_issue403(): def test_issue475(): with pytest.raises(NotImplementedError): - with uproot4.open(skhep_testdata.data_path("uproot-issue475.root"))[ + with uproot.open(skhep_testdata.data_path("uproot-issue475.root"))[ "Event/Elec/ElecEvent" ] as t: t["fElecChannels"].array(library="np") diff --git a/tests/test_0088-read-with-http.py b/tests/test_0088-read-with-http.py index 1e04d7b89..8ce742a42 100644 --- a/tests/test_0088-read-with-http.py +++ b/tests/test_0088-read-with-http.py @@ -4,12 +4,12 @@ import pytest -import uproot4 +import uproot @pytest.mark.network def test_issue176(): - with uproot4.open( + with uproot.open( "https://starterkit.web.cern.ch/starterkit/data/advanced-python-2019/dalitzdata.root" ) as f: data = f["tree/Y1"].array(library="np") @@ -18,7 +18,7 @@ def test_issue176(): @pytest.mark.network def test_issue176_again(): - with uproot4.open( + with uproot.open( "https://starterkit.web.cern.ch/starterkit/data/advanced-python-2019/dalitzdata.root" ) as f: data = f["tree"].arrays(["Y1", "Y2"], library="np") @@ -28,7 +28,7 @@ def test_issue176_again(): @pytest.mark.network def test_issue121(): - with uproot4.open( + with uproot.open( "https://github.com/CoffeaTeam/coffea/raw/master/tests/samples/nano_dy.root" ) as f: data = f["Events/MET_pt"].array(library="np") diff --git a/tests/test_0099-read-from-file-object.py b/tests/test_0099-read-from-file-object.py index 9b1a05a2b..f9158e10b 100644 --- a/tests/test_0099-read-from-file-object.py +++ b/tests/test_0099-read-from-file-object.py @@ -5,12 +5,12 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): with open(skhep_testdata.data_path("uproot-Zmumu.root"), "rb") as f: - assert uproot4.open({f: "events"})["px1"].array(library="np")[:10].tolist() == [ + assert uproot.open({f: "events"})["px1"].array(library="np")[:10].tolist() == [ -41.1952876442, 35.1180497674, 35.1180497674, diff --git a/tests/test_0112-fix-pandas-with-cut.py b/tests/test_0112-fix-pandas-with-cut.py index 70d363c16..a9e0b5991 100644 --- a/tests/test_0112-fix-pandas-with-cut.py +++ b/tests/test_0112-fix-pandas-with-cut.py @@ -6,14 +6,14 @@ import pytest import skhep_testdata -import uproot4 +import uproot pandas = pytest.importorskip("pandas") def test(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root")) as f: df = f["events"].arrays( ["px1", "pmag"], cut="pmag < 30", diff --git a/tests/test_0118-fix-name-fetch-again.py b/tests/test_0118-fix-name-fetch-again.py index 061fc3f6a..dffea1a31 100644 --- a/tests/test_0118-fix-name-fetch-again.py +++ b/tests/test_0118-fix-name-fetch-again.py @@ -5,13 +5,13 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_keys(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as t: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as t: assert t.keys(filter_name="P3.Px") == ["evt/P3/P3.Px"] assert t.keys(filter_name="/P3.Px") == [] assert t.keys(filter_name="P3/P3.Px") == [] @@ -28,9 +28,9 @@ def test_keys(): def test_numpy(): - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as t: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as t: assert list(t.arrays(filter_name="P3.Px", library="np").keys()) == ["P3.Px"] assert list(t.arrays(filter_name="/P3.Px", library="np").keys()) == [] assert list(t.arrays(filter_name="P3/P3.Px", library="np").keys()) == [] @@ -77,10 +77,10 @@ def test_numpy(): def test_awkward(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as t: + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as t: assert t.arrays(filter_name="P3.Px", library="ak").fields == ["P3.Px"] assert t.arrays(filter_name="/P3.Px", library="ak").fields == [] assert t.arrays(filter_name="P3/P3.Px", library="ak").fields == [] @@ -114,9 +114,9 @@ def test_awkward(): def test_pandas(): pandas = pytest.importorskip("pandas") - with uproot4.open( - skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root") - )["tree"] as t: + with uproot.open(skhep_testdata.data_path("uproot-small-evnt-tree-fullsplit.root"))[ + "tree" + ] as t: assert t.arrays(filter_name="P3.Px", library="pd").columns.tolist() == ["P3.Px"] assert t.arrays(filter_name="/P3.Px", library="pd").columns.tolist() == [] assert t.arrays(filter_name="P3/P3.Px", library="pd").columns.tolist() == [] diff --git a/tests/test_0123-atlas-issues.py b/tests/test_0123-atlas-issues.py index 6b7f75734..ff8365705 100644 --- a/tests/test_0123-atlas-issues.py +++ b/tests/test_0123-atlas-issues.py @@ -5,13 +5,13 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_version(): - assert uproot4.classname_decode( - uproot4.classname_encode("xAOD::MissingETAuxAssociationMap_v2") + assert uproot.classname_decode( + uproot.classname_encode("xAOD::MissingETAuxAssociationMap_v2") ) == ("xAOD::MissingETAuxAssociationMap_v2", None) - assert uproot4.classname_decode( - uproot4.classname_encode("xAOD::MissingETAuxAssociationMap_v2", 9) + assert uproot.classname_decode( + uproot.classname_encode("xAOD::MissingETAuxAssociationMap_v2", 9) ) == ("xAOD::MissingETAuxAssociationMap_v2", 9) diff --git a/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py b/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py index 1ce5ab4c0..ae728f585 100644 --- a/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py +++ b/tests/test_0126-turn-unknown-emptyarrays-into-known-types.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): - awkward1 = pytest.importorskip("awkward1") - with uproot4.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root")) as f: + awkward = pytest.importorskip("awkward") + with uproot.open(skhep_testdata.data_path("uproot-vectorVectorDouble.root")) as f: array = f["t/x"].array(entry_stop=2) - assert str(awkward1.type(array)) == "2 * var * var * float64" + assert str(awkward.type(array)) == "2 * var * var * float64" diff --git a/tests/test_0167-use-the-common-histogram-interface.py b/tests/test_0167-use-the-common-histogram-interface.py index ab8e433b9..91e52fb55 100644 --- a/tests/test_0167-use-the-common-histogram-interface.py +++ b/tests/test_0167-use-the-common-histogram-interface.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_axis(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: f["hpx"].axes[0] == f["hpx"].axis(0) == f["hpx"].axis(-1) == f["hpx"].axis("x") axis = f["hpx"].axis() assert len(axis) == 100 @@ -49,7 +49,7 @@ def test_axis(): == len(axis.widths(flow=True)) ) - with uproot4.open(skhep_testdata.data_path("uproot-issue33.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-issue33.root")) as f: f["cutflow"].axes[0] == f["cutflow"].axis(0) == f["cutflow"].axis("x") axis = f["cutflow"].axis() assert len(axis) == 7 @@ -87,7 +87,7 @@ def test_axis(): def test_bins(): - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: for i in range(2): hpx = f["hpx"] hpxpy = f["hpxpy"] @@ -111,7 +111,7 @@ def test_bins(): def test_boost(): boost_histogram = pytest.importorskip("boost_histogram") - with uproot4.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-hepdata-example.root")) as f: hpx = f["hpx"] hpxpy = f["hpxpy"] hprof = f["hprof"] @@ -133,7 +133,7 @@ def test_boost(): assert hprof.to_boost().axes[0].name == "xaxis" assert hprof.to_boost().axes[0].title == "" - with uproot4.open(skhep_testdata.data_path("uproot-issue33.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-issue33.root")) as f: assert f["cutflow"].to_boost().name == "cutflow" assert f["cutflow"].to_boost().title == "dijethad" assert f["cutflow"].to_boost().axes[0].name == "xaxis" diff --git a/tests/test_0172-allow-allocators-in-vector-typenames.py b/tests/test_0172-allow-allocators-in-vector-typenames.py index f04db07a4..620101bdc 100644 --- a/tests/test_0172-allow-allocators-in-vector-typenames.py +++ b/tests/test_0172-allow-allocators-in-vector-typenames.py @@ -5,11 +5,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): - with uproot4.open(skhep_testdata.data_path("uproot-issue-172.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-issue-172.root")) as f: t = f["events"] t.show() assert ( diff --git a/tests/test_0173-empty-and-multiprocessing-bugs.py b/tests/test_0173-empty-and-multiprocessing-bugs.py index 08f8d35ae..1928b08ba 100644 --- a/tests/test_0173-empty-and-multiprocessing-bugs.py +++ b/tests/test_0173-empty-and-multiprocessing-bugs.py @@ -7,11 +7,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test_empty(): - with uproot4.open(skhep_testdata.data_path("uproot-empty.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-empty.root")) as f: t = f["tree"] assert t["x"].array(library="np").tolist() == [] assert t["y"].array(library="np").tolist() == [] @@ -19,8 +19,8 @@ def test_empty(): def readone(filename): - with uproot4.open(filename) as f: - f.decompression_executor = uproot4.ThreadPoolExecutor() + with uproot.open(filename) as f: + f.decompression_executor = uproot.ThreadPoolExecutor() t = f["events"] b = t["px1"] b.array(library="np") diff --git a/tests/test_0182-complain-about-missing-files.py b/tests/test_0182-complain-about-missing-files.py index cfddd5157..48f9dd436 100644 --- a/tests/test_0182-complain-about-missing-files.py +++ b/tests/test_0182-complain-about-missing-files.py @@ -6,7 +6,7 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): @@ -15,12 +15,11 @@ def test(): bad = one.replace(".root", "-DOES-NOT-EXIST.root") okay = one.replace(".root", "-DOES-NOT-EXIST-*.root") - assert len(list(uproot4.iterate([one, two], step_size="1 TB", library="np"))) == 2 + assert len(list(uproot.iterate([one, two], step_size="1 TB", library="np"))) == 2 - with pytest.raises(uproot4._util._FileNotFoundError): - list(uproot4.iterate([one, two, bad], library="np")) + with pytest.raises(uproot._util._FileNotFoundError): + list(uproot.iterate([one, two, bad], library="np")) assert ( - len(list(uproot4.iterate([one, two, okay], step_size="1 TB", library="np"))) - == 2 + len(list(uproot.iterate([one, two, okay], step_size="1 TB", library="np"))) == 2 ) diff --git a/tests/test_0194-fix-lost-cuts-in-iterate.py b/tests/test_0194-fix-lost-cuts-in-iterate.py index b83f64b23..4f03a749e 100644 --- a/tests/test_0194-fix-lost-cuts-in-iterate.py +++ b/tests/test_0194-fix-lost-cuts-in-iterate.py @@ -6,11 +6,11 @@ import pytest import skhep_testdata -import uproot4 +import uproot def test(): - with uproot4.open(skhep_testdata.data_path("uproot-Zmumu.root")) as f: + with uproot.open(skhep_testdata.data_path("uproot-Zmumu.root")) as f: for arrays in f["events"].iterate( "px1", step_size=1000, cut="px1 > 0", library="np" ): diff --git a/tests/test_versions.py b/tests/test_versions.py index 97150b0c7..002135df5 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -6,7 +6,7 @@ import pytest import skhep_testdata -import uproot4 +import uproot truth = { "n": [ @@ -1152,7 +1152,7 @@ ], ) def test(version): - with uproot4.open( + with uproot.open( skhep_testdata.data_path("uproot-sample-{0}-uncompressed.root".format(version)) )["sample"] as sample: arrays = sample.arrays(sample.keys(), library="np") @@ -1160,7 +1160,7 @@ def test(version): assert set(arrays.keys()) == set(truth.keys()) for key in truth.keys(): if isinstance( - sample[key].interpretation, uproot4.interpretation.jagged.AsJagged + sample[key].interpretation, uproot.interpretation.jagged.AsJagged ): assert [row.tolist() for row in arrays[key]] == truth[key] else: diff --git a/uproot/__init__.py b/uproot/__init__.py new file mode 100644 index 000000000..b6f17443a --- /dev/null +++ b/uproot/__init__.py @@ -0,0 +1,218 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +""" +Uproot: ROOT I/O in pure Python and NumPy. + +Nearly all of the functions needed for general use are imported here, but the +documentation gives fully qualified names. For example, the most frequently +used function in Uproot is + +.. code-block:: python + + uproot.open("path/to/filename.root") + +but we refer to it in the documentation as :py:func:`~uproot.reading.open`. + +Typical entry points for file-reading are + +* :py:func:`~uproot.reading.open` +* :py:func:`~uproot.behaviors.TBranch.iterate` +* :py:func:`~uproot.behaviors.TBranch.concatenate` +* :py:func:`~uproot.behaviors.TBranch.lazy` + +though they would usually be accessed as ``uproot.iterate``, +``uproot.concatenate``, and ``uproot.lazy``. + +The most useful classes are + +* :py:class:`~uproot.behaviors.TBranch.HasBranches` (``TTree`` or ``TBranch``) +* :py:class:`~uproot.behaviors.TBranch.TBranch` +* :py:class:`~uproot.behaviors.TH1` +* :py:class:`~uproot.behaviors.TH2` +* :py:class:`~uproot.behaviors.TProfile` + +though they would usually be accessed through instances that have been read +from files. + +The submodules of Uproot are: + +* :py:mod:`uproot.reading`: entry-point for reading files, as well as classes + for the three basic types that can't be modeled: ``TFile``, ``TDirectory``, + and ``TKey``. +* :py:mod:`uproot.behaviors`: methods and properties to mix into instantiated + models, for a high-level user interface. +* :py:mod:`uproot.model`: utilities for modeling C++ objects as Python objects. +* :py:mod:`uproot.streamers`: models for ``TStreamerInfo`` and its elements + to generate code for new models for classes in ROOT files. +* :py:mod:`uproot.cache`: defines caches with least-recently used eviction + policies. +* :py:mod:`uproot.compression`: functions for compressing and decompressing data. +* :py:mod:`uproot.deserialization`: utility functions for deserialization, + including the generation of new classes. +* :py:mod:`uproot.source`: the "physical layer," which reads bytes without + interpreting them from various backends, like files, HTTP(S), and XRootD. +* :py:mod:`uproot.interpretation`: prescriptions for converting ROOT types + into Pythonic arrays. +* :py:mod:`uproot.containers`: interpretations and models for standard + containers, such as ``std::vector`` and arrays. +* :py:mod:`uproot.language`: computational backends for expressions in + :py:mod:`uproot.behavior.TBranch.HasBranches.arrays`. +* :py:mod:`uproot.models`: predefined models for classes that are too basic + to rely on ``TStreamerInfo`` or too common to justify reading it. +* :py:mod:`uproot.const`: integer constants used in ROOT serialization and + deserialization. +* :py:mod:`uproot.extras`: import functions for the libraries that Uproot can + use, but does not require as dependencies. If a library can't be imported, + these functions provide instructions for installing them. +* :py:mod:`uproot.version`: for access to the version number. +* :py:mod:`uproot.dynamic`: initially empty module, in which dynamically + generated classes are defined. +* :py:mod:`uproot._util`: non-public utilities used by the above. +""" + +from __future__ import absolute_import + +from uproot.version import __version__ + +import uproot.dynamic + +classes = {} +unknown_classes = {} + +import uproot.extras + +from uproot.cache import LRUCache +from uproot.cache import LRUArrayCache + +from uproot.source.file import MemmapSource +from uproot.source.file import MultithreadedFileSource +from uproot.source.http import HTTPSource +from uproot.source.http import MultithreadedHTTPSource +from uproot.source.xrootd import XRootDSource +from uproot.source.xrootd import MultithreadedXRootDSource +from uproot.source.object import ObjectSource +from uproot.source.cursor import Cursor +from uproot.source.futures import TrivialExecutor +from uproot.source.futures import ThreadPoolExecutor +from uproot.deserialization import DeserializationError + +from uproot.compression import ZLIB +from uproot.compression import LZMA +from uproot.compression import LZ4 +from uproot.compression import ZSTD + +from uproot.reading import open +from uproot.reading import ReadOnlyFile +from uproot.reading import ReadOnlyDirectory + +from uproot.exceptions import KeyInFileError + +from uproot.model import Model +from uproot.model import classname_decode +from uproot.model import classname_encode +from uproot.model import has_class_named +from uproot.model import class_named +from uproot.model import reset_classes + +import uproot.models.TObject +import uproot.models.TString +import uproot.models.TArray +import uproot.models.TNamed +import uproot.models.TList +import uproot.models.THashList +import uproot.models.TObjArray +import uproot.models.TObjString +import uproot.models.TAtt +import uproot.models.TRef + +import uproot.models.TTree +import uproot.models.TBranch +import uproot.models.TLeaf +import uproot.models.TBasket +import uproot.models.RNTuple + +from uproot.containers import STLVector +from uproot.containers import STLSet +from uproot.containers import STLMap + +import uproot.interpretation +import uproot.interpretation.identify +import uproot.interpretation.library +from uproot.interpretation.numerical import AsDtype +from uproot.interpretation.numerical import AsDtypeInPlace +from uproot.interpretation.numerical import AsDouble32 +from uproot.interpretation.numerical import AsFloat16 +from uproot.interpretation.numerical import AsSTLBits +from uproot.interpretation.jagged import AsJagged +from uproot.interpretation.strings import AsStrings +from uproot.interpretation.objects import AsObjects +from uproot.interpretation.objects import AsStridedObjects +from uproot.interpretation.grouped import AsGrouped +from uproot.containers import AsString +from uproot.containers import AsPointer +from uproot.containers import AsArray +from uproot.containers import AsDynamic +from uproot.containers import AsVector +from uproot.containers import AsSet +from uproot.containers import AsMap + +default_library = "ak" + +from uproot.behaviors.TTree import TTree +from uproot.behaviors.TBranch import TBranch +from uproot.behaviors.TBranch import iterate +from uproot.behaviors.TBranch import concatenate +from uproot.behaviors.TBranch import lazy + +import pkgutil +import uproot.behaviors + + +def behavior_of(classname): + """ + Finds and loads the behavior class for C++ (decoded) classname or returns + None if there isn't one. + + Behaviors do not have a required base class, and they may be used with + Awkward Array's ``ak.behavior``. + + The search strategy for finding behavior classes is: + + 1. Translate the ROOT class name from C++ to Python with + :py:func:`~uproot.model.classname_encode`. For example, + ``"ROOT::RThing"`` becomes ``"Model_ROOT_3a3a_RThing"``. + 2. Look for a submodule of ``uproot.behaviors`` without + the ``"Model_"`` prefix. For example, ``"ROOT_3a3a_RThing"``. + 3. Look for a class in that submodule with the fully encoded + name. For example, ``"Model_ROOT_3a3a_RThing"``. + + See :py:mod:`uproot.behaviors` for details. + """ + name = classname_encode(classname) + assert name.startswith("Model_") + name = name[6:] + + if name not in globals(): + if name in behavior_of._module_names: + exec( + compile( + "import uproot.behaviors.{0}".format(name), "", "exec" + ), + globals(), + ) + module = eval("uproot.behaviors.{0}".format(name)) + behavior_cls = getattr(module, name, None) + if behavior_cls is not None: + globals()[name] = behavior_cls + + return globals().get(name) + + +behavior_of._module_names = [ + module_name + for loader, module_name, is_pkg in pkgutil.walk_packages(uproot.behaviors.__path__) +] + +del pkgutil + +from uproot._util import no_filter diff --git a/uproot4/_util.py b/uproot/_util.py similarity index 75% rename from uproot4/_util.py rename to uproot/_util.py index e8197f957..ffd7384ad 100644 --- a/uproot4/_util.py +++ b/uproot/_util.py @@ -188,7 +188,7 @@ def file_object_path_split(path): def file_path_to_source_class(file_path, options): - import uproot4.source.chunk + import uproot.source.chunk file_path = regularize_path(file_path) @@ -198,7 +198,7 @@ def file_path_to_source_class(file_path, options): and hasattr(file_path, "seek") ): out = options["object_handler"] - if not (isinstance(out, type) and issubclass(out, uproot4.source.chunk.Source)): + if not (isinstance(out, type) and issubclass(out, uproot.source.chunk.Source)): raise TypeError( "'object_handler' is not a class object inheriting from Source: " + repr(out) @@ -233,7 +233,7 @@ def file_path_to_source_class(file_path, options): file_path = windows_absolute_path out = options["file_handler"] - if not (isinstance(out, type) and issubclass(out, uproot4.source.chunk.Source)): + if not (isinstance(out, type) and issubclass(out, uproot.source.chunk.Source)): raise TypeError( "'file_handler' is not a class object inheriting from Source: " + repr(out) @@ -242,7 +242,7 @@ def file_path_to_source_class(file_path, options): elif parsed_url.scheme.upper() == "ROOT": out = options["xrootd_handler"] - if not (isinstance(out, type) and issubclass(out, uproot4.source.chunk.Source)): + if not (isinstance(out, type) and issubclass(out, uproot.source.chunk.Source)): raise TypeError( "'xrootd_handler' is not a class object inheriting from Source: " + repr(out) @@ -251,7 +251,7 @@ def file_path_to_source_class(file_path, options): elif parsed_url.scheme.upper() == "HTTP" or parsed_url.scheme.upper() == "HTTPS": out = options["http_handler"] - if not (isinstance(out, type) and issubclass(out, uproot4.source.chunk.Source)): + if not (isinstance(out, type) and issubclass(out, uproot.source.chunk.Source)): raise TypeError( "'http_handler' is not a class object inheriting from Source: " + repr(out) @@ -295,7 +295,7 @@ def _file_not_found(files, message=None): object-within-ROOT path), regardless of whether there are any colons. Examples: Path("rel:/file.root"), Path("/abs/path:stuff.root") -Functions that accept many files (uproot4.iterate, etc.) also allow: +Functions that accept many files (uproot.iterate, etc.) also allow: * glob syntax in str/bytes and pathlib.Path. Examples: Path("rel/*.root"), "/abs/*.root:tdirectory/ttree" * dict: keys are filesystem paths, values are objects-within-ROOT paths. @@ -368,11 +368,11 @@ def memory_size(data, error_message=None): def new_class(name, bases, members): - import uproot4.dynamic + import uproot.dynamic out = type(ensure_str(name), bases, members) - out.__module__ = "uproot4.dynamic" - setattr(uproot4.dynamic, out.__name__, out) + out.__module__ = "uproot.dynamic" + setattr(uproot.dynamic, out.__name__, out) return out @@ -380,42 +380,38 @@ def new_class(name, bases, members): def awkward_form(model, file, index_format="i64", header=False, tobject_header=True): - import awkward1 + import uproot + + awkward = uproot.extras.awkward() if isinstance(model, numpy.dtype): model = model.newbyteorder("=") if model not in _primitive_awkward_form: if model == numpy.dtype(numpy.bool_) or model == numpy.dtype(numpy.bool): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"bool"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"bool"') elif model == numpy.dtype(numpy.int8): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"int8"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int8"') elif model == numpy.dtype(numpy.uint8): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"uint8"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint8"') elif model == numpy.dtype(numpy.int16): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"int16"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int16"') elif model == numpy.dtype(numpy.uint16): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson( - '"uint16"' - ) + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint16"') elif model == numpy.dtype(numpy.int32): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"int32"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int32"') elif model == numpy.dtype(numpy.uint32): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson( - '"uint32"' - ) + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint32"') elif model == numpy.dtype(numpy.int64): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson('"int64"') + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"int64"') elif model == numpy.dtype(numpy.uint64): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson( - '"uint64"' - ) + _primitive_awkward_form[model] = awkward.forms.Form.fromjson('"uint64"') elif model == numpy.dtype(numpy.float32): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson( + _primitive_awkward_form[model] = awkward.forms.Form.fromjson( '"float32"' ) elif model == numpy.dtype(numpy.float64): - _primitive_awkward_form[model] = awkward1.forms.Form.fromjson( + _primitive_awkward_form[model] = awkward.forms.Form.fromjson( '"float64"' ) else: @@ -427,98 +423,98 @@ def awkward_form(model, file, index_format="i64", header=False, tobject_header=T return model.awkward_form(file, index_format, header, tobject_header) -def awkward_form_remove_uproot(awkward1, form): +def awkward_form_remove_uproot(awkward, form): parameters = dict(form.parameters) parameters.pop("uproot", None) - if isinstance(form, awkward1.forms.BitMaskedForm): - return awkward1.forms.BitMaskedForm( + if isinstance(form, awkward.forms.BitMaskedForm): + return awkward.forms.BitMaskedForm( form.mask, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.valid_when, form.lsb_order, form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.ByteMaskedForm): - return awkward1.forms.ByteMaskedForm( + elif isinstance(form, awkward.forms.ByteMaskedForm): + return awkward.forms.ByteMaskedForm( form.mask, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.valid_when, form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.EmptyForm): - return awkward1.forms.EmptyForm(form.has_identities, parameters,) - elif isinstance(form, awkward1.forms.IndexedForm): - return awkward1.forms.IndexedForm( + elif isinstance(form, awkward.forms.EmptyForm): + return awkward.forms.EmptyForm(form.has_identities, parameters,) + elif isinstance(form, awkward.forms.IndexedForm): + return awkward.forms.IndexedForm( form.index, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.IndexedOptionForm): - return awkward1.forms.IndexedOptionForm( + elif isinstance(form, awkward.forms.IndexedOptionForm): + return awkward.forms.IndexedOptionForm( form.index, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.ListForm): - return awkward1.forms.ListForm( + elif isinstance(form, awkward.forms.ListForm): + return awkward.forms.ListForm( form.starts, form.stops, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.ListOffsetForm): - return awkward1.forms.ListOffsetForm( + elif isinstance(form, awkward.forms.ListOffsetForm): + return awkward.forms.ListOffsetForm( form.offsets, - awkward_form_remove_uproot(awkward1, form.content), + awkward_form_remove_uproot(awkward, form.content), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.NumpyForm): - return awkward1.forms.NumpyForm( + elif isinstance(form, awkward.forms.NumpyForm): + return awkward.forms.NumpyForm( form.inner_shape, form.itemsize, form.format, form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.RecordForm): - return awkward1.forms.RecordForm( + elif isinstance(form, awkward.forms.RecordForm): + return awkward.forms.RecordForm( dict( - (k, awkward_form_remove_uproot(awkward1, v)) + (k, awkward_form_remove_uproot(awkward, v)) for k, v in form.contents.items() ), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.RegularForm): - return awkward1.forms.RegularForm( - awkward_form_remove_uproot(awkward1, form.content), + elif isinstance(form, awkward.forms.RegularForm): + return awkward.forms.RegularForm( + awkward_form_remove_uproot(awkward, form.content), form.size, form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.UnionForm): - return awkward1.forms.UnionForm( + elif isinstance(form, awkward.forms.UnionForm): + return awkward.forms.UnionForm( form.tags, form.index, - [awkward_form_remove_uproot(awkward1, x) for x in form.contents], + [awkward_form_remove_uproot(awkward, x) for x in form.contents], form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.UnmaskedForm): - return awkward1.forms.UnmaskedForm( - awkward_form_remove_uproot(awkward1, form.content), + elif isinstance(form, awkward.forms.UnmaskedForm): + return awkward.forms.UnmaskedForm( + awkward_form_remove_uproot(awkward, form.content), form.has_identities, parameters, ) - elif isinstance(form, awkward1.forms.VirtualForm): - return awkward1.forms.VirtualForm( - awkward_form_remove_uproot(awkward1, form.form), + elif isinstance(form, awkward.forms.VirtualForm): + return awkward.forms.VirtualForm( + awkward_form_remove_uproot(awkward, form.form), form.has_length, form.has_identities, parameters, @@ -530,56 +526,56 @@ def awkward_form_remove_uproot(awkward1, form): # FIXME: Until we get Awkward reading these bytes directly, rather than # going through ak.from_iter, the integer dtypes will be int64 and the # floating dtypes will be float64 because that's what ak.from_iter makes. -def awkward_form_of_iter(awkward1, form): - if isinstance(form, awkward1.forms.BitMaskedForm): - return awkward1.forms.BitMaskedForm( +def awkward_form_of_iter(awkward, form): + if isinstance(form, awkward.forms.BitMaskedForm): + return awkward.forms.BitMaskedForm( form.mask, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.valid_when, form.lsb_order, form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.ByteMaskedForm): - return awkward1.forms.ByteMaskedForm( + elif isinstance(form, awkward.forms.ByteMaskedForm): + return awkward.forms.ByteMaskedForm( form.mask, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.valid_when, form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.EmptyForm): - return awkward1.forms.EmptyForm(form.has_identities, form.parameters,) - elif isinstance(form, awkward1.forms.IndexedForm): - return awkward1.forms.IndexedForm( + elif isinstance(form, awkward.forms.EmptyForm): + return awkward.forms.EmptyForm(form.has_identities, form.parameters,) + elif isinstance(form, awkward.forms.IndexedForm): + return awkward.forms.IndexedForm( form.index, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.IndexedOptionForm): - return awkward1.forms.IndexedOptionForm( + elif isinstance(form, awkward.forms.IndexedOptionForm): + return awkward.forms.IndexedOptionForm( form.index, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.ListForm): - return awkward1.forms.ListForm( + elif isinstance(form, awkward.forms.ListForm): + return awkward.forms.ListForm( form.starts, form.stops, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.ListOffsetForm): - return awkward1.forms.ListOffsetForm( + elif isinstance(form, awkward.forms.ListOffsetForm): + return awkward.forms.ListOffsetForm( form.offsets, - awkward_form_of_iter(awkward1, form.content), + awkward_form_of_iter(awkward, form.content), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.NumpyForm): + elif isinstance(form, awkward.forms.NumpyForm): if form.parameter("__array__") in ("char", "byte"): f = form else: @@ -588,8 +584,8 @@ def awkward_form_of_iter(awkward1, form): d = numpy.dtype(numpy.int64) elif issubclass(d.type, numpy.floating): d = numpy.dtype(numpy.float64) - f = awkward1.forms.Form.from_numpy(d) - out = awkward1.forms.NumpyForm( + f = awkward.forms.Form.from_numpy(d) + out = awkward.forms.NumpyForm( form.inner_shape, f.itemsize, f.format, @@ -597,38 +593,38 @@ def awkward_form_of_iter(awkward1, form): form.parameters, ) return out - elif isinstance(form, awkward1.forms.RecordForm): - return awkward1.forms.RecordForm( + elif isinstance(form, awkward.forms.RecordForm): + return awkward.forms.RecordForm( dict( - (k, awkward_form_of_iter(awkward1, v)) for k, v in form.contents.items() + (k, awkward_form_of_iter(awkward, v)) for k, v in form.contents.items() ), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.RegularForm): - return awkward1.forms.RegularForm( - awkward_form_of_iter(awkward1, form.content), + elif isinstance(form, awkward.forms.RegularForm): + return awkward.forms.RegularForm( + awkward_form_of_iter(awkward, form.content), form.size, form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.UnionForm): - return awkward1.forms.UnionForm( + elif isinstance(form, awkward.forms.UnionForm): + return awkward.forms.UnionForm( form.tags, form.index, - [awkward_form_of_iter(awkward1, x) for x in form.contents], + [awkward_form_of_iter(awkward, x) for x in form.contents], form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.UnmaskedForm): - return awkward1.forms.UnmaskedForm( - awkward_form_of_iter(awkward1, form.content), + elif isinstance(form, awkward.forms.UnmaskedForm): + return awkward.forms.UnmaskedForm( + awkward_form_of_iter(awkward, form.content), form.has_identities, form.parameters, ) - elif isinstance(form, awkward1.forms.VirtualForm): - return awkward1.forms.VirtualForm( - awkward_form_of_iter(awkward1, form.form), + elif isinstance(form, awkward.forms.VirtualForm): + return awkward.forms.VirtualForm( + awkward_form_of_iter(awkward, form.form), form.has_length, form.has_identities, form.parameters, diff --git a/uproot4/behaviors/TAxis.py b/uproot/behaviors/TAxis.py similarity index 100% rename from uproot4/behaviors/TAxis.py rename to uproot/behaviors/TAxis.py diff --git a/uproot4/behaviors/TBranch.py b/uproot/behaviors/TBranch.py similarity index 84% rename from uproot4/behaviors/TBranch.py rename to uproot/behaviors/TBranch.py index 789094852..5fdac419d 100644 --- a/uproot4/behaviors/TBranch.py +++ b/uproot/behaviors/TBranch.py @@ -1,13 +1,13 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines behaviors for :py:class:`~uproot4.behaviors.TBranch.TBranch` and -:py:class:`~uproot4.behaviors.TBranch.HasBranches` (both ``TBranch`` and +Defines behaviors for :py:class:`~uproot.behaviors.TBranch.TBranch` and +:py:class:`~uproot.behaviors.TBranch.HasBranches` (both ``TBranch`` and ``TTree``). Most of the functionality of TTree-reading is implemented here. -See :py:class:`~uproot4.models.TBranch` for deserialization of the ``TBranch`` +See :py:class:`~uproot.models.TBranch` for deserialization of the ``TBranch`` objects themselves. """ @@ -39,21 +39,9 @@ import numpy -import uproot4.cache -import uproot4.source.cursor -import uproot4.streamers -import uproot4.containers -import uproot4.interpretation -import uproot4.interpretation.numerical -import uproot4.interpretation.jagged -import uproot4.interpretation.library -import uproot4.interpretation.identify -import uproot4.reading -import uproot4.language.python -import uproot4.models.TBasket -import uproot4.models.TObjArray -import uproot4._util -from uproot4._util import no_filter +import uproot +import uproot.language.python +from uproot._util import no_filter class _NoClose(object): @@ -81,7 +69,7 @@ def iterate( filter_typename=no_filter, filter_branch=no_filter, aliases=None, - language=uproot4.language.python.PythonLanguage(), + language=uproot.language.python.PythonLanguage(), step_size="100 MB", decompression_executor=None, interpretation_executor=None, @@ -105,19 +93,19 @@ def iterate( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. If the function + :py:class:`~uproot.behaviors.TBranch.TBranch` object. If the function returns False or None, the ``TBranch`` is excluded; if the function returns True, it is included with its standard - :py:class:`~uproot4.behaviors.TBranch.TBranch.interpretation`; if an - :py:class:`~uproot4.interpretation.Interpretation`, this interpretation + :py:class:`~uproot.behaviors.TBranch.TBranch.interpretation`; if an + :py:class:`~uproot.interpretation.Interpretation`, this interpretation overrules the standard one. aliases (None or dict of str \u2192 str): Mathematical expressions that can be used in ``expressions`` or other aliases (without cycles). Uses the ``language`` engine to evaluate. If None, only the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.aliases` are available. - language (:py:class:`~uproot4.language.Language`): Language used to interpret + :py:attr:`~uproot.behaviors.TBranch.TBranch.aliases` are available. + language (:py:class:`~uproot.language.Language`): Language used to interpret the ``expressions`` and ``aliases``. step_size (int or str): If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size @@ -125,12 +113,12 @@ def iterate( such as "100 MB". decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, a - :py:class:`~uproot4.source.futures.TrivialExecutor` is created. + :py:class:`~uproot.source.futures.TrivialExecutor` is created. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, a :py:class:`~uproot4.source.futures.TrivialExecutor` + arrays; if None, a :py:class:`~uproot.source.futures.TrivialExecutor` is created. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. Options are ``"np"`` for NumPy, ``"ak"`` for Awkward Array, ``"pd"`` for Pandas, and ``"cp"`` for CuPy. @@ -140,11 +128,11 @@ def iterate( must be passed as ``how``, not an instance of that type (i.e. ``how=tuple``, not ``how=()``). report (bool): If True, this generator yields - (arrays, :py:class:`~uproot4.behaviors.TBranch.Report`) pairs; if False, + (arrays, :py:class:`~uproot.behaviors.TBranch.Report`) pairs; if False, it only yields arrays. The report has data about the ``TFile``, ``TTree``, and global and local entry ranges. custom_classes (None or dict): If a dict, override the classes from - the :py:class:`~uproot4.reading.ReadOnlyFile` or ``uproot4.classes``. + the :py:class:`~uproot.reading.ReadOnlyFile` or ``uproot.classes``. allow_missing (bool): If True, skip over any files that do not contain the specified ``TTree``. options: See below. @@ -155,7 +143,7 @@ def iterate( .. code-block:: python - >>> for array in uproot4.iterate("files*.root:tree", ["x", "y"], step_size=100): + >>> for array in uproot.iterate("files*.root:tree", ["x", "y"], step_size=100): ... # each of the following have 100 entries ... array["x"], array["y"] @@ -178,10 +166,10 @@ def iterate( Options (type; default): - * file_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.file.MemmapSource`) - * xrootd_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.xrootd.XRootDSource`) - * http_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.http.HTTPSource`) - * object_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.object.ObjectSource`) + * file_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.file.MemmapSource`) + * xrootd_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.xrootd.XRootDSource`) + * http_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.http.HTTPSource`) + * object_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.object.ObjectSource`) * timeout (float for HTTP, int for XRootD; 30) * max_num_elements (None or int; None) * num_workers (int; 1) @@ -189,24 +177,24 @@ def iterate( * begin_chunk_size (memory_size; 512) * minimal_ttree_metadata (bool; True) - See also :py:meth:`~uproot4.behavior.TBranch.HasBranches.iterate` to iterate + See also :py:meth:`~uproot.behavior.TBranch.HasBranches.iterate` to iterate within a single file. Other file entry points: - * :py:func:`~uproot4.reading.open`: opens one file to read any of its objects. - * :py:func:`~uproot4.behaviors.TBranch.iterate` (this function): iterates through + * :py:func:`~uproot.reading.open`: opens one file to read any of its objects. + * :py:func:`~uproot.behaviors.TBranch.iterate` (this function): iterates through chunks of contiguous entries in ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.concatenate`: returns a single concatenated + * :py:func:`~uproot.behaviors.TBranch.concatenate`: returns a single concatenated array from ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.lazy`: returns a lazily read array from + * :py:func:`~uproot.behaviors.TBranch.lazy`: returns a lazily read array from ``TTrees``. """ files = _regularize_files(files) decompression_executor, interpretation_executor = _regularize_executors( decompression_executor, interpretation_executor, None ) - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) global_offset = 0 for file_path, object_path in files: @@ -251,7 +239,7 @@ def concatenate( filter_typename=no_filter, filter_branch=no_filter, aliases=None, - language=uproot4.language.python.PythonLanguage(), + language=uproot.language.python.PythonLanguage(), decompression_executor=None, interpretation_executor=None, library="ak", @@ -273,28 +261,28 @@ def concatenate( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. If the function + :py:class:`~uproot.behaviors.TBranch.TBranch` object. If the function returns False or None, the ``TBranch`` is excluded; if the function returns True, it is included with its standard - :py:attr:`~uproot4.behaviors.TBranch.TBranch.interpretation`; if an - :py:class:`~uproot4.interpretation.Interpretation`, this interpretation + :py:attr:`~uproot.behaviors.TBranch.TBranch.interpretation`; if an + :py:class:`~uproot.interpretation.Interpretation`, this interpretation overrules the standard one. aliases (None or dict of str \u2192 str): Mathematical expressions that can be used in ``expressions`` or other aliases (without cycles). Uses the ``language`` engine to evaluate. If None, only the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.aliases` are available. - language (:py:class:`~uproot4.language.Language`): Language used to interpret + :py:attr:`~uproot.behaviors.TBranch.TBranch.aliases` are available. + language (:py:class:`~uproot.language.Language`): Language used to interpret the ``expressions`` and ``aliases``. decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, a - :py:class:`~uproot4.source.futures.TrivialExecutor` is created. + :py:class:`~uproot.source.futures.TrivialExecutor` is created. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, a :py:class:`~uproot4.source.futures.TrivialExecutor` + arrays; if None, a :py:class:`~uproot.source.futures.TrivialExecutor` is created. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. Options are ``"np"`` for NumPy, ``"ak"`` for Awkward Array, ``"pd"`` for Pandas, and ``"cp"`` for CuPy. @@ -304,7 +292,7 @@ def concatenate( must be passed as ``how``, not an instance of that type (i.e. ``how=tuple``, not ``how=()``). custom_classes (None or dict): If a dict, override the classes from - the :py:class:`~uproot4.reading.ReadOnlyFile` or ``uproot4.classes``. + the :py:class:`~uproot.reading.ReadOnlyFile` or ``uproot.classes``. allow_missing (bool): If True, skip over any files that do not contain the specified ``TTree``. options: See below. @@ -315,7 +303,7 @@ def concatenate( .. code-block:: python - >>> array = uproot4.concatenate("files*.root:tree", ["x", "y"]) + >>> array = uproot.concatenate("files*.root:tree", ["x", "y"]) Depending on the number of files, the number of selected ``TBranches``, and the size of your computer's memory, this function might not have enough @@ -340,10 +328,10 @@ def concatenate( Options (type; default): - * file_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.file.MemmapSource`) - * xrootd_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.xrootd.XRootDSource`) - * http_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.http.HTTPSource`) - * object_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.object.ObjectSource`) + * file_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.file.MemmapSource`) + * xrootd_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.xrootd.XRootDSource`) + * http_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.http.HTTPSource`) + * object_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.object.ObjectSource`) * timeout (float for HTTP, int for XRootD; 30) * max_num_elements (None or int; None) * num_workers (int; 1) @@ -353,19 +341,19 @@ def concatenate( Other file entry points: - * :py:func:`~uproot4.reading.open`: opens one file to read any of its objects. - * :py:func:`~uproot4.behaviors.TBranch.iterate`: iterates through chunks of + * :py:func:`~uproot.reading.open`: opens one file to read any of its objects. + * :py:func:`~uproot.behaviors.TBranch.iterate`: iterates through chunks of contiguous entries in ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.concatenate` (this function): returns a + * :py:func:`~uproot.behaviors.TBranch.concatenate` (this function): returns a single concatenated array from ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.lazy`: returns a lazily read array from + * :py:func:`~uproot.behaviors.TBranch.lazy`: returns a lazily read array from ``TTrees``. """ files = _regularize_files(files) decompression_executor, interpretation_executor = _regularize_executors( decompression_executor, interpretation_executor, None ) - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) all_arrays = [] global_start = 0 @@ -421,13 +409,13 @@ def lazy( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. If the function + :py:class:`~uproot.behaviors.TBranch.TBranch` object. If the function returns False or None, the ``TBranch`` is excluded; if the function returns True, it is included with its standard - :py:attr:`~uproot4.behaviors.TBranch.TBranch.interpretation`; if an - :py:class:`~uproot4.interpretation.Interpretation`, this interpretation + :py:attr:`~uproot.behaviors.TBranch.TBranch.interpretation`; if an + :py:class:`~uproot.interpretation.Interpretation`, this interpretation overrules the standard one. recursive (bool): If True, include all subbranches of branches as separate fields; otherwise, only search one level deep. @@ -440,19 +428,19 @@ def lazy( such as "100 MB". decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, a - :py:class:`~uproot4.source.futures.TrivialExecutor` is created. + :py:class:`~uproot.source.futures.TrivialExecutor` is created. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, a :py:class:`~uproot4.source.futures.TrivialExecutor` + arrays; if None, a :py:class:`~uproot.source.futures.TrivialExecutor` is created. array_cache (None, MutableMapping, or memory size): Cache of arrays; if None, do not use a cache; if a memory size, create a new cache of this size. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. For lazy arrays, only ``"ak"`` for Awkward Array is allowed. custom_classes (None or dict): If a dict, override the classes from - the :py:class:`~uproot4.reading.ReadOnlyFile` or ``uproot4.classes``. + the :py:class:`~uproot.reading.ReadOnlyFile` or ``uproot.classes``. allow_missing (bool): If True, skip over any files that do not contain the specified ``TTree``. options: See below. @@ -464,7 +452,7 @@ def lazy( .. code-block:: python - >>> lazyarray = uproot4.lazy("files*.root:tree") + >>> lazyarray = uproot.lazy("files*.root:tree") >>> # all files*.root have been opened and the "tree" from each is examined >>> lazyarray @@ -479,7 +467,7 @@ def lazy( If the size of the fields used in a calculation do not fit into ``array_cache``, lazy arrays may be inefficient, repeatedly rereading data that could be read once by iterating through the calculation with - :py:func:`~uproot4.behavior.TBranch.iterate`. + :py:func:`~uproot.behavior.TBranch.iterate`. Allowed types for the ``files`` parameter: @@ -500,10 +488,10 @@ def lazy( Options (type; default): - * file_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.file.MemmapSource`) - * xrootd_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.xrootd.XRootDSource`) - * http_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.http.HTTPSource`) - * object_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.object.ObjectSource`) + * file_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.file.MemmapSource`) + * xrootd_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.xrootd.XRootDSource`) + * http_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.http.HTTPSource`) + * object_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.object.ObjectSource`) * timeout (float for HTTP, int for XRootD; 30) * max_num_elements (None or int; None) * num_workers (int; 1) @@ -513,32 +501,31 @@ def lazy( Other file entry points: - * :py:func:`~uproot4.reading.open`: opens one file to read any of its objects. - * :py:func:`~uproot4.behaviors.TBranch.iterate`: iterates through chunks of + * :py:func:`~uproot.reading.open`: opens one file to read any of its objects. + * :py:func:`~uproot.behaviors.TBranch.iterate`: iterates through chunks of contiguous entries in ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.concatenate`: returns a single + * :py:func:`~uproot.behaviors.TBranch.concatenate`: returns a single concatenated array from ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.lazy` (this function): returns a lazily + * :py:func:`~uproot.behaviors.TBranch.lazy` (this function): returns a lazily read array from ``TTrees``. """ - import awkward1 - + awkward = uproot.extras.awkward() files = _regularize_files(files) decompression_executor, interpretation_executor = _regularize_executors( decompression_executor, interpretation_executor, None ) array_cache = _regularize_array_cache(array_cache, None) - library = uproot4.interpretation.library._regularize_library_lazy(library) + library = uproot.interpretation.library._regularize_library_lazy(library) hold_cache = array_cache if array_cache is not None and not isinstance( - array_cache, awkward1.layout.ArrayCache + array_cache, awkward.layout.ArrayCache ): if type(array_cache) is dict: hold_cache = _WrapDict(array_cache) if not isinstance(hold_cache, MutableMapping): raise TypeError("array_cache must be None or a MutableMapping") - array_cache = awkward1.layout.ArrayCache(hold_cache) + array_cache = awkward.layout.ArrayCache(hold_cache) real_options = dict(options) if "num_workers" not in real_options: @@ -546,7 +533,7 @@ def lazy( if "num_fallback_workers" not in real_options: real_options["num_fallback_workers"] = 1 - filter_branch = uproot4._util.regularize_filter(filter_branch) + filter_branch = uproot._util.regularize_filter(filter_branch) hasbranches = [] common_keys = None @@ -634,7 +621,7 @@ def real_filter_branch(branch): obj, step_size, entry_start, entry_stop, branchid_interpretation ) - for start in uproot4._util.range(entry_start, entry_stop, entry_step): + for start in uproot._util.range(entry_start, entry_stop, entry_step): stop = min(start + entry_step, entry_stop) length = stop - start @@ -645,13 +632,13 @@ def real_filter_branch(branch): interpretation = branchid_interpretation[branch.cache_key] form = interpretation.awkward_form(obj.file, index_format="i64") - if isinstance(interpretation, uproot4.interpretation.objects.AsObjects): - if not uproot4.interpretation.objects.awkward_can_optimize( + if isinstance(interpretation, uproot.interpretation.objects.AsObjects): + if not uproot.interpretation.objects.awkward_can_optimize( interpretation, form ): - form = uproot4._util.awkward_form_of_iter(awkward1, form) + form = uproot._util.awkward_form_of_iter(awkward, form) - generator = awkward1.layout.ArrayGenerator( + generator = awkward.layout.ArrayGenerator( branch.array, ( None, @@ -663,8 +650,8 @@ def real_filter_branch(branch): "ak", ), {}, - uproot4._util.awkward_form_remove_uproot( - awkward1, form + uproot._util.awkward_form_remove_uproot( + awkward, form ), # , interpretation length, ) @@ -676,26 +663,26 @@ def real_filter_branch(branch): library.name, ) global_cache_key.append(cache_key) - virtualarray = awkward1.layout.VirtualArray( + virtualarray = awkward.layout.VirtualArray( generator, cache=array_cache, cache_key=cache_key ) fields.append(virtualarray) names.append(key) - recordarray = awkward1.layout.RecordArray(fields, names, length) + recordarray = awkward.layout.RecordArray(fields, names, length) partitions.append(recordarray) global_offsets.append(global_offsets[-1] + length) - out = awkward1.partition.IrregularlyPartitionedArray(partitions, global_offsets[1:]) - return awkward1.Array(out) + out = awkward.partition.IrregularlyPartitionedArray(partitions, global_offsets[1:]) + return awkward.Array(out) class Report(object): """ Args: - source (:py:class:`~uproot4.behaviors.TBranch.HasBranches`): The - object (:py:class:`~uproot4.behaviors.TBranch.TBranch` or - :py:class:`~uproot4.behaviors.TTree.TTree`) that this batch of data + source (:py:class:`~uproot.behaviors.TBranch.HasBranches`): The + object (:py:class:`~uproot.behaviors.TBranch.TBranch` or + :py:class:`~uproot.behaviors.TTree.TTree`) that this batch of data came from. tree_entry_start (int): First entry in the batch, counting zero at the start of the current ``TTree`` (current file). @@ -703,22 +690,22 @@ class Report(object): one), counting zero at the start of the ``TTree`` (current file). global_offset (int): Number of entries between the start of iteration and the start of this ``TTree``. The - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_start` and - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_stop` are - equal to :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_start` - and :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_stop` plus + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_start` and + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_stop` are + equal to :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_start` + and :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_stop` plus ``global_offset``. Information about the current iteration of - :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` (the method) or - :py:func:`~uproot4.behaviors.TBranch.iterate` (the function). + :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate` (the method) or + :py:func:`~uproot.behaviors.TBranch.iterate` (the function). - Since the :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate` method + Since the :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate` method only iterates over data from one ``TTree``, its ``global_offset`` is always - zero; :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_start` and - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_stop` are equal to - :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_start` and - :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_stop`, respectively. + zero; :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_start` and + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_stop` are equal to + :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_start` and + :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_stop`, respectively. """ @@ -738,8 +725,8 @@ def __repr__(self): @property def source(self): """ - The object (:py:class:`~uproot4.behaviors.TBranch.TBranch` or - :py:class:`~uproot4.behaviors.TTree.TTree`) that this batch of data + The object (:py:class:`~uproot.behaviors.TBranch.TBranch` or + :py:class:`~uproot.behaviors.TTree.TTree`) that this batch of data came from. """ return self._source @@ -747,7 +734,7 @@ def source(self): @property def tree(self): """ - The :py:class:`~uproot4.behaviors.TTree.TTree` that this batch of data + The :py:class:`~uproot.behaviors.TTree.TTree` that this batch of data came from. """ return self._source.tree @@ -755,7 +742,7 @@ def tree(self): @property def file(self): """ - The :py:class:`~uproot4.reading.ReadOnlyFile` that this batch of data + The :py:class:`~uproot.reading.ReadOnlyFile` that this batch of data came from. """ return self._source.file @@ -763,7 +750,7 @@ def file(self): @property def file_path(self): """ - The path/name of the :py:class:`~uproot4.reading.ReadOnlyFile` that + The path/name of the :py:class:`~uproot.reading.ReadOnlyFile` that this batch of data came from. """ return self._source.file.file_path @@ -804,7 +791,7 @@ def global_entry_stop(self): def start(self): """ A synonym for - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_start`. + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_start`. """ return self._tree_entry_start + self._global_offset @@ -812,7 +799,7 @@ def start(self): def stop(self): """ A synonym for - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_stop`. + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_stop`. """ return self._tree_entry_stop + self._global_offset @@ -821,19 +808,19 @@ def global_offset(self): """ Number of entries between the start of iteration and the start of this ``TTree``. The - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_start` and - :py:attr:`~uproot4.behaviors.TBranch.Report.global_entry_stop` are - equal to :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_start` - and :py:attr:`~uproot4.behaviors.TBranch.Report.tree_entry_stop` plus + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_start` and + :py:attr:`~uproot.behaviors.TBranch.Report.global_entry_stop` are + equal to :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_start` + and :py:attr:`~uproot.behaviors.TBranch.Report.tree_entry_stop` plus ``global_offset``. """ return self._global_offset def to_global(self, global_offset): """ - Copies the data in this :py:class:`~uproot4.branches.TBranch.Report` to + Copies the data in this :py:class:`~uproot.branches.TBranch.Report` to another with a new - :py:attr:`~uproot4.branches.TBranch.Report.global_offset`. + :py:attr:`~uproot.branches.TBranch.Report.global_offset`. """ return Report( self._source, self._tree_entry_start, self._tree_entry_stop, global_offset @@ -843,11 +830,11 @@ def to_global(self, global_offset): class HasBranches(Mapping): """ Abstract class of behaviors for anything that "has branches," namely - :py:class:`~uproot4.behavior.TTree.TTree` and - :py:class:`~uproot4.behavior.TBranch.TBranch`, which mostly consist of array-reading + :py:class:`~uproot.behavior.TTree.TTree` and + :py:class:`~uproot.behavior.TBranch.TBranch`, which mostly consist of array-reading methods. - A :py:class:`~uproot4.behavior.TBranch.HasBranches` is a Python ``Mapping``, which + A :py:class:`~uproot.behavior.TBranch.HasBranches` is a Python ``Mapping``, which uses square bracket syntax to extract subbranches: .. code-block:: python @@ -861,9 +848,9 @@ class HasBranches(Mapping): @property def branches(self): """ - The list of :py:class:`~uproot4.behavior.TBranch.TBranch` directly under - this :py:class:`~uproot4.behavior.TTree.TTree` or - :py:class:`~uproot4.behavior.TBranch.TBranch` (i.e. not recursive). + The list of :py:class:`~uproot.behavior.TBranch.TBranch` directly under + this :py:class:`~uproot.behavior.TTree.TTree` or + :py:class:`~uproot.behavior.TBranch.TBranch` (i.e. not recursive). """ return self.member("fBranches") @@ -885,9 +872,9 @@ def show( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, recursively descend into the branches' branches. @@ -899,7 +886,7 @@ def show( typename_width (int): Number of characters to reserve for the C++ typenames. interpretation_width (int): Number of characters to reserve for the - :py:class:`~uproot4.interpretation.Interpretation` displays. + :py:class:`~uproot.interpretation.Interpretation` displays. stream (object with a ``write(str)`` method): Stream to write the output to. @@ -973,7 +960,7 @@ def arrays( filter_typename=no_filter, filter_branch=no_filter, aliases=None, - language=uproot4.language.python.PythonLanguage(), + language=uproot.language.python.PythonLanguage(), entry_start=None, entry_stop=None, decompression_executor=None, @@ -994,38 +981,38 @@ def arrays( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. If the function + :py:class:`~uproot.behaviors.TBranch.TBranch` object. If the function returns False or None, the ``TBranch`` is excluded; if the function returns True, it is included with its standard - :py:class:`~uproot4.behaviors.TBranch.TBranch.interpretation`; if an - :py:class:`~uproot4.interpretation.Interpretation`, this interpretation + :py:class:`~uproot.behaviors.TBranch.TBranch.interpretation`; if an + :py:class:`~uproot.interpretation.Interpretation`, this interpretation overrules the standard one. aliases (None or dict of str \u2192 str): Mathematical expressions that can be used in ``expressions`` or other aliases (without cycles). Uses the ``language`` engine to evaluate. If None, only the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.aliases` are available. - language (:py:class:`~uproot4.language.Language`): Language used to interpret + :py:attr:`~uproot.behaviors.TBranch.TBranch.aliases` are available. + language (:py:class:`~uproot.language.Language`): Language used to interpret the ``expressions`` and ``aliases``. entry_start (None or int): The first entry to include. If None, start at zero. If negative, count from the end, like a Python slice. entry_stop (None or int): The first entry to exclude (i.e. one greater than the last entry to include). If None, stop at - :py:attr:`~uproot4.behavior.TTree.TTree.num_entries`. If negative, + :py:attr:`~uproot.behavior.TTree.TTree.num_entries`. If negative, count from the end, like a Python slice. decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, the - file's :py:attr:`~uproot4.reading.ReadOnlyFile.decompression_executor` + file's :py:attr:`~uproot.reading.ReadOnlyFile.decompression_executor` is used. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, the file's :py:attr:`~uproot4.reading.ReadOnlyFile.interpretation_executor` + arrays; if None, the file's :py:attr:`~uproot.reading.ReadOnlyFile.interpretation_executor` is used. array_cache ("inherit", None, MutableMapping, or memory size): Cache of arrays; if "inherit", use the file's cache; if None, do not use a cache; if a memory size, create a new cache of this size. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. Options are ``"np"`` for NumPy, ``"ak"`` for Awkward Array, ``"pd"`` for Pandas, and ``"cp"`` for CuPy. @@ -1046,15 +1033,15 @@ def arrays( >>> my_tree["y"].array() - See also :py:meth:`~uproot4.behavior.TBranch.TBranch.array` to read a single + See also :py:meth:`~uproot.behavior.TBranch.TBranch.array` to read a single ``TBranch`` as an array. - See also :py:meth:`~uproot4.behavior.TBranch.HasBranches.iterate` to iterate over + See also :py:meth:`~uproot.behavior.TBranch.HasBranches.iterate` to iterate over the array in contiguous ranges of entries. """ keys = _keys_deep(self) if isinstance(self, TBranch) and expressions is None and len(keys) == 0: - filter_branch = uproot4._util.regularize_filter(filter_branch) + filter_branch = uproot._util.regularize_filter(filter_branch) return self.parent.arrays( expressions=expressions, cut=cut, @@ -1079,7 +1066,7 @@ def arrays( decompression_executor, interpretation_executor, self._file ) array_cache = _regularize_array_cache(array_cache, self._file) - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) def get_from_cache(branchname, interpretation): if array_cache is not None: @@ -1179,7 +1166,7 @@ def iterate( filter_typename=no_filter, filter_branch=no_filter, aliases=None, - language=uproot4.language.python.PythonLanguage(), + language=uproot.language.python.PythonLanguage(), entry_start=None, entry_stop=None, step_size="100 MB", @@ -1201,25 +1188,25 @@ def iterate( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. If the function + :py:class:`~uproot.behaviors.TBranch.TBranch` object. If the function returns False or None, the ``TBranch`` is excluded; if the function returns True, it is included with its standard - :py:attr:`~uproot4.behaviors.TBranch.TBranch.interpretation`; if an - :py:class:`~uproot4.interpretation.Interpretation`, this interpretation + :py:attr:`~uproot.behaviors.TBranch.TBranch.interpretation`; if an + :py:class:`~uproot.interpretation.Interpretation`, this interpretation overrules the standard one. aliases (None or dict of str \u2192 str): Mathematical expressions that can be used in ``expressions`` or other aliases (without cycles). Uses the ``language`` engine to evaluate. If None, only the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.aliases` are available. - language (:py:class:`~uproot4.language.Language`): Language used to interpret + :py:attr:`~uproot.behaviors.TBranch.TBranch.aliases` are available. + language (:py:class:`~uproot.language.Language`): Language used to interpret the ``expressions`` and ``aliases``. entry_start (None or int): The first entry to include. If None, start at zero. If negative, count from the end, like a Python slice. entry_stop (None or int): The first entry to exclude (i.e. one greater than the last entry to include). If None, stop at - :py:attr:`~uproot4.behavior.TTree.TTree.num_entries`. If negative, + :py:attr:`~uproot.behavior.TTree.TTree.num_entries`. If negative, count from the end, like a Python slice. step_size (int or str): If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size @@ -1227,13 +1214,13 @@ def iterate( such as "100 MB". decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, the - file's :py:attr:`~uproot4.reading.ReadOnlyFile.decompression_executor` + file's :py:attr:`~uproot.reading.ReadOnlyFile.decompression_executor` is used. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, the file's :py:attr:`~uproot4.reading.ReadOnlyFile.interpretation_executor` + arrays; if None, the file's :py:attr:`~uproot.reading.ReadOnlyFile.interpretation_executor` is used. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. Options are ``"np"`` for NumPy, ``"ak"`` for Awkward Array, ``"pd"`` for Pandas, and ``"cp"`` for CuPy. @@ -1243,7 +1230,7 @@ def iterate( must be passed as ``how``, not an instance of that type (i.e. ``how=tuple``, not ``how=()``). report (bool): If True, this generator yields - (arrays, :py:class:`~uproot4.behaviors.TBranch.Report`) pairs; if False, + (arrays, :py:class:`~uproot.behaviors.TBranch.Report`) pairs; if False, it only yields arrays. The report has data about the ``TFile``, ``TTree``, and global and local entry ranges. @@ -1257,15 +1244,15 @@ def iterate( ... # each of the following have 100 entries ... array["x"], array["y"] - See also :py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` to read + See also :py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` to read everything in a single step, without iteration. - See also :py:func:`~uproot4.behavior.TBranch.iterate` to iterate over many + See also :py:func:`~uproot.behavior.TBranch.iterate` to iterate over many files. """ keys = _keys_deep(self) if isinstance(self, TBranch) and expressions is None and len(keys) == 0: - filter_branch = uproot4._util.regularize_filter(filter_branch) + filter_branch = uproot._util.regularize_filter(filter_branch) for x in self.parent.iterate( expressions=expressions, cut=cut, @@ -1292,7 +1279,7 @@ def iterate( decompression_executor, interpretation_executor = _regularize_executors( decompression_executor, interpretation_executor, self._file ) - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) aliases = _regularize_aliases(self, aliases) ( @@ -1317,7 +1304,7 @@ def iterate( ) previous_baskets = {} - for sub_entry_start in uproot4._util.range( + for sub_entry_start in uproot._util.range( entry_start, entry_stop, entry_step ): sub_entry_stop = min(sub_entry_start + entry_step, entry_stop) @@ -1410,9 +1397,9 @@ def keys( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return the names of branches directly accessible @@ -1446,19 +1433,19 @@ def values( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return branches that are directly accessible under this object. Returns the subbranches as a list of - :py:class:`~uproot4.behavior.TBranch.TBranch`. + :py:class:`~uproot.behavior.TBranch.TBranch`. (Note: with ``recursive=False``, this is the same as - :py:attr:`~uproot4.behavior.TBranch.HasBranches.branches`.) + :py:attr:`~uproot.behavior.TBranch.HasBranches.branches`.) """ return list( self.itervalues( @@ -1483,9 +1470,9 @@ def items( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return (name, branch) pairs for branches @@ -1495,7 +1482,7 @@ def items( name as the name without modification. Returns (name, branch) pairs of the subbranches as a list of 2-tuples - of (str, :py:class:`~uproot4.behavior.TBranch.TBranch`). + of (str, :py:class:`~uproot.behavior.TBranch.TBranch`). """ return list( self.iteritems( @@ -1521,9 +1508,9 @@ def typenames( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return (name, typename) pairs for branches @@ -1559,9 +1546,9 @@ def iterkeys( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return the names of branches directly accessible @@ -1594,19 +1581,19 @@ def itervalues( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return branches that are directly accessible under this object. Returns the subbranches as an iterator over - :py:class:`~uproot4.behavior.TBranch.TBranch`. + :py:class:`~uproot.behavior.TBranch.TBranch`. (Note: with ``recursive=False``, this is the same as - :py:attr:`~uproot4.behavior.TBranch.HasBranches.branches`.) + :py:attr:`~uproot.behavior.TBranch.HasBranches.branches`.) """ for k, v in self.iteritems( filter_name=filter_name, @@ -1631,9 +1618,9 @@ def iteritems( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return (name, branch) pairs for branches @@ -1643,10 +1630,10 @@ def iteritems( name as the name without modification. Returns (name, branch) pairs of the subbranches as an iterator over - 2-tuples of (str, :py:class:`~uproot4.behavior.TBranch.TBranch`). + 2-tuples of (str, :py:class:`~uproot.behavior.TBranch.TBranch`). """ - filter_name = uproot4._util.regularize_filter(filter_name) - filter_typename = uproot4._util.regularize_filter(filter_typename) + filter_name = uproot._util.regularize_filter(filter_name) + filter_typename = uproot._util.regularize_filter(filter_typename) if filter_branch is None: filter_branch = no_filter elif callable(filter_branch): @@ -1700,9 +1687,9 @@ def itertypenames( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only return (name, typename) pairs for branches @@ -1738,7 +1725,7 @@ def num_entries_for( filter_typename=no_filter, filter_branch=no_filter, aliases=None, - language=uproot4.language.python.PythonLanguage(), + language=uproot.language.python.PythonLanguage(), entry_start=None, entry_stop=None, ): @@ -1757,21 +1744,21 @@ def num_entries_for( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. aliases (None or dict of str \u2192 str): Mathematical expressions that can be used in ``expressions`` or other aliases (without cycles). Uses the ``language`` engine to evaluate. If None, only the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.aliases` are available. - language (:py:class:`~uproot4.language.Language`): Language used to interpret + :py:attr:`~uproot.behaviors.TBranch.TBranch.aliases` are available. + language (:py:class:`~uproot.language.Language`): Language used to interpret the ``expressions`` and ``aliases``. entry_start (None or int): The first entry to include. If None, start at zero. If negative, count from the end, like a Python slice. entry_stop (None or int): The first entry to exclude (i.e. one greater than the last entry to include). If None, stop at - :py:attr:`~uproot4.behavior.TTree.TTree.num_entries`. If negative, + :py:attr:`~uproot.behavior.TTree.TTree.num_entries`. If negative, count from the end, like a Python slice. Returns an *approximate* step size as a number of entries to read @@ -1788,10 +1775,10 @@ def num_entries_for( in memory, without considering ``cuts``). This is the algorithm that - :py:meth:`~uproot4.behavior.TBranch.HasBranches.iterate` uses to convert a + :py:meth:`~uproot.behavior.TBranch.HasBranches.iterate` uses to convert a ``step_size`` expressed in memory units into a number of entries. """ - target_num_bytes = uproot4._util.memory_size(memory_size) + target_num_bytes = uproot._util.memory_size(memory_size) entry_start, entry_stop = _regularize_entries_start_stop( self.tree.num_entries, entry_start, entry_stop @@ -1829,9 +1816,9 @@ def common_entry_offsets( filter to select ``TBranches`` by name. filter_typename (None, glob string, regex string in ``"/pattern/i"`` syntax, function of str \u2192 bool, or iterable of the above): A filter to select ``TBranches`` by type. - filter_branch (None or function of :py:class:`~uproot4.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot4.interpretation.Interpretation`, or None): A + filter_branch (None or function of :py:class:`~uproot.behaviors.TBranch.TBranch` \u2192 bool, :py:class:`~uproot.interpretation.Interpretation`, or None): A filter to select ``TBranches`` using the full - :py:class:`~uproot4.behaviors.TBranch.TBranch` object. The ``TBranch`` is + :py:class:`~uproot.behaviors.TBranch.TBranch` object. The ``TBranch`` is included if the function returns True, excluded if it returns False. recursive (bool): If True, descend into any nested subbranches. If False, only consider branches directly accessible under this @@ -1840,9 +1827,9 @@ def common_entry_offsets( Returns entry offsets in which ``TBasket`` boundaries align in the specified set of branches. - If this :py:class:`~uproot4.behaviors.TBranch.TBranch` has no subbranches, + If this :py:class:`~uproot.behaviors.TBranch.TBranch` has no subbranches, the output is identical to - :py:attr:`~uproot4.behaviors.TBranch.TBranch.entry_offsets`. + :py:attr:`~uproot.behaviors.TBranch.TBranch.entry_offsets`. """ common_offsets = None for branch in self.itervalues( @@ -1864,10 +1851,10 @@ def __getitem__(self, where): if got is not None: return got - if uproot4._util.isint(where): + if uproot._util.isint(where): return self.branches[where] - elif uproot4._util.isstr(where): - where = uproot4._util.ensure_str(where) + elif uproot._util.isstr(where): + where = uproot._util.ensure_str(where) else: raise TypeError( "where must be an integer or a string, not {0}".format(repr(where)) @@ -1886,7 +1873,7 @@ def __getitem__(self, where): self._lookup[original_where] = v return v else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( original_where, keys=self.keys(recursive=recursive), file_path=self._file.file_path, @@ -1899,7 +1886,7 @@ def __getitem__(self, where): self._lookup[original_where] = got return got else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( original_where, keys=self.keys(recursive=recursive), file_path=self._file.file_path, @@ -1912,7 +1899,7 @@ def __getitem__(self, where): self._lookup[original_where] = branch return branch else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( original_where, keys=self.keys(recursive=recursive), file_path=self._file.file_path, @@ -1935,8 +1922,8 @@ class TBranch(HasBranches): """ Behaviors for a ``TBranch``, which mostly consist of array-reading methods. - Since a :py:class:`~uproot4.behavior.TBranch.TBranch` is a - :py:class:`~uproot4.behavior.TBranch.HasBranches`, it is also a Python + Since a :py:class:`~uproot.behavior.TBranch.TBranch` is a + :py:class:`~uproot.behavior.TBranch.HasBranches`, it is also a Python ``Mapping``, which uses square bracket syntax to extract subbranches: .. code-block:: python @@ -1968,29 +1955,29 @@ def array( ): u""" Args: - interpretation (None or :py:class:`~uproot4.interpretation.Interpretation`): An + interpretation (None or :py:class:`~uproot.interpretation.Interpretation`): An interpretation of the ``TBranch`` data as an array. If None, the - standard :py:attr:`~uproot4.behavior.TBranch.TBranch.interpretation` + standard :py:attr:`~uproot.behavior.TBranch.TBranch.interpretation` is used, which is derived from - :py:func:`~uproot4.interpretation.identify.interpretation_of`. + :py:func:`~uproot.interpretation.identify.interpretation_of`. entry_start (None or int): The first entry to include. If None, start at zero. If negative, count from the end, like a Python slice. entry_stop (None or int): The first entry to exclude (i.e. one greater than the last entry to include). If None, stop at - :py:attr:`~uproot4.behavior.TTree.TTree.num_entries`. If negative, + :py:attr:`~uproot.behavior.TTree.TTree.num_entries`. If negative, count from the end, like a Python slice. decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, the - file's :py:attr:`~uproot4.reading.ReadOnlyFile.decompression_executor` + file's :py:attr:`~uproot.reading.ReadOnlyFile.decompression_executor` is used. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, the file's :py:attr:`~uproot4.reading.ReadOnlyFile.interpretation_executor` + arrays; if None, the file's :py:attr:`~uproot.reading.ReadOnlyFile.interpretation_executor` is used. array_cache ("inherit", None, MutableMapping, or memory size): Cache of arrays; if "inherit", use the file's cache; if None, do not use a cache; if a memory size, create a new cache of this size. - library (str or :py:class:`~uproot4.interpretation.library.Library`): The library + library (str or :py:class:`~uproot.interpretation.library.Library`): The library that is used to represent arrays. Options are ``"np"`` for NumPy, ``"ak"`` for Awkward Array, ``"pd"`` for Pandas, and ``"cp"`` for CuPy. @@ -2010,7 +1997,7 @@ def array( >>> array["y"] - See also :py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` to read + See also :py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` to read multiple ``TBranches`` into a group of arrays or an array-group. """ if interpretation is None: @@ -2025,7 +2012,7 @@ def array( decompression_executor, interpretation_executor, self._file ) array_cache = _regularize_array_cache(array_cache, self._file) - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) def get_from_cache(branchname, interpretation): if array_cache is not None: @@ -2112,7 +2099,7 @@ def name(self): Note that ``TBranch`` names are not guaranteed to be unique; it is sometimes necessary to address a branch by its - :py:attr:`~uproot4.behavior.TBranch.TBranch.index`. + :py:attr:`~uproot.behavior.TBranch.TBranch.index`. """ return self.member("fName") @@ -2128,7 +2115,7 @@ def object_path(self): """ Object path of the ``TBranch``. """ - if isinstance(self._parent, uproot4.behaviors.TTree.TTree): + if isinstance(self._parent, uproot.behaviors.TTree.TTree): sep = ":" else: sep = "/" @@ -2141,7 +2128,7 @@ def cache_key(self): part of object and array cache keys. """ if self._cache_key is None: - if isinstance(self._parent, uproot4.behaviors.TTree.TTree): + if isinstance(self._parent, uproot.behaviors.TTree.TTree): sep = ":" else: sep = "/" @@ -2156,7 +2143,7 @@ def index(self): Integer position of this ``TBranch`` in its parent's list of branches. Useful for cases in which the - :py:attr:`~uproot4.behavior.TBranch.TBranch.name` is not unique: the + :py:attr:`~uproot.behavior.TBranch.TBranch.name` is not unique: the non-recursive index is always unique. """ for i, branch in enumerate(self.parent.branches): @@ -2168,26 +2155,26 @@ def index(self): @property def interpretation(self): """ - The standard :py:class:`~uproot4.interpretation.Interpretation` of this + The standard :py:class:`~uproot.interpretation.Interpretation` of this ``TBranch`` as an array, derived from - :py:func:`~uproot4.interpretation.identify.interpretation_of`. + :py:func:`~uproot.interpretation.identify.interpretation_of`. If no interpretation could be found, the value of this property - would be a :py:exc:`~uproot4.interpretation.identify.UnknownInterpretation`, + would be a :py:exc:`~uproot.interpretation.identify.UnknownInterpretation`, which is a Python ``Exception``. Since the exception is *returned*, rather than *raised*, a branch lacking an interpretation is not a fatal error. However, any attempt to use this exception object as an - :py:class:`~uproot4.interpretation.Interpretation` causes it to raise itself: + :py:class:`~uproot.interpretation.Interpretation` causes it to raise itself: attempting to read a branch lacking an interpretation is a fatal error. """ if self._interpretation is None: try: - self._interpretation = uproot4.interpretation.identify.interpretation_of( + self._interpretation = uproot.interpretation.identify.interpretation_of( self, {} ) - except uproot4.interpretation.identify.UnknownInterpretation as err: + except uproot.interpretation.identify.UnknownInterpretation as err: self._interpretation = err return self._interpretation @@ -2195,9 +2182,9 @@ def interpretation(self): def typename(self): """ The C++ typename of the ``TBranch``, derived from its - :py:attr:`~uproot4.behavior.TBranch.TBranch.interpretation`. If the + :py:attr:`~uproot.behavior.TBranch.TBranch.interpretation`. If the interpretation is - :py:exc:`~uproot4.interpretation.identify.UnknownInterpretation`, the + :py:exc:`~uproot.interpretation.identify.UnknownInterpretation`, the typename is ``"unknown"``. """ if self.interpretation is None: @@ -2211,12 +2198,12 @@ def num_entries(self): The number of entries in the ``TBranch``, as reported by ``fEntries``. In principle, this could disagree with the - :py:attr:`~uproot4.behaviors.TTree.TTree.num_entries`, which is from the + :py:attr:`~uproot.behaviors.TTree.TTree.num_entries`, which is from the ``TTree``'s ``fEntries``. The ``TBranch`` also has a ``fEntryNumber``, which ought to be equal to the ``TBranch`` and ``TTree``'s ``fEntries``, and the last value of - :py:attr:`~uproot4.behaviors.TBranch.TBranch.entry_offsets` ought to be + :py:attr:`~uproot.behaviors.TBranch.TBranch.entry_offsets` ought to be equal to the number of entries as well. """ return int(self.member("fEntries")) # or fEntryNumber? @@ -2230,7 +2217,7 @@ def entry_offsets(self): The number of ``entry_offsets`` in this list of integers is one more than the number of ``TBaskets``. The first is ``0`` and the last is the number of entries - (:py:attr:`~uproot4.behaviors.TBranch.TBranch.num_entries`). + (:py:attr:`~uproot.behaviors.TBranch.TBranch.num_entries`). """ if self._num_normal_baskets == 0: out = [0] @@ -2245,7 +2232,7 @@ def entry_offsets(self): out[-1] != self.num_entries and self.interpretation is not None and not isinstance( - self.interpretation, uproot4.interpretation.grouped.AsGrouped + self.interpretation, uproot.interpretation.grouped.AsGrouped ) ): raise ValueError( @@ -2300,17 +2287,17 @@ def tree(self): deeply nested; this property ascends all the way to the top. """ out = self - while not isinstance(out, uproot4.behaviors.TTree.TTree): + while not isinstance(out, uproot.behaviors.TTree.TTree): out = out.parent return out @property def top_level(self): """ - True if the immediate :py:attr:`~uproot4.behaviors.TBranch.TBranch.parent` + True if the immediate :py:attr:`~uproot.behaviors.TBranch.TBranch.parent` is the ``TTree``; False otherwise. """ - return isinstance(self.parent, uproot4.behaviors.TTree.TTree) + return isinstance(self.parent, uproot.behaviors.TTree.TTree) @property def streamer(self): @@ -2318,7 +2305,7 @@ def streamer(self): The ``TStreamerInfo`` or ``TStreamerElement`` for this ``TBranch``, which may be None. - If the :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` have not yet been + If the :py:attr:`~uproot.reading.ReadOnlyFile.streamers` have not yet been read, this method *might* cause them to be read. (Only ``TBranchElements`` can have streamers.) """ @@ -2387,12 +2374,12 @@ def context(self): @property def aliases(self): """ - The :py:attr:`~uproot4.behaviors.TTree.TTree.aliases`, which are used as the + The :py:attr:`~uproot.behaviors.TTree.TTree.aliases`, which are used as the ``aliases`` argument to - :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, - :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate`, - :py:func:`~uproot4.behaviors.TBranch.iterate`, and - :py:func:`~uproot4.behaviors.TBranch.concatenate` if one is not given. + :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, + :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate`, + :py:func:`~uproot.behaviors.TBranch.iterate`, and + :py:func:`~uproot.behaviors.TBranch.concatenate` if one is not given. The return type is always a dict of str \u2192 str, even if there are no aliases (an empty dict). @@ -2406,9 +2393,9 @@ def count_branch(self): if this branch has no "counts". """ out = self.count_leaf - while isinstance(out, uproot4.model.Model) and out.is_instance("TLeaf"): + while isinstance(out, uproot.model.Model) and out.is_instance("TLeaf"): out = out.parent - if isinstance(out, uproot4.model.Model) and out.is_instance("TBranch"): + if isinstance(out, uproot.model.Model) and out.is_instance("TBranch"): return out else: return None @@ -2453,8 +2440,8 @@ def compression_ratio(self): The number of uncompressed bytes divided by the number of compressed bytes for this ``TBranch``. - See :py:attr:`~uproot4.behaviors.TBranch.TBranch.compressed_bytes` and - :py:attr:`~uproot4.behaviors.TBranch.TBranch.uncompressed_bytes`. + See :py:attr:`~uproot.behaviors.TBranch.TBranch.compressed_bytes` and + :py:attr:`~uproot.behaviors.TBranch.TBranch.uncompressed_bytes`. """ return float(self.uncompressed_bytes) / float(self.compressed_bytes) @@ -2463,20 +2450,20 @@ def num_baskets(self): """ The number of ``TBaskets`` in this ``TBranch``, including both normal (free) ``TBaskets`` and - :py:attr:`~uproot4.behaviors.TBranch.TBranch.embedded_baskets`. + :py:attr:`~uproot.behaviors.TBranch.TBranch.embedded_baskets`. """ return self._num_normal_baskets + len(self.embedded_baskets) def basket(self, basket_num): """ - The :py:class:`~uproot4.models.TBasket.Model_TBasket` at index ``basket_num``. + The :py:class:`~uproot.models.TBasket.Model_TBasket` at index ``basket_num``. It may be a normal (free) ``TBasket`` or one of the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.embedded_baskets`. + :py:attr:`~uproot.behaviors.TBranch.TBranch.embedded_baskets`. """ if 0 <= basket_num < self._num_normal_baskets: chunk, cursor = self.basket_chunk_cursor(basket_num) - return uproot4.models.TBasket.Model_TBasket.read( + return uproot.models.TBasket.Model_TBasket.read( chunk, cursor, {"basket_num": basket_num}, self._file, self._file, self ) elif 0 <= basket_num < self.num_baskets: @@ -2491,14 +2478,14 @@ def basket(self, basket_num): def basket_chunk_cursor(self, basket_num): """ - Returns a :py:class:`~uproot4.source.chunk.Chunk` and - :py:class:`~uproot4.source.cursor.Cursor` as a 2-tuple for a given + Returns a :py:class:`~uproot.source.chunk.Chunk` and + :py:class:`~uproot.source.cursor.Cursor` as a 2-tuple for a given ``basket_num``. """ if 0 <= basket_num < self._num_normal_baskets: start = self.member("fBasketSeek")[basket_num] stop = start + self.basket_compressed_bytes(basket_num) - cursor = uproot4.source.cursor.Cursor(start) + cursor = uproot.source.cursor.Cursor(start) chunk = self._file.source.chunk(start, stop) return chunk, cursor elif 0 <= basket_num < self.num_baskets: @@ -2558,18 +2545,18 @@ def basket_uncompressed_bytes(self, basket_num): def basket_key(self, basket_num): """ - The ``TKey`` (:py:class:`~uproot4.reading.ReadOnlyKey`) for the ``TBasket`` + The ``TKey`` (:py:class:`~uproot.reading.ReadOnlyKey`) for the ``TBasket`` at ``basket_num``. Only applies to normal (free) ``TBaskets``, not - :py:attr:`~uproot4.behaviors.TBranch.TBranch.embedded_baskets`. + :py:attr:`~uproot.behaviors.TBranch.TBranch.embedded_baskets`. """ if 0 <= basket_num < self._num_normal_baskets: start = self.member("fBasketSeek")[basket_num] - stop = start + uproot4.reading._key_format_big.size - cursor = uproot4.source.cursor.Cursor(start) + stop = start + uproot.reading._key_format_big.size + cursor = uproot.source.cursor.Cursor(start) chunk = self._file.source.chunk(start, stop) - return uproot4.reading.ReadOnlyKey( + return uproot.reading.ReadOnlyKey( chunk, cursor, {}, self._file, self, read_strings=False ) elif 0 <= basket_num < self.num_baskets: @@ -2595,7 +2582,7 @@ def embedded_baskets(self): """ if self._embedded_baskets is None: cursor = self._cursor_baskets.copy() - baskets = uproot4.models.TObjArray.Model_TObjArrayOfTBaskets.read( + baskets = uproot.models.TObjArray.Model_TObjArrayOfTBaskets.read( self.tree.chunk, cursor, {}, self._file, self._file, self ) with self._embedded_baskets_lock: @@ -2612,12 +2599,12 @@ def embedded_baskets(self): def entries_to_ranges_or_baskets(self, entry_start, entry_stop): """ Returns a list of (start, stop) integer pairs for free (normal) - ``TBaskets`` and :py:class:`~uproot4.models.TBasket.Model_TBasket` objects + ``TBaskets`` and :py:class:`~uproot.models.TBasket.Model_TBasket` objects for embedded ``TBaskets``. The intention is for this list to be updated in place, replacing (start, stop) integer pairs with - :py:class:`~uproot4.models.TBasket.Model_TBasket` objects as they get + :py:class:`~uproot.models.TBasket.Model_TBasket` objects as they get read and interpreted. """ entry_offsets = self.entry_offsets @@ -2734,11 +2721,11 @@ def debug( 101.0 202.0 303.0 """ data = self.debug_array(entry) - chunk = uproot4.source.chunk.Chunk.wrap(self._file.source, data) + chunk = uproot.source.chunk.Chunk.wrap(self._file.source, data) if skip_bytes is None: - cursor = uproot4.source.cursor.Cursor(0) + cursor = uproot.source.cursor.Cursor(0) else: - cursor = uproot4.source.cursor.Cursor(skip_bytes) + cursor = uproot.source.cursor.Cursor(skip_bytes) cursor.debug( chunk, limit_bytes=limit_bytes, dtype=dtype, offset=offset, stream=stream ) @@ -2756,12 +2743,12 @@ def debug_array(self, entry, skip_bytes=0, dtype=numpy.dtype("u1")): which to interpret the data. (The size of the array returned is truncated to this ``dtype.itemsize``.) - Like :py:meth:`~uproot4.behaviors.TBranch.TBranch.debug`, but returns a + Like :py:meth:`~uproot.behaviors.TBranch.TBranch.debug`, but returns a NumPy array for further inspection. """ dtype = numpy.dtype(dtype) - interpretation = uproot4.interpretation.jagged.AsJagged( - uproot4.interpretation.numerical.AsDtype("u1") + interpretation = uproot.interpretation.jagged.AsJagged( + uproot.interpretation.numerical.AsDtype("u1") ) out = self.array( interpretation, entry_start=entry, entry_stop=entry + 1, library="np" @@ -2801,21 +2788,21 @@ def _keys_deep(hasbranches): def _regularize_files_inner(files, parse_colon, counter): - files2 = uproot4._util.regularize_path(files) + files2 = uproot._util.regularize_path(files) - if uproot4._util.isstr(files2) and not uproot4._util.isstr(files): + if uproot._util.isstr(files2) and not uproot._util.isstr(files): parse_colon = False files = files2 - if uproot4._util.isstr(files): + if uproot._util.isstr(files): if parse_colon: - file_path, object_path = uproot4._util.file_object_path_split(files) + file_path, object_path = uproot._util.file_object_path_split(files) else: file_path, object_path = files, None parsed_url = urlparse(file_path) - if parsed_url.scheme.upper() in uproot4._util._remote_schemes: + if parsed_url.scheme.upper() in uproot._util._remote_schemes: yield file_path, object_path else: @@ -2874,7 +2861,7 @@ def _regularize_files(files): seen = set() counter = [0] for file_path, object_path in _regularize_files_inner(files, True, counter): - if uproot4._util.isstr(file_path): + if uproot._util.isstr(file_path): key = (counter[0], file_path, object_path) if key not in seen: out.append((file_path, object_path)) @@ -2883,7 +2870,7 @@ def _regularize_files(files): out.append((file_path, object_path)) if len(out) == 0: - raise uproot4._util._file_not_found(files) + raise uproot._util._file_not_found(files) return out @@ -2895,7 +2882,7 @@ def _regularize_object_path( return _NoClose(file_path) else: - file = uproot4.reading.ReadOnlyFile( + file = uproot.reading.ReadOnlyFile( file_path, object_cache=None, array_cache=None, @@ -2968,9 +2955,9 @@ def _regularize_entries_start_stop(num_entries, entry_start, entry_stop): def _regularize_executors(decompression_executor, interpretation_executor, file): if file is None: if decompression_executor is None: - decompression_executor = uproot4.source.futures.TrivialExecutor() + decompression_executor = uproot.source.futures.TrivialExecutor() if interpretation_executor is None: - interpretation_executor = uproot4.source.futures.TrivialExecutor() + interpretation_executor = uproot.source.futures.TrivialExecutor() else: if decompression_executor is None: decompression_executor = file.decompression_executor @@ -2982,12 +2969,12 @@ def _regularize_executors(decompression_executor, interpretation_executor, file) def _regularize_array_cache(array_cache, file): if isinstance(array_cache, MutableMapping): return array_cache - elif uproot4._util.isstr(array_cache) and array_cache == "inherit": + elif uproot._util.isstr(array_cache) and array_cache == "inherit": return file._array_cache elif array_cache is None: return None - elif uproot4._util.isint(array_cache) or uproot4._util.isstr(array_cache): - return uproot4.cache.LRUArrayCache(array_cache) + elif uproot._util.isint(array_cache) or uproot._util.isstr(array_cache): + return uproot.cache.LRUArrayCache(array_cache) else: raise TypeError("array_cache must be None, a MutableMapping, or a memory size") @@ -3002,14 +2989,14 @@ def _regularize_aliases(hasbranches, aliases): def _regularize_interpretation(interpretation): - if isinstance(interpretation, uproot4.interpretation.Interpretation): + if isinstance(interpretation, uproot.interpretation.Interpretation): return interpretation elif isinstance(interpretation, numpy.dtype): - return uproot4.interpretation.numerical.AsDtype(interpretation) + return uproot.interpretation.numerical.AsDtype(interpretation) else: dtype = numpy.dtype(interpretation) dtype = dtype.newbyteorder(">") - return uproot4.interpretation.numerical.AsDtype(interpretation) + return uproot.interpretation.numerical.AsDtype(interpretation) def _regularize_branchname( @@ -3028,9 +3015,9 @@ def _regularize_branchname( if got is not None: arrays[branch.cache_key] = got - is_jagged = isinstance(interpretation, uproot4.interpretation.jagged.AsJagged) + is_jagged = isinstance(interpretation, uproot.interpretation.jagged.AsJagged) - if isinstance(interpretation, uproot4.interpretation.grouped.AsGrouped): + if isinstance(interpretation, uproot.interpretation.grouped.AsGrouped): branches = [] for subname, subinterp in interpretation.subbranches.items(): _regularize_branchname( @@ -3197,8 +3184,8 @@ def _regularize_expressions( if not isinstance( branch.interpretation, ( - uproot4.interpretation.identify.UnknownInterpretation, - uproot4.interpretation.grouped.AsGrouped, + uproot.interpretation.identify.UnknownInterpretation, + uproot.interpretation.grouped.AsGrouped, ), ): _regularize_expression( @@ -3216,7 +3203,7 @@ def _regularize_expressions( branchname, ) - elif uproot4._util.isstr(expressions): + elif uproot._util.isstr(expressions): _regularize_expression( hasbranches, expressions, @@ -3238,7 +3225,7 @@ def _regularize_expressions( else: items = [] for expression in expressions: - if uproot4._util.isstr(expression): + if uproot._util.isstr(expression): items.append((expression, None)) elif isinstance(expression, tuple) and len(expression) == 2: items.append(expression) @@ -3291,7 +3278,7 @@ def _regularize_expressions( if cut is None: pass - elif uproot4._util.isstr(cut): + elif uproot._util.isstr(cut): _regularize_expression( hasbranches, cut, @@ -3364,8 +3351,8 @@ def replace(ranges_or_baskets, original_index, basket): def chunk_to_basket(chunk, branch, basket_num): try: - cursor = uproot4.source.cursor.Cursor(chunk.start) - basket = uproot4.models.TBasket.Model_TBasket.read( + cursor = uproot.source.cursor.Cursor(chunk.start) + basket = uproot.models.TBasket.Model_TBasket.read( chunk, cursor, {"basket_num": basket_num}, @@ -3427,12 +3414,12 @@ def basket_to_array(basket): while len(arrays) < len(branchid_interpretation): obj = notifications.get() - if isinstance(obj, uproot4.source.chunk.Chunk): + if isinstance(obj, uproot.source.chunk.Chunk): chunk = obj args = range_args[(chunk.start, chunk.stop)] decompression_executor.submit(chunk_to_basket, chunk, *args) - elif isinstance(obj, uproot4.models.TBasket.Model_TBasket): + elif isinstance(obj, uproot.models.TBasket.Model_TBasket): basket = obj interpretation_executor.submit(basket_to_array, basket) @@ -3440,7 +3427,7 @@ def basket_to_array(basket): pass elif isinstance(obj, tuple) and len(obj) == 3: - uproot4.source.futures.delayed_raise(*obj) + uproot.source.futures.delayed_raise(*obj) else: raise AssertionError(obj) @@ -3452,7 +3439,7 @@ def _fix_asgrouped(arrays, expression_context, branchid_interpretation, library, if context["is_branch"]: branch = context["branches"][-1] interpretation = branchid_interpretation[branch.cache_key] - if isinstance(interpretation, uproot4.interpretation.grouped.AsGrouped): + if isinstance(interpretation, uproot.interpretation.grouped.AsGrouped): assert arrays[branch.cache_key] is None limited_context = dict(expression_context[index_start:index_stop]) @@ -3493,9 +3480,9 @@ def _hasbranches_num_entries_for( def _regularize_step_size( hasbranches, step_size, entry_start, entry_stop, branchid_interpretation ): - if uproot4._util.isint(step_size): + if uproot._util.isint(step_size): return step_size - target_num_bytes = uproot4._util.memory_size( + target_num_bytes = uproot._util.memory_size( step_size, "number of entries or memory size string with units " "(such as '100 MB') required, not {0}".format(repr(step_size)), diff --git a/uproot4/behaviors/TBranchElement.py b/uproot/behaviors/TBranchElement.py similarity index 65% rename from uproot4/behaviors/TBranchElement.py rename to uproot/behaviors/TBranchElement.py index b2318b45f..473f49b78 100644 --- a/uproot4/behaviors/TBranchElement.py +++ b/uproot/behaviors/TBranchElement.py @@ -2,21 +2,21 @@ """ Defines the behaviors of ``TBranchElement``, which is entirely inherited from -functions in :py:class:`~uproot4.behaviors.TBranch.TBranch`. +functions in :py:class:`~uproot.behaviors.TBranch.TBranch`. """ from __future__ import absolute_import -import uproot4.behaviors.TBranch +import uproot -class TBranchElement(uproot4.behaviors.TBranch.TBranch): +class TBranchElement(uproot.behaviors.TBranch.TBranch): """ Behaviors for a ``TBranchElement``, which mostly consist of array-reading methods. - Since a :py:class:`~uproot4.behavior.TBranchElement.TBranchElement` is a - :py:class:`~uproot4.behavior.TBranch.HasBranches`, it is also a Python + Since a :py:class:`~uproot.behavior.TBranchElement.TBranchElement` is a + :py:class:`~uproot.behavior.TBranch.HasBranches`, it is also a Python ``Mapping``, which uses square bracket syntax to extract subbranches: .. code-block:: python diff --git a/uproot4/behaviors/TH1.py b/uproot/behaviors/TH1.py similarity index 92% rename from uproot4/behaviors/TH1.py rename to uproot/behaviors/TH1.py index 69659db2f..982d930fa 100644 --- a/uproot4/behaviors/TH1.py +++ b/uproot/behaviors/TH1.py @@ -9,8 +9,7 @@ import numpy -import uproot4.models.TArray -import uproot4.extras +import uproot boost_metadata = {"name": "fName", "title": "fTitle"} @@ -18,7 +17,7 @@ def _boost_axis(axis, metadata): - boost_histogram = uproot4.extras.boost_histogram() + boost_histogram = uproot.extras.boost_histogram() fNbins = axis.member("fNbins") fXbins = axis.member("fXbins", none_if_missing=True) @@ -72,13 +71,13 @@ def __ne__(self, other): @property def axes(self): """ - A tuple of all :py:class:`~uproot4.behaviors.TAxis.TAxis` objects. + A tuple of all :py:class:`~uproot.behaviors.TAxis.TAxis` objects. """ raise NotImplementedError(repr(self)) def axis(self, axis): """ - Returns a specified :py:class:`~uproot4.behaviors.TAxis.TAxis` object. + Returns a specified :py:class:`~uproot.behaviors.TAxis.TAxis` object. The ``axis`` can be specified as @@ -127,7 +126,7 @@ def errors(self, flow=False): flow (bool): If True, include underflow and overflow bins before and after the normal (finite-width) bins. - Errors (uncertainties) in the :py:meth:`~uproot4.behaviors.TH1.Histogram.values` + Errors (uncertainties) in the :py:meth:`~uproot.behaviors.TH1.Histogram.values` as a 1, 2, or 3 dimensional ``numpy.ndarray`` of ``numpy.float64``. If ``fSumw2`` (weights) are available, they will be used in the @@ -146,7 +145,7 @@ def variances(self, flow=False): after the normal (finite-width) bins. Variances (uncertainties squared) in the - :py:meth:`~uproot4.behaviors.TH1.Histogram.values` as a 1, 2, or 3 + :py:meth:`~uproot.behaviors.TH1.Histogram.values` as a 1, 2, or 3 dimensional ``numpy.ndarray`` of ``numpy.float64``. If ``fSumw2`` (weights) are available, they will be used in the @@ -165,8 +164,8 @@ def counts(self, flow=False): after the normal (finite-width) bins. Returns the (possibly weighted) number of entries in each bin. For - histograms, this is equal to :py:meth:`~uproot4.behaviors.TH1.Histogram.values`. - For profiles, this is equal to :py:meth:`~uproot4.behaviors.TH1.Histogram.effective_entries`. + histograms, this is equal to :py:meth:`~uproot.behaviors.TH1.Histogram.values`. + For profiles, this is equal to :py:meth:`~uproot.behaviors.TH1.Histogram.effective_entries`. """ return self.values(flow=flow) @@ -192,7 +191,7 @@ def to_hist(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): Converts the histogram into a ``hist`` object. """ - return uproot4.extras.hist().Hist( + return uproot.extras.hist().Hist( self.to_boost(metadata=boost_metadata, axis_metadata=boost_axis_metadata) ) @@ -226,7 +225,7 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (values,) = self.base(uproot4.models.TArray.Model_TArray) + (values,) = self.base(uproot.models.TArray.Model_TArray) values = numpy.asarray(values, dtype=values.dtype.newbyteorder("=")) self._values = values @@ -279,8 +278,7 @@ def to_numpy(self, flow=False, dd=False): return values, xedges def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): - - boost_histogram = uproot4.extras.boost_histogram() + boost_histogram = uproot.extras.boost_histogram() values = self.values(flow=True) diff --git a/uproot4/behaviors/TH2.py b/uproot/behaviors/TH2.py similarity index 90% rename from uproot4/behaviors/TH2.py rename to uproot/behaviors/TH2.py index 558a5a6bc..e14a1a88e 100644 --- a/uproot4/behaviors/TH2.py +++ b/uproot/behaviors/TH2.py @@ -9,18 +9,17 @@ import numpy -import uproot4.models.TArray -import uproot4.behaviors.TH1 -from uproot4.behaviors.TH1 import boost_metadata, boost_axis_metadata +import uproot +from uproot.behaviors.TH1 import boost_metadata, boost_axis_metadata -class TH2(uproot4.behaviors.TH1.Histogram): +class TH2(uproot.behaviors.TH1.Histogram): """ Behaviors for two-dimensional histograms: descendants of ROOT's ``TH2``, not including ``TProfile2D`` or ``TH2Poly``. """ - no_inherit = (uproot4.behaviors.TH1.TH1,) + no_inherit = (uproot.behaviors.TH1.TH1,) @property def axes(self): @@ -47,7 +46,7 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (values,) = self.base(uproot4.models.TArray.Model_TArray) + (values,) = self.base(uproot.models.TArray.Model_TArray) values = numpy.asarray(values, dtype=values.dtype.newbyteorder("=")) xaxis_fNbins = self.member("fXaxis").member("fNbins") yaxis_fNbins = self.member("fYaxis").member("fNbins") @@ -104,8 +103,7 @@ def to_numpy(self, flow=False, dd=False): return values, xedges, yedges def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): - - boost_histogram = uproot4.extras.boost_histogram() + boost_histogram = uproot.extras.boost_histogram() values = self.values(flow=True) @@ -121,8 +119,8 @@ def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): else: storage = boost_histogram.storage.Double() - xaxis = uproot4.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) - yaxis = uproot4.behaviors.TH1._boost_axis(self.member("fYaxis"), axis_metadata) + xaxis = uproot.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) + yaxis = uproot.behaviors.TH1._boost_axis(self.member("fYaxis"), axis_metadata) out = boost_histogram.Histogram(xaxis, yaxis, storage=storage) for k, v in metadata.items(): setattr(out, k, self.member(v)) diff --git a/uproot4/behaviors/TH2Poly.py b/uproot/behaviors/TH2Poly.py similarity index 84% rename from uproot4/behaviors/TH2Poly.py rename to uproot/behaviors/TH2Poly.py index 14a0d5f1d..654ee41c5 100644 --- a/uproot4/behaviors/TH2Poly.py +++ b/uproot/behaviors/TH2Poly.py @@ -6,15 +6,15 @@ from __future__ import absolute_import -import uproot4.behaviors.TH2 +import uproot -class TH2Poly(uproot4.behaviors.TH1.Histogram): +class TH2Poly(uproot.behaviors.TH1.Histogram): """ Behaviors for two-dimensional polygon histograms: ROOT's ``TH2Poly``. """ - no_inherit = (uproot4.behaviors.TH2.TH2,) + no_inherit = (uproot.behaviors.TH2.TH2,) @property def axes(self): diff --git a/uproot4/behaviors/TH3.py b/uproot/behaviors/TH3.py similarity index 89% rename from uproot4/behaviors/TH3.py rename to uproot/behaviors/TH3.py index 2cecfa0e1..950b78a65 100644 --- a/uproot4/behaviors/TH3.py +++ b/uproot/behaviors/TH3.py @@ -9,18 +9,17 @@ import numpy -import uproot4.models.TArray -import uproot4.behaviors.TH1 -from uproot4.behaviors.TH1 import boost_metadata, boost_axis_metadata +import uproot +from uproot.behaviors.TH1 import boost_metadata, boost_axis_metadata -class TH3(uproot4.behaviors.TH1.Histogram): +class TH3(uproot.behaviors.TH1.Histogram): """ Behaviors for three-dimensional histograms: descendants of ROOT's ``TH3``, not including ``TProfile3D``. """ - no_inherit = (uproot4.behaviors.TH1.TH1,) + no_inherit = (uproot.behaviors.TH1.TH1,) @property def axes(self): @@ -51,7 +50,7 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (values,) = self.base(uproot4.models.TArray.Model_TArray) + (values,) = self.base(uproot.models.TArray.Model_TArray) values = numpy.asarray(values, dtype=values.dtype.newbyteorder("=")) xaxis_fNbins = self.member("fXaxis").member("fNbins") @@ -113,7 +112,7 @@ def to_numpy(self, flow=False, dd=False): return values, xedges, yedges, zedges def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): - boost_histogram = uproot4.extras.boost_histogram() + boost_histogram = uproot.extras.boost_histogram() values = self.values(flow=True) @@ -129,9 +128,9 @@ def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): else: storage = boost_histogram.storage.Double() - xaxis = uproot4.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) - yaxis = uproot4.behaviors.TH1._boost_axis(self.member("fYaxis"), axis_metadata) - zaxis = uproot4.behaviors.TH1._boost_axis(self.member("fZaxis"), axis_metadata) + xaxis = uproot.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) + yaxis = uproot.behaviors.TH1._boost_axis(self.member("fYaxis"), axis_metadata) + zaxis = uproot.behaviors.TH1._boost_axis(self.member("fZaxis"), axis_metadata) out = boost_histogram.Histogram(xaxis, yaxis, zaxis, storage=storage) for k, v in metadata.items(): setattr(out, k, self.member(v)) diff --git a/uproot4/behaviors/TProfile.py b/uproot/behaviors/TProfile.py similarity index 93% rename from uproot4/behaviors/TProfile.py rename to uproot/behaviors/TProfile.py index 598c74af8..fccb8990a 100644 --- a/uproot4/behaviors/TProfile.py +++ b/uproot/behaviors/TProfile.py @@ -8,9 +8,8 @@ import numpy -import uproot4.models.TArray -import uproot4.behaviors.TH1 -from uproot4.behaviors.TH1 import boost_metadata, boost_axis_metadata +import uproot +from uproot.behaviors.TH1 import boost_metadata, boost_axis_metadata _kERRORMEAN = 0 @@ -132,7 +131,7 @@ def _values_errors_1d(error_mode, fBinEntries, root_cont, fSumw2, fNcells, fBinS return root_contsum, out -class Profile(uproot4.behaviors.TH1.Histogram): +class Profile(uproot.behaviors.TH1.Histogram): """ Abstract class for profile plots. """ @@ -144,7 +143,7 @@ def effective_entries(self, flow=False): after the normal (finite-width) bins. The effective number of entries, which is a step in the calculation of - :py:meth:`~uproot4.behaviors.TProfile.Profile.values`. The calculation + :py:meth:`~uproot.behaviors.TProfile.Profile.values`. The calculation of profile errors exactly follows ROOT's function, but in a vectorized NumPy form. """ @@ -170,7 +169,7 @@ def errors(self, flow=False, error_mode=""): after the normal (finite-width) bins. error_mode (str): Choose a method for calculating the errors (see below). - Errors (uncertainties) in the :py:meth:`~uproot4.behaviors.TH1.Histogram.values` + Errors (uncertainties) in the :py:meth:`~uproot.behaviors.TH1.Histogram.values` as a 1, 2, or 3 dimensional ``numpy.ndarray`` of ``numpy.float64``. The calculation of profile errors exactly follows ROOT's function, but @@ -196,7 +195,7 @@ def variances(self, flow=False, error_mode=""): error_mode (str): Choose a method for calculating the errors (see below). Variances (uncertainties squared) in the - :py:meth:`~uproot4.behaviors.TH1.Histogram.values` as a 1, 2, or 3 + :py:meth:`~uproot.behaviors.TH1.Histogram.values` as a 1, 2, or 3 dimensional ``numpy.ndarray`` of ``numpy.float64``. The calculation of profile variances exactly follows ROOT's function, but @@ -223,7 +222,7 @@ class TProfile(Profile): Behaviors for one-dimensional profiles: ROOT's ``TProfile``. """ - no_inherit = (uproot4.behaviors.TH1.TH1,) + no_inherit = (uproot.behaviors.TH1.TH1,) @property def axes(self): @@ -259,7 +258,7 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) values = _values_1d(self.member("fBinEntries"), root_cont,) self._values = values @@ -275,7 +274,7 @@ def _values_errors(self, flow, error_mode): values = self._values errors = getattr(self, attr) else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) fSumw2 = self.member("fSumw2", none_if_missing=True) if fSumw2 is not None: @@ -297,7 +296,7 @@ def _values_errors(self, flow, error_mode): return values[1:-1], errors[1:-1] def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): - boost_histogram = uproot4.extras.boost_histogram() + boost_histogram = uproot.extras.boost_histogram() effective_entries = self.effective_entries(flow=True) values, errors = self._values_errors(True, self.member("fErrorMode")) @@ -306,7 +305,7 @@ def to_boost(self, metadata=boost_metadata, axis_metadata=boost_axis_metadata): storage = boost_histogram.storage.WeightedMean() - xaxis = uproot4.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) + xaxis = uproot.behaviors.TH1._boost_axis(self.member("fXaxis"), axis_metadata) out = boost_histogram.Histogram(xaxis, storage=storage) for k, v in metadata.items(): setattr(out, k, self.member(v)) diff --git a/uproot4/behaviors/TProfile2D.py b/uproot/behaviors/TProfile2D.py similarity index 82% rename from uproot4/behaviors/TProfile2D.py rename to uproot/behaviors/TProfile2D.py index 06e9df959..bdf985d2e 100644 --- a/uproot4/behaviors/TProfile2D.py +++ b/uproot/behaviors/TProfile2D.py @@ -8,18 +8,16 @@ import numpy -import uproot4.behaviors.TH1 -import uproot4.behaviors.TH2 -import uproot4.behaviors.TProfile -from uproot4.behaviors.TH1 import boost_metadata, boost_axis_metadata +import uproot +from uproot.behaviors.TH1 import boost_metadata, boost_axis_metadata -class TProfile2D(uproot4.behaviors.TProfile.Profile): +class TProfile2D(uproot.behaviors.TProfile.Profile): """ Behaviors for two-dimensional profiles: ROOT's ``TProfile2D``. """ - no_inherit = (uproot4.behaviors.TH2.TH2,) + no_inherit = (uproot.behaviors.TH2.TH2,) @property def axes(self): @@ -44,7 +42,7 @@ def interpretation(self): def effective_entries(self, flow=False): fBinEntries = numpy.asarray(self.member("fBinEntries")) - out = uproot4.behaviors.TProfile._effective_entries_1d( + out = uproot.behaviors.TProfile._effective_entries_1d( fBinEntries.reshape(-1), numpy.asarray(self.member("fBinSumw2")).reshape(-1), self.member("fNcells"), @@ -59,9 +57,9 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) - values = uproot4.behaviors.TProfile._values_1d( + values = uproot.behaviors.TProfile._values_1d( numpy.asarray(self.member("fBinEntries")).reshape(-1), root_cont.reshape(-1), ) @@ -76,17 +74,17 @@ def values(self, flow=False): return values[1:-1, 1:-1] def _values_errors(self, flow, error_mode): - attr = "_errors" + uproot4.behaviors.TProfile._error_mode_str(error_mode) + attr = "_errors" + uproot.behaviors.TProfile._error_mode_str(error_mode) if hasattr(self, attr): values = self._values errors = getattr(self, attr) else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) fSumw2 = self.member("fSumw2", none_if_missing=True) if fSumw2 is not None: fSumw2 = numpy.asarray(fSumw2).reshape(-1) - values, errors = uproot4.behaviors.TProfile._values_errors_1d( + values, errors = uproot.behaviors.TProfile._values_errors_1d( error_mode, numpy.asarray(self.member("fBinEntries")).reshape(-1), root_cont.reshape(-1), diff --git a/uproot4/behaviors/TProfile3D.py b/uproot/behaviors/TProfile3D.py similarity index 84% rename from uproot4/behaviors/TProfile3D.py rename to uproot/behaviors/TProfile3D.py index 7abbbd50d..330af9241 100644 --- a/uproot4/behaviors/TProfile3D.py +++ b/uproot/behaviors/TProfile3D.py @@ -8,18 +8,16 @@ import numpy -import uproot4.behaviors.TH1 -import uproot4.behaviors.TH3 -import uproot4.behaviors.TProfile -from uproot4.behaviors.TH1 import boost_metadata, boost_axis_metadata +import uproot +from uproot.behaviors.TH1 import boost_metadata, boost_axis_metadata -class TProfile3D(uproot4.behaviors.TProfile.Profile): +class TProfile3D(uproot.behaviors.TProfile.Profile): """ Behaviors for three-dimensional profiles: ROOT's ``TProfile3D``. """ - no_inherit = (uproot4.behaviors.TH3.TH3,) + no_inherit = (uproot.behaviors.TH3.TH3,) @property def axes(self): @@ -48,7 +46,7 @@ def interpretation(self): def effective_entries(self, flow=False): fBinEntries = numpy.asarray(self.member("fBinEntries")) - out = uproot4.behaviors.TProfile._effective_entries_1d( + out = uproot.behaviors.TProfile._effective_entries_1d( fBinEntries.reshape(-1), numpy.asarray(self.member("fBinSumw2")).reshape(-1), self.member("fNcells"), @@ -63,9 +61,9 @@ def values(self, flow=False): if hasattr(self, "_values"): values = self._values else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) - values = uproot4.behaviors.TProfile._values_1d( + values = uproot.behaviors.TProfile._values_1d( numpy.asarray(self.member("fBinEntries")).reshape(-1), root_cont.reshape(-1), ) @@ -83,17 +81,17 @@ def values(self, flow=False): return values[1:-1, 1:-1, 1:-1] def _values_errors(self, flow, error_mode): - attr = "_errors" + uproot4.behaviors.TProfile._error_mode_str(error_mode) + attr = "_errors" + uproot.behaviors.TProfile._error_mode_str(error_mode) if hasattr(self, attr): values = self._values errors = getattr(self, attr) else: - (root_cont,) = self.base(uproot4.models.TArray.Model_TArray) + (root_cont,) = self.base(uproot.models.TArray.Model_TArray) root_cont = numpy.asarray(root_cont, dtype=numpy.float64) fSumw2 = self.member("fSumw2", none_if_missing=True) if fSumw2 is not None: fSumw2 = numpy.asarray(fSumw2).reshape(-1) - values, errors = uproot4.behaviors.TProfile._values_errors_1d( + values, errors = uproot.behaviors.TProfile._values_errors_1d( error_mode, numpy.asarray(self.member("fBinEntries")).reshape(-1), root_cont.reshape(-1), diff --git a/uproot4/behaviors/TTree.py b/uproot/behaviors/TTree.py similarity index 76% rename from uproot4/behaviors/TTree.py rename to uproot/behaviors/TTree.py index 1e7b39394..14db8f6fc 100644 --- a/uproot4/behaviors/TTree.py +++ b/uproot/behaviors/TTree.py @@ -2,20 +2,20 @@ """ Defines the behaviors of ``TTree``, which is almost entirely inherited from -functions in :py:mod:`uproot4.behaviors.TBranch`. +functions in :py:mod:`uproot.behaviors.TBranch`. """ from __future__ import absolute_import -import uproot4.behaviors.TBranch +import uproot -class TTree(uproot4.behaviors.TBranch.HasBranches): +class TTree(uproot.behaviors.TBranch.HasBranches): """ Behaviors for a ``TTree``, which mostly consist of array-reading methods. - Since a :py:class:`~uproot4.behavior.TTree.TTree` is a - :py:class:`~uproot4.behavior.TBranch.HasBranches`, it is also a Python + Since a :py:class:`~uproot.behavior.TTree.TTree` is a + :py:class:`~uproot.behavior.TBranch.HasBranches`, it is also a Python ``Mapping``, which uses square bracket syntax to extract subbranches: .. code-block:: python @@ -71,7 +71,7 @@ def num_entries(self): The number of entries in the ``TTree``, as reported by ``fEntries``. In principle, this could disagree with the - :py:attr:`~uproot4.behaviors.TBranch.TBranch.num_entries`, which is from the + :py:attr:`~uproot.behaviors.TBranch.TBranch.num_entries`, which is from the ``TBranch``'s ``fEntries``. See that method's documentation for yet more ways the number of entries could, in principle, be inconsistent. """ @@ -88,10 +88,10 @@ def tree(self): def aliases(self): u""" The ``TTree``'s ``fAliases``, which are used as the ``aliases`` - argument to :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays`, - :py:meth:`~uproot4.behaviors.TBranch.HasBranches.iterate`, - :py:func:`~uproot4.behaviors.TBranch.iterate`, and - :py:func:`~uproot4.behaviors.TBranch.concatenate` if one is not given. + argument to :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays`, + :py:meth:`~uproot.behaviors.TBranch.HasBranches.iterate`, + :py:func:`~uproot.behaviors.TBranch.iterate`, and + :py:func:`~uproot.behaviors.TBranch.concatenate` if one is not given. The return type is always a dict of str \u2192 str, even if there are no aliases (an empty dict). @@ -107,19 +107,19 @@ def aliases(self): @property def chunk(self): """ - The :py:class:`~uproot4.source.chunk.Chunk` from which this ``TTree`` was + The :py:class:`~uproot.source.chunk.Chunk` from which this ``TTree`` was read (as a strong, not weak, reference). The reason the chunk is retained is to read - :py:attr:`~uproot4.behaviors.TBranch.TBranch.embedded_baskets` only if + :py:attr:`~uproot.behaviors.TBranch.TBranch.embedded_baskets` only if necessary (if the file was opened with ``options["minimal_ttree_metadata"]=True``, the reading of these ``TBaskets`` is deferred until they are accessed). Holding a strong reference to a chunk holds a strong reference to - its :py:class:`~uproot4.source.chunk.Source`, preventing open file handles + its :py:class:`~uproot.source.chunk.Source`, preventing open file handles from going out of scope, but so does the - :py:class:`~uproot4.reading.ReadOnlyFile` that ``TTree`` needs to read data + :py:class:`~uproot.reading.ReadOnlyFile` that ``TTree`` needs to read data on demand. """ return self._chunk diff --git a/uproot4/behaviors/__init__.py b/uproot/behaviors/__init__.py similarity index 86% rename from uproot4/behaviors/__init__.py rename to uproot/behaviors/__init__.py index dfac8ae44..d613d690e 100644 --- a/uproot4/behaviors/__init__.py +++ b/uproot/behaviors/__init__.py @@ -10,9 +10,9 @@ To add a behavior for a ROOT class: 1. Translate the ROOT class name from C++ to Python with - :py:func:`~uproot4.model.classname_encode`. For example, + :py:func:`~uproot.model.classname_encode`. For example, ``"ROOT::RThing"`` becomes ``"Model_ROOT_3a3a_RThing"``. -2. Create a submodule of ``uproot4.behaviors`` without +2. Create a submodule of ``uproot.behaviors`` without the ``"Model_"`` prefix. For example, ``"ROOT_3a3a_RThing"``. 3. Include a class in that submodule with the fully encoded name. For example, ``"Model_ROOT_3a3a_RThing"``. @@ -22,7 +22,7 @@ appropriate name exist, the new class will inherit from the behavior, giving the newly created object specialized methods and properties. -See also :py:mod:`uproot4.models`. +See also :py:mod:`uproot.models`. """ from __future__ import absolute_import diff --git a/uproot4/cache.py b/uproot/cache.py similarity index 96% rename from uproot4/cache.py rename to uproot/cache.py index 4a441aff6..8f9179a46 100644 --- a/uproot4/cache.py +++ b/uproot/cache.py @@ -3,11 +3,11 @@ """ Simple, thread-safe cache classes satisfying the ``MutableMapping`` protocol. -The :py:class:`~uproot4.cache.LRUCache` implements a least-recently used eviction +The :py:class:`~uproot.cache.LRUCache` implements a least-recently used eviction policy that limits the number of items in the cache (used as an ``object_cache``). -The :py:class:`~uproot4.cache.LRUArrayCache` implements the same policy, limiting the +The :py:class:`~uproot.cache.LRUArrayCache` implements the same policy, limiting the total number of bytes, as reported by ``nbytes``. """ @@ -20,7 +20,7 @@ except ImportError: from collections import MutableMapping -import uproot4._util +import uproot class LRUCache(MutableMapping): @@ -206,7 +206,7 @@ def __init__(self, limit_bytes): if limit_bytes is None: limit = None else: - limit = uproot4._util.memory_size(limit_bytes) + limit = uproot._util.memory_size(limit_bytes) super(LRUArrayCache, self).__init__(limit) def __repr__(self): diff --git a/uproot4/compression.py b/uproot/compression.py similarity index 84% rename from uproot4/compression.py rename to uproot/compression.py index 3f53ecd73..edeb65579 100644 --- a/uproot4/compression.py +++ b/uproot/compression.py @@ -2,7 +2,7 @@ """ Defines an interface to compression algorithms used by ROOT, as well as functions -for compressing and decompressing a :py:class:`~uproot4.source.chunk.Chunk`. +for compressing and decompressing a :py:class:`~uproot.source.chunk.Chunk`. """ from __future__ import absolute_import @@ -11,10 +11,8 @@ import numpy -import uproot4.source.chunk -import uproot4.const -import uproot4._util -import uproot4.extras +import uproot +import uproot.const class Compression(object): @@ -31,7 +29,7 @@ def __repr__(self): @classmethod def from_code(cls, code): """ - Constructs a :py:class:`~uproot4.compression.Compression` from a raw + Constructs a :py:class:`~uproot.compression.Compression` from a raw ``fCompress`` integer. """ return cls.from_code_pair(code // 100, code % 100) @@ -39,7 +37,7 @@ def from_code(cls, code): @classmethod def from_code_pair(cls, algorithm, level): """ - Constructs a :py:class:`~uproot4.compression.Compression` from a pair of + Constructs a :py:class:`~uproot.compression.Compression` from a pair of integers representing ``algorithm`` and ``level``. """ if algorithm == 0 or level == 0: @@ -54,7 +52,7 @@ def from_code_pair(cls, algorithm, level): @property def code(self): """ - This :py:class:`~uproot4.compression.Compression` as a raw ``fCompress`` + This :py:class:`~uproot.compression.Compression` as a raw ``fCompress`` integer. """ algorithm, level = self.code_pair @@ -63,7 +61,7 @@ def code(self): @property def code_pair(self): """ - This :py:class:`~uproot4.compression.Compression` as a 2-tuple of integers + This :py:class:`~uproot.compression.Compression` as a 2-tuple of integers representing algorithm and level. """ for const, cls in algorithm_codes.items(): @@ -82,7 +80,7 @@ def level(self): @level.setter def level(self, value): - if not uproot4._util.isint(value): + if not uproot._util.isint(value): raise TypeError("Compression level must be an integer") if not 0 <= value <= 9: raise ValueError("Compression level must be between 0 and 9 (inclusive)") @@ -122,7 +120,7 @@ class LZMA(Compression): @classmethod def decompress(cls, data, uncompressed_bytes=None): - lzma = uproot4.extras.lzma() + lzma = uproot.extras.lzma() return lzma.decompress(data) @@ -139,7 +137,7 @@ class LZ4(Compression): @classmethod def decompress(cls, data, uncompressed_bytes=None): - lz4_block = uproot4.extras.lz4_block() + lz4_block = uproot.extras.lz4_block() if uncompressed_bytes is None: raise ValueError( "lz4 block decompression requires the number of uncompressed bytes" @@ -160,16 +158,16 @@ class ZSTD(Compression): @classmethod def decompress(cls, data, uncompressed_bytes=None): - zstandard = uproot4.extras.zstandard() + zstandard = uproot.extras.zstandard() dctx = zstandard.ZstdDecompressor() return dctx.decompress(data) algorithm_codes = { - uproot4.const.kZLIB: ZLIB, - uproot4.const.kLZMA: LZMA, - uproot4.const.kLZ4: LZ4, - uproot4.const.kZSTD: ZSTD, + uproot.const.kZLIB: ZLIB, + uproot.const.kLZMA: LZMA, + uproot.const.kLZ4: LZ4, + uproot.const.kZSTD: ZSTD, } @@ -180,21 +178,21 @@ def decompress(cls, data, uncompressed_bytes=None): def decompress(chunk, cursor, context, compressed_bytes, uncompressed_bytes): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. compressed_bytes (int): Number of compressed bytes to decompress. uncompressed_bytes (int): Number of uncompressed bytes to expect after decompression. - Decompresses ``compressed_bytes`` of a :py:class:`~uproot4.source.chunk.Chunk` + Decompresses ``compressed_bytes`` of a :py:class:`~uproot.source.chunk.Chunk` of data, starting at the ``cursor``. This function parses ROOT's 9-byte compression headers (17 bytes for LZ4 because it includes a checksum), combining blocks if there are more than - one, returning the result as a new :py:class:`~uproot4.source.chunk.Chunk`. + one, returning the result as a new :py:class:`~uproot.source.chunk.Chunk`. """ assert compressed_bytes >= 0 assert uncompressed_bytes >= 0 @@ -229,7 +227,7 @@ def decompress(chunk, cursor, context, compressed_bytes, uncompressed_bytes): ) data = cursor.bytes(chunk, block_compressed_bytes, context) - xxhash = uproot4.extras.xxhash() + xxhash = uproot.extras.xxhash() computed_checksum = xxhash.xxh64(data).intdigest() if computed_checksum != expected_checksum: raise ValueError( @@ -277,7 +275,7 @@ def decompress(chunk, cursor, context, compressed_bytes, uncompressed_bytes): ) uncompressed_array = numpy.frombuffer( - uncompressed_bytestring, dtype=uproot4.source.chunk.Chunk._dtype + uncompressed_bytestring, dtype=uproot.source.chunk.Chunk._dtype ) if num_blocks == 0: @@ -288,11 +286,11 @@ def decompress(chunk, cursor, context, compressed_bytes, uncompressed_bytes): else: output = numpy.empty( - uncompressed_bytes, dtype=uproot4.source.chunk.Chunk._dtype + uncompressed_bytes, dtype=uproot.source.chunk.Chunk._dtype ) output[filled : filled + block_uncompressed_bytes] = uncompressed_array filled += block_uncompressed_bytes num_blocks += 1 - return uproot4.source.chunk.Chunk.wrap(chunk.source, output) + return uproot.source.chunk.Chunk.wrap(chunk.source, output) diff --git a/uproot4/const.py b/uproot/const.py similarity index 100% rename from uproot4/const.py rename to uproot/const.py diff --git a/uproot4/containers.py b/uproot/containers.py similarity index 82% rename from uproot4/containers.py rename to uproot/containers.py index 25458ac8b..b37a34daf 100644 --- a/uproot4/containers.py +++ b/uproot/containers.py @@ -4,7 +4,7 @@ Interpretations and models for standard containers, such as ``std::vector`` and simple arrays. -See :py:mod:`uproot4.interpretation` and :py:mod:`uproot4.model`. +See :py:mod:`uproot.interpretation` and :py:mod:`uproot.model`. """ from __future__ import absolute_import @@ -28,10 +28,7 @@ import numpy -import uproot4._util -import uproot4.model -import uproot4.interpretation.numerical -import uproot4.deserialization +import uproot _stl_container_size = struct.Struct(">I") @@ -40,18 +37,18 @@ def _content_typename(content): if isinstance(content, numpy.dtype): - return uproot4.interpretation.numerical._dtype_kind_itemsize_to_typename[ + return uproot.interpretation.numerical._dtype_kind_itemsize_to_typename[ content.kind, content.itemsize ] elif isinstance(content, type): - return uproot4.model.classname_decode(content.__name__)[0] + return uproot.model.classname_decode(content.__name__)[0] else: return content.typename def _content_cache_key(content): if isinstance(content, numpy.dtype): - bo = uproot4.interpretation.numerical._numpy_byteorder_to_cache_key[ + bo = uproot.interpretation.numerical._numpy_byteorder_to_cache_key[ content.byteorder ] return "{0}{1}{2}".format(bo, content.kind, content.itemsize) @@ -70,18 +67,18 @@ def _read_nested( else: values = numpy.empty(length, dtype=_stl_object_type) if isinstance(model, AsContainer): - for i in uproot4._util.range(length): + for i in uproot._util.range(length): values[i] = model.read( chunk, cursor, context, file, selffile, parent, header=header ) else: - for i in uproot4._util.range(length): + for i in uproot._util.range(length): values[i] = model.read(chunk, cursor, context, file, selffile, parent) return values def _tostring(value): - if uproot4._util.isstr(value): + if uproot._util.isstr(value): return repr(value) else: return str(value) @@ -132,13 +129,13 @@ class AsContainer(object): Abstract class for all descriptions of data as containers, such as ``std::vector``. - Note that these are not :py:class:`~uproot4.interpretation.Interpretation` + Note that these are not :py:class:`~uproot.interpretation.Interpretation` objects, since they are recursively nestable and have a ``read`` - instance method like :py:class:`~uproot4.model.Model`'s ``read`` classmethod. + instance method like :py:class:`~uproot.model.Model`'s ``read`` classmethod. - A nested tree of :py:class:`~uproot4.containers.AsContainer` instances and - :py:class:`~uproot4.model.Model` class objects may be the ``model`` argument - of a :py:class:`~uproot4.interpretation.objects.AsObjects`. + A nested tree of :py:class:`~uproot.containers.AsContainer` instances and + :py:class:`~uproot.model.Model` class objects may be the ``model`` argument + of a :py:class:`~uproot.interpretation.objects.AsObjects`. """ @property @@ -162,17 +159,17 @@ def typename(self): def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): """ Args: - file (:py:class:`~uproot4.reading.CommonFileMethods`): The file associated + file (:py:class:`~uproot.reading.CommonFileMethods`): The file associated with this interpretation's ``TBranch``. index_format (str): Format to use for indexes of the - ``awkward1.forms.Form``; may be ``"i32"``, ``"u32"``, or + ``awkward.forms.Form``; may be ``"i32"``, ``"u32"``, or ``"i64"``. header (bool): If True, include headers in the Form's ``"uproot"`` parameters. tobject_header (bool): If True, include headers for ``TObject`` classes in the Form's ``"uproot"`` parameters. - The ``awkward1.forms.Form`` to use to put objects of type type in an + The ``awkward.forms.Form`` to use to put objects of type type in an Awkward Array. """ raise AssertionError @@ -182,19 +179,19 @@ def strided_interpretation( ): """ Args: - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. header (bool): If True, assume the outermost object has a header. tobject_header (bool): If True, assume that ``TObjects`` have headers. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): The + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): The original, non-strided model or container. Returns a list of (str, ``numpy.dtype``) pairs to build a - :py:class:`~uproot4.interpretation.objects.AsStridedObjects` interpretation. + :py:class:`~uproot.interpretation.objects.AsStridedObjects` interpretation. """ - raise uproot4.interpretation.objects.CannotBeStrided(self.typename) + raise uproot.interpretation.objects.CannotBeStrided(self.typename) @property def header(self): @@ -215,20 +212,20 @@ def header(self, value): def read(self, chunk, cursor, context, file, selffile, parent, header=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:class:`~uproot4.reading.ReadOnlyFile.streamers`. - selffile (:py:class:`~uproot4.reading.CommonFileMethods`): A possibly - :py:class:`~uproot4.reading.DetachedFile` associated with this object. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:class:`~uproot.reading.ReadOnlyFile.streamers`. + selffile (:py:class:`~uproot.reading.CommonFileMethods`): A possibly + :py:class:`~uproot.reading.DetachedFile` associated with this object. parent (None or calling object): The previous ``read`` in the recursive descent. header (bool): If True, enable the container's - :py:attr:`~uproot4.containers.AsContainer.header`. + :py:attr:`~uproot.containers.AsContainer.header`. Read one object as part of a recursive descent. """ @@ -244,12 +241,12 @@ def __ne__(self, other): class AsDynamic(AsContainer): """ Args: - model (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): Optional + model (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): Optional description of the data, used in - :py:meth:`~uproot4.containers.AsDynamic.awkward_form` but ignored in - :py:meth:`~uproot4.containers.AsDynamic.read`. + :py:meth:`~uproot.containers.AsDynamic.awkward_form` but ignored in + :py:meth:`~uproot.containers.AsDynamic.read`. - A :py:class:`~uproot4.containers.AsContainer` for one object whose class may + A :py:class:`~uproot.containers.AsContainer` for one object whose class may not be known before reading. The byte-stream consists of a class name followed by instance data. Only @@ -263,8 +260,8 @@ def __init__(self, model=None): def model(self): """ Optional description of the data, used in - :py:meth:`~uproot4.containers.AsDynamic.awkward_form` but ignored in - :py:meth:`~uproot4.containers.AsDynamic.read`. + :py:meth:`~uproot.containers.AsDynamic.awkward_form` but ignored in + :py:meth:`~uproot.containers.AsDynamic.read`. """ return self._model @@ -292,14 +289,13 @@ def typename(self): return _content_typename(self._values) + "*" def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() if self._model is None: - raise uproot4.interpretation.objects.CannotBeAwkward("dynamic type") + raise uproot.interpretation.objects.CannotBeAwkward("dynamic type") else: - return awkward1.forms.ListOffsetForm( + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( self._model, file, index_format, header, tobject_header ), parameters={"uproot": {"as": "array", "header": self._header}}, @@ -317,12 +313,12 @@ class AsFIXME(AsContainer): Args: message (str): Required string, prefixes the error message. - A :py:class:`~uproot4.containers.AsContainer` for types that are known to be + A :py:class:`~uproot.containers.AsContainer` for types that are known to be unimplemented. The name is intended to be conspicuous, so that such cases may be more easily fixed. - :py:meth:`~uproot4.containers.AsFIXME.read` raises a - :py:exc:`~uproot4.deserialization.DeserializationError` asking for a bug-report. + :py:meth:`~uproot.containers.AsFIXME.read` raises a + :py:exc:`~uproot.deserialization.DeserializationError` asking for a bug-report. """ def __init__(self, message): @@ -343,10 +339,10 @@ def typename(self): return "unknown" def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - raise uproot4.interpretation.objects.CannotBeAwkward(self.message) + raise uproot.interpretation.objects.CannotBeAwkward(self.message) def read(self, chunk, cursor, context, file, selffile, parent, header=True): - raise uproot4.deserialization.DeserializationError( + raise uproot.deserialization.DeserializationError( self.message + "; please file a bug report!", None, None, None, None ) @@ -360,7 +356,7 @@ def __eq__(self, other): class AsString(AsContainer): """ Args: - header (bool): Sets the :py:attr:`~uproot4.containers.AsContainer.header`. + header (bool): Sets the :py:attr:`~uproot.containers.AsContainer.header`. length_bytes ("1-5" or "4"): Method used to determine the length of a string: "1-5" means one byte if the length is less than 256, otherwise the true length is in the next four bytes; "4" means @@ -368,19 +364,19 @@ class AsString(AsContainer): typename (None or str): If None, construct a plausible C++ typename. Otherwise, take the suggestion as given. - A :py:class:`~uproot4.containers.AsContainer` for strings nested withing other + A :py:class:`~uproot.containers.AsContainer` for strings nested withing other objects. - This is not an :py:class:`~uproot4.interpretation.Interpretation`; it *must* be - nested, at least within :py:class:`~uproot4.interpretation.objects.AsObjects`. + This is not an :py:class:`~uproot.interpretation.Interpretation`; it *must* be + nested, at least within :py:class:`~uproot.interpretation.objects.AsObjects`. - Note that the :py:class:`~uproot4.interpretation.strings.AsStrings` class is + Note that the :py:class:`~uproot.interpretation.strings.AsStrings` class is for a ``TBranch`` that contains only strings. - (:py:meth:`~uproot4.interpretation.objects.AsObjects.simplify` converts an - :py:class:`~uproot4.interpretation.objects.AsObjects` of - :py:class:`~uproot4.containers.AsString` into a - :py:class:`~uproot4.interpretation.strings.AsStrings`.) + (:py:meth:`~uproot.interpretation.objects.AsObjects.simplify` converts an + :py:class:`~uproot.interpretation.objects.AsObjects` of + :py:class:`~uproot.containers.AsString` into a + :py:class:`~uproot.interpretation.strings.AsStrings`.) """ def __init__(self, header, length_bytes="1-5", typename=None): @@ -421,11 +417,10 @@ def typename(self): return self._typename def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - awkward1.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": { @@ -443,7 +438,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): num_bytes, instance_version, is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) if self._length_bytes == "1-5": out = cursor.string(chunk, context) @@ -454,7 +449,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): raise AssertionError(repr(self._length_bytes)) if self._header and header: - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, start_cursor, cursor, @@ -477,17 +472,17 @@ def __eq__(self, other): class AsPointer(AsContainer): """ Args: - pointee (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): Optional + pointee (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): Optional description of the data, used in - :py:meth:`~uproot4.containers.AsPointer.awkward_form` but ignored in - :py:meth:`~uproot4.containers.AsPointer.read`. + :py:meth:`~uproot.containers.AsPointer.awkward_form` but ignored in + :py:meth:`~uproot.containers.AsPointer.read`. - A :py:class:`~uproot4.containers.AsContainer` for an object referred to by + A :py:class:`~uproot.containers.AsContainer` for an object referred to by pointer, meaning that it could be None (``nullptr``) or identical to an already-read object. The deserialization procedure calls - :py:func:`~uproot4.deserialization.read_object_any`. + :py:func:`~uproot.deserialization.read_object_any`. """ def __init__(self, pointee=None): @@ -497,8 +492,8 @@ def __init__(self, pointee=None): def pointee(self): """ Optional description of the data, used in - :py:meth:`~uproot4.containers.AsPointer.awkward_form` but ignored in - :py:meth:`~uproot4.containers.AsPointer.read`. + :py:meth:`~uproot.containers.AsPointer.awkward_form` but ignored in + :py:meth:`~uproot.containers.AsPointer.read`. """ return self._pointee @@ -529,10 +524,10 @@ def typename(self): return _content_typename(self._pointee) + "*" def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - raise uproot4.interpretation.objects.CannotBeAwkward("arbitrary pointer") + raise uproot.interpretation.objects.CannotBeAwkward("arbitrary pointer") def read(self, chunk, cursor, context, file, selffile, parent, header=True): - return uproot4.deserialization.read_object_any( + return uproot.deserialization.read_object_any( chunk, cursor, context, file, selffile, parent ) @@ -546,13 +541,13 @@ def __eq__(self, other): class AsArray(AsContainer): """ Args: - header (bool): Sets the :py:attr:`~uproot4.containers.AsContainer.header`. + header (bool): Sets the :py:attr:`~uproot.containers.AsContainer.header`. speedbump (bool): If True, one byte must be skipped before reading the data. - values (:py:class:`~uproot4.model.Model`, :py:class:`~uproot4.containers.Container`, or ``numpy.dtype``): Data + values (:py:class:`~uproot.model.Model`, :py:class:`~uproot.containers.Container`, or ``numpy.dtype``): Data type for data nested in the array. - A :py:class:`~uproot4.containers.AsContainer` for simple arrays (not + A :py:class:`~uproot.containers.AsContainer` for simple arrays (not ``std::vector``). """ @@ -572,7 +567,7 @@ def speedbump(self): def values(self): """ Data type for data nested in the array. May be a - :py:class:`~uproot4.model.Model`, :py:class:`~uproot4.containers.Container`, or + :py:class:`~uproot.model.Model`, :py:class:`~uproot.containers.Container`, or ``numpy.dtype``. """ return self._values @@ -595,11 +590,10 @@ def typename(self): return _content_typename(self._values) + "*" def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( self._values, file, index_format, header, tobject_header ), parameters={ @@ -618,7 +612,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): num_bytes, instance_version, is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) if is_memberwise: raise NotImplementedError( @@ -644,7 +638,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): ) if self._header and header: - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, start_cursor, cursor, @@ -677,11 +671,11 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): class AsVector(AsContainer): """ Args: - header (bool): Sets the :py:attr:`~uproot4.containers.AsContainer.header`. - values (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.Container`): Data + header (bool): Sets the :py:attr:`~uproot.containers.AsContainer.header`. + values (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.Container`): Data type for data nested in the container. - A :py:class:`~uproot4.containers.AsContainer` for ``std::vector``. + A :py:class:`~uproot.containers.AsContainer` for ``std::vector``. """ def __init__(self, header, values): @@ -689,7 +683,7 @@ def __init__(self, header, values): if isinstance(values, AsContainer): self._values = values elif isinstance(values, type) and issubclass( - values, (uproot4.model.Model, uproot4.model.DispatchByVersion) + values, (uproot.model.Model, uproot.model.DispatchByVersion) ): self._values = values else: @@ -723,11 +717,10 @@ def typename(self): return "std::vector<{0}>".format(_content_typename(self._values)) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( self._values, file, index_format, header, tobject_header ), parameters={"uproot": {"as": "vector", "header": self._header}}, @@ -740,7 +733,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): num_bytes, instance_version, is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) else: is_memberwise = False @@ -760,7 +753,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): out = STLVector(values) if self._header and header: - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, start_cursor, cursor, @@ -794,11 +787,11 @@ def __eq__(self, other): class AsSet(AsContainer): """ Args: - header (bool): Sets the :py:attr:`~uproot4.containers.AsContainer.header`. - keys (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.Container`): Data + header (bool): Sets the :py:attr:`~uproot.containers.AsContainer.header`. + keys (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.Container`): Data type for data nested in the container. - A :py:class:`~uproot4.containers.AsContainer` for ``std::set``. + A :py:class:`~uproot.containers.AsContainer` for ``std::set``. """ def __init__(self, header, keys): @@ -806,7 +799,7 @@ def __init__(self, header, keys): if isinstance(keys, AsContainer): self._keys = keys elif isinstance(keys, type) and issubclass( - keys, (uproot4.model.Model, uproot4.model.DispatchByVersion) + keys, (uproot.model.Model, uproot.model.DispatchByVersion) ): self._keys = keys else: @@ -838,11 +831,10 @@ def typename(self): return "std::set<{0}>".format(_content_typename(self._keys)) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( self._keys, file, index_format, header, tobject_header ), parameters={ @@ -858,7 +850,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): num_bytes, instance_version, is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) else: is_memberwise = False @@ -878,7 +870,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): out = STLSet(keys) if self._header and header: - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, start_cursor, cursor, @@ -917,13 +909,13 @@ def _has_nested_header(obj): class AsMap(AsContainer): """ Args: - header (bool): Sets the :py:attr:`~uproot4.containers.AsContainer.header`. - keys (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.Container`): Data + header (bool): Sets the :py:attr:`~uproot.containers.AsContainer.header`. + keys (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.Container`): Data type for the map's keys. - values (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.Container`): Data + values (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.Container`): Data type for the map's values. - A :py:class:`~uproot4.containers.AsContainer` for ``std::map``. + A :py:class:`~uproot.containers.AsContainer` for ``std::map``. """ def __init__(self, header, keys, values): @@ -937,7 +929,7 @@ def __init__(self, header, keys, values): if isinstance(values, AsContainer): self._values = values elif isinstance(values, type) and issubclass( - values, (uproot4.model.Model, uproot4.model.DispatchByVersion) + values, (uproot.model.Model, uproot.model.DispatchByVersion) ): self._values = values else: @@ -986,16 +978,15 @@ def typename(self): ) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - awkward1.forms.RecordForm( + awkward.forms.RecordForm( ( - uproot4._util.awkward_form( + uproot._util.awkward_form( self._keys, file, index_format, header, tobject_header ), - uproot4._util.awkward_form( + uproot._util.awkward_form( self._values, file, index_format, header, tobject_header ), ) @@ -1013,7 +1004,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): num_bytes, instance_version, is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) cursor.skip(6) else: is_memberwise = False @@ -1052,7 +1043,7 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): out = STLMap(keys, values) if self._header and header: - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, start_cursor, cursor, @@ -1215,7 +1206,7 @@ def __contains__(self, where): where = numpy.asarray(where) index = numpy.searchsorted(self._keys.astype(where.dtype), where, side="left") - if uproot4._util.isint(index): + if uproot._util.isint(index): if index < len(self._keys) and self._keys[index] == where: return True else: @@ -1260,7 +1251,7 @@ class STLMap(Container, Mapping): @classmethod def from_mapping(cls, mapping): """ - Construct a :py:class:`~uproot4.containers.STLMap` from a Python object with + Construct a :py:class:`~uproot.containers.STLMap` from a Python object with ``keys()`` and ``values()``. """ return STLMap(mapping.keys(), mapping.values()) @@ -1324,7 +1315,7 @@ def __getitem__(self, where): where = numpy.asarray(where) index = numpy.searchsorted(self._keys.astype(where.dtype), where, side="left") - if uproot4._util.isint(index): + if uproot._util.isint(index): if index < len(self._keys) and self._keys[index] == where: return self._values[index] else: @@ -1346,7 +1337,7 @@ def get(self, where, default=None): where = numpy.asarray(where) index = numpy.searchsorted(self._keys.astype(where.dtype), where, side="left") - if uproot4._util.isint(index): + if uproot._util.isint(index): if index < len(self._keys) and self._keys[index] == where: return self._values[index] else: @@ -1372,7 +1363,7 @@ def __contains__(self, where): where = numpy.asarray(where) index = numpy.searchsorted(self._keys.astype(where.dtype), where, side="left") - if uproot4._util.isint(index): + if uproot._util.isint(index): if index < len(self._keys) and self._keys[index] == where: return True else: @@ -1400,7 +1391,7 @@ def __eq__(self, other): def tolist(self): out = {} - for i in uproot4._util.range(len(self)): + for i in uproot._util.range(len(self)): x = self._values[i] if isinstance(x, (Container, numpy.ndarray)): out[self._keys[i]] = x.tolist() diff --git a/uproot4/deserialization.py b/uproot/deserialization.py similarity index 78% rename from uproot4/deserialization.py rename to uproot/deserialization.py index ec13f59eb..a84d61c90 100644 --- a/uproot4/deserialization.py +++ b/uproot/deserialization.py @@ -2,9 +2,9 @@ """ Defines low-level routines for deserialization, including -:py:func:`~uproot4.deserialization.compile_class`, which creates class objects from +:py:func:`~uproot.deserialization.compile_class`, which creates class objects from ``TStreamerInfo``-derived code, and -:py:func:`~uproot4.deserialization.read_object_any`, which manages references to +:py:func:`~uproot.deserialization.read_object_any`, which manages references to previously read objects. """ @@ -15,15 +15,13 @@ import numpy -import uproot4.const -import uproot4.model -import uproot4._util +import uproot scope = { "struct": struct, "numpy": numpy, - "uproot4": uproot4, + "uproot": uproot, } @@ -32,7 +30,7 @@ def _actually_compile(class_code, new_scope): def _yield_all_behaviors(cls, c): - behavior_cls = uproot4.behavior_of(uproot4.model.classname_decode(cls.__name__)[0]) + behavior_cls = uproot.behavior_of(uproot.model.classname_decode(cls.__name__)[0]) if behavior_cls is not None: yield behavior_cls if hasattr(cls, "base_names_versions"): @@ -44,15 +42,15 @@ def _yield_all_behaviors(cls, c): def compile_class(file, classes, class_code, class_name): """ Args: - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes as needed from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes as needed from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. classes (dict): MutableMapping in which to add the finished class. class_code (str): Python code string defining the new class. class_name (str): Python (encoded) name of the new class. See - :py:func:`~uproot4.model.classname_decode` and - :py:func:`~uproot4.model.classname_encode`. + :py:func:`~uproot.model.classname_decode` and + :py:func:`~uproot.model.classname_encode`. Compile a new class from Python code and insert it in the dict of classes. """ @@ -61,10 +59,10 @@ def compile_class(file, classes, class_code, class_name): new_scope[cls.__name__] = cls def c(name, version=None): - name = uproot4.model.classname_regularize(name) - cls = new_scope.get(uproot4.model.classname_encode(name, version)) + name = uproot.model.classname_regularize(name) + cls = new_scope.get(uproot.model.classname_encode(name, version)) if cls is None: - cls = new_scope.get(uproot4.model.classname_encode(name)) + cls = new_scope.get(uproot.model.classname_encode(name)) if cls is None: cls = file.class_named(name, version) return cls @@ -75,8 +73,8 @@ def c(name, version=None): out = new_scope[class_name] out.class_code = class_code - out.__module__ = "uproot4.dynamic" - setattr(uproot4.dynamic, out.__name__, out) + out.__module__ = "uproot.dynamic" + setattr(uproot.dynamic, out.__name__, out) behaviors = tuple(_yield_all_behaviors(out, c)) exclude = tuple( @@ -86,7 +84,7 @@ def c(name, version=None): out.behaviors = behaviors if len(behaviors) != 0: - out = uproot4._util.new_class(out.__name__, behaviors + (out,), {}) + out = uproot._util.new_class(out.__name__, behaviors + (out,), {}) return out @@ -98,9 +96,9 @@ def c(name, version=None): def numbytes_version(chunk, cursor, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the ``cursor`` to a position just past the @@ -119,14 +117,14 @@ def numbytes_version(chunk, cursor, context, move=True): num_bytes, version = cursor.fields(chunk, _numbytes_version_1, context, move=False) num_bytes = numpy.int64(num_bytes) - if num_bytes & uproot4.const.kByteCountMask: + if num_bytes & uproot.const.kByteCountMask: # Note this extra 4 bytes: the num_bytes field doesn't count itself, # but we count the Model.start_cursor position from the point just # before these two fields (since num_bytes might not exist, it's a more # stable point than after num_bytes). # | # V - num_bytes = int(num_bytes & ~uproot4.const.kByteCountMask) + 4 + num_bytes = int(num_bytes & ~uproot.const.kByteCountMask) + 4 if move: cursor.skip(_numbytes_version_1.size) @@ -134,9 +132,9 @@ def numbytes_version(chunk, cursor, context, move=True): num_bytes = None version = cursor.field(chunk, _numbytes_version_2, context, move=move) - is_memberwise = version & uproot4.const.kStreamedMemberWise + is_memberwise = version & uproot.const.kStreamedMemberWise if is_memberwise: - version = version & ~uproot4.const.kStreamedMemberWise + version = version & ~uproot.const.kStreamedMemberWise return num_bytes, version, is_memberwise @@ -146,11 +144,11 @@ def numbytes_check( ): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - start_cursor (:py:class:`~uproot4.source.cursor.Cursor`): Initial position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + start_cursor (:py:class:`~uproot.source.cursor.Cursor`): Initial position in that ``chunk``. - stop_cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + stop_cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. num_bytes (int or None): If an integer, the number of bytes to compare with the difference between ``start_cursor`` and ``stop_cursor``; @@ -162,7 +160,7 @@ def numbytes_check( Verifies that the number of bytes matches the change in position of the cursor (if ``num_bytes`` is not None). - Raises a :py:exc:`~uproot4.deserialization.DeserializationError` on failure. + Raises a :py:exc:`~uproot.deserialization.DeserializationError` on failure. """ if num_bytes is not None: observed = stop_cursor.displacement(start_cursor) @@ -184,33 +182,33 @@ def numbytes_check( def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=None): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes as needed from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes as needed from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. - selffile (:py:class:`~uproot4.reading.CommonFileMethods`): A possibly - :py:class:`~uproot4.reading.DetachedFile` associated with the ``parent``. + selffile (:py:class:`~uproot.reading.CommonFileMethods`): A possibly + :py:class:`~uproot.reading.DetachedFile` associated with the ``parent``. parent (None or calling object): The previous ``read`` in the recursive descent. - as_class (None or :py:class:`~uproot4.model.Model`): If None, use the class + as_class (None or :py:class:`~uproot.model.Model`): If None, use the class indicated in the byte stream; otherwise, use this class. Generic read function, which may deliver an instance of any class and may reference previously read objects. - This function is the reason why :py:class:`~uproot4.source.cursor.Cursor` has a - :py:attr:`~uproot4.source.cursor.Cursor.refs`; that dictionary holds previously + This function is the reason why :py:class:`~uproot.source.cursor.Cursor` has a + :py:attr:`~uproot.source.cursor.Cursor.refs`; that dictionary holds previously read objects that might need to be accessed later. - The :py:class:`~uproot4.source.cursor.Cursor` has an - :py:attr:`~uproot4.source.cursor.Cursor.origin` to account for the fact that + The :py:class:`~uproot.source.cursor.Cursor` has an + :py:attr:`~uproot.source.cursor.Cursor.origin` to account for the fact that seek positions for keys in the reference dict are relative to the start of - the :py:class:`~uproot4.source.chunk.Chunk`, rather than the start of the file + the :py:class:`~uproot.source.chunk.Chunk`, rather than the start of the file (as it would have to be for decompressed chunks). """ # TBufferFile::ReadObjectAny() @@ -220,9 +218,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non beg = cursor.displacement() bcnt = numpy.int64(cursor.field(chunk, _read_object_any_format1, context)) - if (bcnt & uproot4.const.kByteCountMask) == 0 or ( - bcnt == uproot4.const.kNewClassTag - ): + if (bcnt & uproot.const.kByteCountMask) == 0 or (bcnt == uproot.const.kNewClassTag): vers = 0 start = 0 tag = bcnt @@ -233,7 +229,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non tag = numpy.int64(cursor.field(chunk, _read_object_any_format1, context)) bcnt = int(bcnt) - if tag & uproot4.const.kClassMask == 0: + if tag & uproot.const.kClassMask == 0: # reference object if tag == 0: @@ -250,7 +246,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non else: return cursor.refs[int(tag)] # return object - elif tag == uproot4.const.kNewClassTag: + elif tag == uproot.const.kNewClassTag: # new class and object classname = cursor.classname(chunk, context) @@ -258,7 +254,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non cls = file.class_named(classname) if vers > 0: - cursor.refs[start + uproot4.const.kMapOffset] = cls + cursor.refs[start + uproot.const.kMapOffset] = cls else: cursor.refs[len(cursor.refs) + 1] = cls @@ -268,7 +264,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non obj = as_class.read(chunk, cursor, context, file, selffile, parent) if vers > 0: - cursor.refs[beg + uproot4.const.kMapOffset] = obj + cursor.refs[beg + uproot.const.kMapOffset] = obj else: cursor.refs[len(cursor.refs) + 1] = obj @@ -277,7 +273,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non else: # reference class, new object - ref = int(tag & ~uproot4.const.kClassMask) + ref = int(tag & ~uproot.const.kClassMask) if as_class is None: if ref not in cursor.refs: @@ -304,7 +300,7 @@ def read_object_any(chunk, cursor, context, file, selffile, parent, as_class=Non obj = as_class.read(chunk, cursor, context, file, selffile, parent) if vers > 0: - cursor.refs[beg + uproot4.const.kMapOffset] = obj + cursor.refs[beg + uproot.const.kMapOffset] = obj else: cursor.refs[len(cursor.refs) + 1] = obj @@ -318,20 +314,20 @@ class DeserializationError(Exception): """ Error raised when a ROOT file cannot be deserialized. - If the first attempt in :py:meth:`~uproot4.reading.ReadOnlyKey.get` failed with - predefined :py:class:`~uproot4.model.Model` classes, this exception is caught + If the first attempt in :py:meth:`~uproot.reading.ReadOnlyKey.get` failed with + predefined :py:class:`~uproot.model.Model` classes, this exception is caught and retried with ``TStreamerInfo``-derived classes, so - :py:exc:`~uproot4.deserialization.DeserializationError` sometimes appears in an + :py:exc:`~uproot.deserialization.DeserializationError` sometimes appears in an exception chain two levels deep. (Some ROOT files do have classes that don't match the standard ``TStreamerInfo``; they may have been produced from private builds of ROOT between official releases.) - If a :py:exc:`~uproot4.deserialization.DeserializationError` is caught, the byte + If a :py:exc:`~uproot.deserialization.DeserializationError` is caught, the byte stream at the position where it failed can be inspected with - * :py:meth:`~uproot4.deserialization.DeserializationError.debug` - * :py:meth:`~uproot4.deserialization.DeserializationError.debug_array` - * :py:attr:`~uproot4.deserialization.DeserializationError.partial_object` + * :py:meth:`~uproot.deserialization.DeserializationError.debug` + * :py:meth:`~uproot.deserialization.DeserializationError.debug_array` + * :py:attr:`~uproot.deserialization.DeserializationError.partial_object` """ def __init__(self, message, chunk, cursor, context, file_path): @@ -427,13 +423,13 @@ def debug( """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted deserialization. limit_bytes (None or int): Number of bytes to limit the output to. A line of debugging output (without any ``offset``) is 20 bytes, so multiples of 20 show full lines. If None, everything is - shown to the end of the :py:class:`~uproot4.source.chunk.Chunk`, + shown to the end of the :py:class:`~uproot.source.chunk.Chunk`, which might be large. dtype (None, ``numpy.dtype``, or its constructor argument): If None, present only the bytes as decimal values (0-255). Otherwise, @@ -481,14 +477,14 @@ def debug_array(self, skip_bytes=0, dtype=numpy.dtype("u1")): """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted deserialization. dtype (``numpy.dtype`` or its constructor argument): Data type in which to interpret the data. (The size of the array returned is truncated to this ``dtype.itemsize``.) - Like :py:meth:`~uproot4.deserialization.DeserializationError.debug`, but + Like :py:meth:`~uproot.deserialization.DeserializationError.debug`, but returns a NumPy array for further inspection. """ dtype = numpy.dtype(dtype) diff --git a/uproot4/dynamic.py b/uproot/dynamic.py similarity index 56% rename from uproot4/dynamic.py rename to uproot/dynamic.py index 7e6cf39b7..fb8892cd0 100644 --- a/uproot4/dynamic.py +++ b/uproot/dynamic.py @@ -3,24 +3,22 @@ """ Initially empty submodule into which new classes are dynamically added. -The purpose of this namespace is to allow :py:class:`~uproot4.model.VersionedModel` +The purpose of this namespace is to allow :py:class:`~uproot.model.VersionedModel` classes that were automatically generated from ROOT ``TStreamerInfo`` to be -pickled, with the help of :py:class:`~uproot4.model.DynamicModel`. +pickled, with the help of :py:class:`~uproot.model.DynamicModel`. In `Python 3.7 and later `__, attempts -to extract items from this namespace generate new :py:class:`~uproot4.model.DynamicModel` +to extract items from this namespace generate new :py:class:`~uproot.model.DynamicModel` classes, which are used as a container in which data from pickled -:py:class:`~uproot4.model.VersionedModel` instances are filled. +:py:class:`~uproot.model.VersionedModel` instances are filled. """ def __getattr__(name): - import uproot4.model - import uproot4.deserialization - import uproot4._util + import uproot g = globals() if name not in g: - g[name] = uproot4._util.new_class(name, (uproot4.model.DynamicModel,), {}) + g[name] = uproot._util.new_class(name, (uproot.model.DynamicModel,), {}) return g[name] diff --git a/uproot4/exceptions.py b/uproot/exceptions.py similarity index 89% rename from uproot4/exceptions.py rename to uproot/exceptions.py index 4f63d6ae8..6138e7610 100644 --- a/uproot4/exceptions.py +++ b/uproot/exceptions.py @@ -1,10 +1,14 @@ -from uproot4._util import damerau_levenshtein +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +from __future__ import absolute_import + +import uproot class KeyInFileError(KeyError): """ Exception raised by attempts to find ROOT objects in ``TDirectories`` - or ``TBranches`` in :py:class:`~uproot4.behaviors.TBranch.HasBranches`, which + or ``TBranches`` in :py:class:`~uproot.behaviors.TBranch.HasBranches`, which both have a Python ``Mapping`` interface (square bracket syntax to extract items). @@ -42,7 +46,7 @@ def __str__(self): if self.keys is not None: to_show = None sorted_keys = sorted( - self.keys, key=lambda x: damerau_levenshtein(self.key, x) + self.keys, key=lambda x: uproot._util.damerau_levenshtein(self.key, x) ) for key in sorted_keys: if to_show is None: diff --git a/uproot4/extras.py b/uproot/extras.py similarity index 96% rename from uproot4/extras.py rename to uproot/extras.py index f02d90cea..542cef222 100644 --- a/uproot4/extras.py +++ b/uproot/extras.py @@ -13,23 +13,23 @@ import os -def awkward1(): +def awkward(): """ - Imports and returns ``awkward1``. + Imports and returns ``awkward``. """ try: - import awkward1 + import awkward except ImportError: raise ImportError( - """install the 'awkward1' package with: + """install the 'awkward' package with: - pip install awkward1 + pip install awkward or use library="np" to output as NumPy arrays, rather than Awkward arrays. """ ) else: - return awkward1 + return awkward def pandas(): diff --git a/uproot4/interpretation/__init__.py b/uproot/interpretation/__init__.py similarity index 69% rename from uproot4/interpretation/__init__.py rename to uproot/interpretation/__init__.py index e4bc0cb22..7322d3e54 100644 --- a/uproot4/interpretation/__init__.py +++ b/uproot/interpretation/__init__.py @@ -4,11 +4,11 @@ Defines procedures for interpreting data in ``TTrees`` as arrays. All interpretations must be subclasses of -:py:class:`~uproot4.interpretation.Interpretation`. +:py:class:`~uproot.interpretation.Interpretation`. -See :py:func:`~uproot4.interpretation.identify.interpretation_of` for heuristics +See :py:func:`~uproot.interpretation.identify.interpretation_of` for heuristics that determine the default interpretation of a -:py:class:`~uproot4.behavior.TBranch.TBranch`. +:py:class:`~uproot.behavior.TBranch.TBranch`. """ from __future__ import absolute_import @@ -23,13 +23,13 @@ class Interpretation(object): 1. Producing temporary arrays from each uncompressed ``TBasket``. 2. Combining those temporary arrays for the whole range of entries requested between ``entry_start`` and ``entry_stop`` in - :py:meth:`~uproot4.behaviors.TBranch.HasBranches.arrays` or - :py:meth:`~uproot4.behaviors.TBranch.TBranch.array`, or by ``entry_step`` - in :py:meth:`~uproot4.behaviors.TBranch.TBranch.iterate`. + :py:meth:`~uproot.behaviors.TBranch.HasBranches.arrays` or + :py:meth:`~uproot.behaviors.TBranch.TBranch.array`, or by ``entry_step`` + in :py:meth:`~uproot.behaviors.TBranch.TBranch.iterate`. 3. Trimming the combined array to the exact entry range requested. (``TBasket`` boundaries might not align with the requested entry range.) 4. Passing the combined, trimmed temporary array to a selected - :py:class:`~uproot4.interpretation.library.Library` for finalization + :py:class:`~uproot.interpretation.library.Library` for finalization and possibly grouping. """ @@ -61,19 +61,19 @@ def numpy_dtype(self): def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): """ Args: - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. index_format (str): Format to use for indexes of the - ``awkward1.forms.Form``; may be ``"i32"``, ``"u32"``, or + ``awkward.forms.Form``; may be ``"i32"``, ``"u32"``, or ``"i64"``. header (bool): If True, include headers in the Form's ``"uproot"`` parameters. tobject_header (bool): If True, include headers for ``TObject`` classes in the Form's ``"uproot"`` parameters. - The ``awkward1.forms.Form`` to use to put objects of type type in an + The ``awkward.forms.Form`` to use to put objects of type type in an Awkward Array. """ raise AssertionError @@ -90,13 +90,13 @@ def basket_array( the ``TBasket`` starts and stops. The header is not included (i.e. the first offset is ``0``), and the length of this array is one greater than the number of entries in the ``TBasket``. - basket (:py:class:`~uproot4.models.TBasket.Model_TBasket`): The ``TBasket`` object. + basket (:py:class:`~uproot.models.TBasket.Model_TBasket`): The ``TBasket`` object. context (dict): Auxiliary data used in deserialization. cursor_offset (int): Correction to the integer keys used in - :py:attr:`~uproot4.source.cursor.Cursor.refs` for objects + :py:attr:`~uproot.source.cursor.Cursor.refs` for objects deserialized by reference - (:py:func:`~uproot4.deserialization.read_object_any`). - library (:py:class:`~uproot4.interpretation.library.Library`): The + (:py:func:`~uproot.deserialization.read_object_any`). + library (:py:class:`~uproot.interpretation.library.Library`): The requested library for output. Performs the first step of interpretation, from uncompressed ``TBasket`` @@ -111,18 +111,18 @@ def final_array( Args: basket_arrays (dict of int \u2192 array): Mapping from ``TBasket`` number to the temporary array returned by - :py:meth:`~uproot4.interpretation.Interpretation.basket_array`. + :py:meth:`~uproot.interpretation.Interpretation.basket_array`. entry_start (int): First entry to include when trimming any excess entries from the first ``TBasket``. entry_stop (int): FIrst entry to exclude (one greater than the last entry to include) when trimming any excess entries from the last ``TBasket``. entry_offsets (list of int): The - :py:attr:`~uproot4.behaviors.TBranch.TBranch.entry_offsets` for this + :py:attr:`~uproot.behaviors.TBranch.TBranch.entry_offsets` for this ``TBranch``. - library (:py:class:`~uproot4.interpretation.library.Library`): The + library (:py:class:`~uproot.interpretation.library.Library`): The requested library for output. - branch (:py:class:`~uproot4.behaviors.TBranch.TBranch`): The ``TBranch`` + branch (:py:class:`~uproot.behaviors.TBranch.TBranch`): The ``TBranch`` that is being interpreted. Performs the last steps of interpretation, from a collection of @@ -139,48 +139,48 @@ def __ne__(self, other): def hook_before_basket_array(self, *args, **kwargs): """ - Called in :py:meth:`~uproot4.interpretation.Interpretation.basket_array`, + Called in :py:meth:`~uproot.interpretation.Interpretation.basket_array`, before any interpretation. This is the first hook called in - :py:meth:`~uproot4.interpretation.Interpretation.basket_array`. + :py:meth:`~uproot.interpretation.Interpretation.basket_array`. """ pass def hook_after_basket_array(self, *args, **kwargs): """ - Called in :py:meth:`~uproot4.interpretation.Interpretation.basket_array`, + Called in :py:meth:`~uproot.interpretation.Interpretation.basket_array`, after all interpretation. This is the last hook called in - :py:meth:`~uproot4.interpretation.Interpretation.basket_array`. + :py:meth:`~uproot.interpretation.Interpretation.basket_array`. """ pass def hook_before_final_array(self, *args, **kwargs): """ - Called in :py:meth:`~uproot4.interpretation.Interpretation.final_array`, + Called in :py:meth:`~uproot.interpretation.Interpretation.final_array`, before any trimming, finalization, or grouping. This is the first hook called in - :py:meth:`~uproot4.interpretation.Interpretation.final_array`. + :py:meth:`~uproot.interpretation.Interpretation.final_array`. """ pass def hook_before_library_finalize(self, *args, **kwargs): """ - Called in :py:meth:`~uproot4.interpretation.Interpretation.final_array`, + Called in :py:meth:`~uproot.interpretation.Interpretation.final_array`, after trimming but before calling the - :py:meth:`~uproot4.interpretation.library.Library.finalize` routine. + :py:meth:`~uproot.interpretation.library.Library.finalize` routine. """ pass def hook_after_final_array(self, *args, **kwargs): """ - Called in :py:meth:`~uproot4.interpretation.Interpretation.final_array`, + Called in :py:meth:`~uproot.interpretation.Interpretation.final_array`, after all trimming, finalization, and grouping. This is the last hook called in - :py:meth:`~uproot4.interpretation.Interpretation.final_array`. + :py:meth:`~uproot.interpretation.Interpretation.final_array`. """ pass diff --git a/uproot4/interpretation/grouped.py b/uproot/interpretation/grouped.py similarity index 80% rename from uproot4/interpretation/grouped.py rename to uproot/interpretation/grouped.py index 8c9488c52..6e96ebe68 100644 --- a/uproot4/interpretation/grouped.py +++ b/uproot/interpretation/grouped.py @@ -1,34 +1,33 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines an :py:class:`~uproot4.interpretation.Interpretation` and temporary array +Defines an :py:class:`~uproot.interpretation.Interpretation` and temporary array for grouped data; usually applied to a ``TBranch`` that does not contain data but has subbranches that do. """ from __future__ import absolute_import -import uproot4.interpretation -import uproot4.extras +import uproot -class AsGrouped(uproot4.interpretation.Interpretation): +class AsGrouped(uproot.interpretation.Interpretation): u""" Args: - branch (:py:class:`~uproot4.behavior.TBranch.TBranch`): The ``TBranch`` that + branch (:py:class:`~uproot.behavior.TBranch.TBranch`): The ``TBranch`` that represents the group. - subbranches (dict of str \u2192 :py:class:`~uproot4.behavior.TBranch.TBranch`): Names + subbranches (dict of str \u2192 :py:class:`~uproot.behavior.TBranch.TBranch`): Names and interpretations of the ``TBranches`` that actually contain data. typename (None or str): If None, construct a plausible C++ typename. Otherwise, take the suggestion as given. Interpretation for a group of arrays, usually because they are all - subbranches of the same :py:class:`~uproot4.behavior.TBranch.TBranch`. + subbranches of the same :py:class:`~uproot.behavior.TBranch.TBranch`. - Each :py:class:`~uproot4.interpretation.library.Library` presents a group - differently: :py:class:`~uproot4.interpretation.library.NumPy` puts arrays - in a dict, :py:class:`~uproot4.interpretation.library.Awkward` makes an - array of records, :py:class:`~uproot4.interpretation.library.Pandas` makes + Each :py:class:`~uproot.interpretation.library.Library` presents a group + differently: :py:class:`~uproot.interpretation.library.NumPy` puts arrays + in a dict, :py:class:`~uproot.interpretation.library.Awkward` makes an + array of records, :py:class:`~uproot.interpretation.library.Pandas` makes a ``pandas.DataFrame``, etc. """ @@ -87,8 +86,7 @@ def typename(self): ) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - awkward1 = uproot4.extras.awkward1() - + awkward = uproot.extras.awkward() names = [] fields = [] for x, y in self._subbranches.items(): @@ -97,8 +95,7 @@ def awkward_form(self, file, index_format="i64", header=False, tobject_header=Tr fields.append( y.awkward_form(file, index_format, header, tobject_header) ) - - return awkward1.forms.RecordForm(fields, names) + return awkward.forms.RecordForm(fields, names) def basket_array( self, data, byte_offsets, basket, branch, context, cursor_offset, library diff --git a/uproot4/interpretation/identify.py b/uproot/interpretation/identify.py similarity index 78% rename from uproot4/interpretation/identify.py rename to uproot/interpretation/identify.py index dc63a48c7..1faa6843d 100644 --- a/uproot4/interpretation/identify.py +++ b/uproot/interpretation/identify.py @@ -2,11 +2,11 @@ """ Defines utilities for identifying the -:py:class:`~uproot4.interpretation.Interpretation` of a -:py:class:`~uproot4.behavior.TBranch.TBranch`. +:py:class:`~uproot.interpretation.Interpretation` of a +:py:class:`~uproot.behavior.TBranch.TBranch`. This includes a tokenizer/parser for C++ types and heuristics encoded in -:py:func:`~uproot4.interpretation.identify.interpretation_of`. The latter will +:py:func:`~uproot.interpretation.identify.interpretation_of`. The latter will need to be tweaked by new types, type combinations, and serialization methods observed in ROOT files (perhaps forever), unless a systematic study can be performed to exhaustively discover all cases. @@ -19,50 +19,43 @@ import numpy -import uproot4.const -import uproot4.interpretation.numerical -import uproot4.interpretation.strings -import uproot4.interpretation.objects -import uproot4.interpretation.grouped -import uproot4.containers -import uproot4.streamers -import uproot4._util +import uproot def _normalize_ftype(fType): - if fType is not None and uproot4.const.kOffsetL < fType < uproot4.const.kOffsetP: - return fType - uproot4.const.kOffsetL + if fType is not None and uproot.const.kOffsetL < fType < uproot.const.kOffsetP: + return fType - uproot.const.kOffsetL else: return fType def _ftype_to_dtype(fType): fType = _normalize_ftype(fType) - if fType == uproot4.const.kBool: + if fType == uproot.const.kBool: return numpy.dtype(numpy.bool_) - elif fType == uproot4.const.kChar: + elif fType == uproot.const.kChar: return numpy.dtype("i1") - elif fType == uproot4.const.kUChar: + elif fType == uproot.const.kUChar: return numpy.dtype("u1") - elif fType == uproot4.const.kShort: + elif fType == uproot.const.kShort: return numpy.dtype(">i2") - elif fType == uproot4.const.kUShort: + elif fType == uproot.const.kUShort: return numpy.dtype(">u2") - elif fType == uproot4.const.kInt: + elif fType == uproot.const.kInt: return numpy.dtype(">i4") - elif fType in (uproot4.const.kBits, uproot4.const.kUInt, uproot4.const.kCounter): + elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter): return numpy.dtype(">u4") - elif fType == uproot4.const.kLong: + elif fType == uproot.const.kLong: return numpy.dtype(">i8") - elif fType == uproot4.const.kULong: + elif fType == uproot.const.kULong: return numpy.dtype(">u8") - elif fType == uproot4.const.kLong64: + elif fType == uproot.const.kLong64: return numpy.dtype(">i8") - elif fType == uproot4.const.kULong64: + elif fType == uproot.const.kULong64: return numpy.dtype(">u8") - elif fType == uproot4.const.kFloat: + elif fType == uproot.const.kFloat: return numpy.dtype(">f4") - elif fType == uproot4.const.kDouble: + elif fType == uproot.const.kDouble: return numpy.dtype(">f8") else: raise NotNumerical() @@ -238,17 +231,17 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims): spec = eval(compile(transformed, repr(title), "eval")) if ( len(spec) == 2 - and uproot4._util.isnum(spec[0]) - and uproot4._util.isnum(spec[1]) + and uproot._util.isnum(spec[0]) + and uproot._util.isnum(spec[1]) ): low, high = spec num_bits = None elif ( len(spec) == 3 - and uproot4._util.isnum(spec[0]) - and uproot4._util.isnum(spec[1]) - and uproot4._util.isint(spec[2]) + and uproot._util.isnum(spec[0]) + and uproot._util.isnum(spec[1]) + and uproot._util.isint(spec[2]) ): low, high, num_bits = spec @@ -262,41 +255,39 @@ def _float16_or_double32(branch, context, leaf, is_float16, dims): if not is_float16: if num_bits == 0: - return uproot4.interpretation.numerical.AsDtype( + return uproot.interpretation.numerical.AsDtype( numpy.dtype((">f4", dims)), numpy.dtype(("f8", dims)) ) elif num_bits is None: - return uproot4.interpretation.numerical.AsDouble32(low, high, 32, dims) + return uproot.interpretation.numerical.AsDouble32(low, high, 32, dims) else: - return uproot4.interpretation.numerical.AsDouble32( - low, high, num_bits, dims - ) + return uproot.interpretation.numerical.AsDouble32(low, high, num_bits, dims) else: if num_bits == 0: - return uproot4.interpretation.numerical.AsFloat16(low, high, 12, dims) + return uproot.interpretation.numerical.AsFloat16(low, high, 12, dims) elif num_bits is None: - return uproot4.interpretation.numerical.AsFloat16(low, high, 32, dims) + return uproot.interpretation.numerical.AsFloat16(low, high, 32, dims) else: - return uproot4.interpretation.numerical.AsFloat16(low, high, num_bits, dims) + return uproot.interpretation.numerical.AsFloat16(low, high, num_bits, dims) def interpretation_of(branch, context, simplify=True): """ Args: - branch (:py:class:`~uproot4.behavior.TBranch.TBranch`): The ``TBranch`` to + branch (:py:class:`~uproot.behavior.TBranch.TBranch`): The ``TBranch`` to interpret as an array. context (dict): Auxiliary data used in deserialization. simplify (bool): If True, call - :py:meth:`~uproot4.interpretation.objects.AsObjects.simplify` on any - :py:class:`~uproot4.interpretation.objects.AsObjects` to try to get a + :py:meth:`~uproot.interpretation.objects.AsObjects.simplify` on any + :py:class:`~uproot.interpretation.objects.AsObjects` to try to get a more efficient interpretation. - Attempts to derive an :py:class:`~uproot4.interpretation.Interpretation` of the + Attempts to derive an :py:class:`~uproot.interpretation.Interpretation` of the ``branch`` (within some ``context``). If no interpretation can be found, it raises - :py:exc:`~uproot4.interpretation.identify.UnknownInterpretation`. + :py:exc:`~uproot.interpretation.identify.UnknownInterpretation`. """ if len(branch.branches) != 0: if branch.top_level and branch.has_member("fClassName"): @@ -306,7 +297,7 @@ def interpretation_of(branch, context, simplify=True): else: typename = None subbranches = dict((x.name, x.interpretation) for x in branch.branches) - return uproot4.interpretation.grouped.AsGrouped( + return uproot.interpretation.grouped.AsGrouped( branch, subbranches, typename=typename ) @@ -319,8 +310,8 @@ def interpretation_of(branch, context, simplify=True): inner_header=False, string_header=False, ) - return uproot4.interpretation.objects.AsObjects( - uproot4.containers.AsDynamic(model_cls), branch + return uproot.interpretation.objects.AsObjects( + uproot.containers.AsDynamic(model_cls), branch ) if branch.streamer is not None: @@ -332,12 +323,12 @@ def interpretation_of(branch, context, simplify=True): string_header=True, ) - return uproot4.interpretation.objects.AsObjects( - uproot4.containers.AsDynamic(model_cls), branch + return uproot.interpretation.objects.AsObjects( + uproot.containers.AsDynamic(model_cls), branch ) - return uproot4.interpretation.objects.AsObjects( - uproot4.containers.AsDynamic(), branch + return uproot.interpretation.objects.AsObjects( + uproot.containers.AsDynamic(), branch ) dims, is_jagged = _from_leaves(branch, context) @@ -349,15 +340,15 @@ def interpretation_of(branch, context, simplify=True): elif len(branch.member("fLeaves")) == 1: leaf = branch.member("fLeaves")[0] - leaftype = uproot4.const.kBase + leaftype = uproot.const.kBase if leaf.classname == "TLeafElement": leaftype = _normalize_ftype(leaf.member("fType")) is_float16 = ( - leaftype == uproot4.const.kFloat16 or leaf.classname == "TLeafF16" + leaftype == uproot.const.kFloat16 or leaf.classname == "TLeafF16" ) is_double32 = ( - leaftype == uproot4.const.kDouble32 or leaf.classname == "TLeafD32" + leaftype == uproot.const.kDouble32 or leaf.classname == "TLeafD32" ) if is_float16 or is_double32: out = _float16_or_double32(branch, context, leaf, is_float16, dims) @@ -370,14 +361,14 @@ def interpretation_of(branch, context, simplify=True): else: to_dtype = from_dtype - out = uproot4.interpretation.numerical.AsDtype( + out = uproot.interpretation.numerical.AsDtype( numpy.dtype((from_dtype, dims)), numpy.dtype((to_dtype, dims)) ) if leaf.member("fLeafCount") is None: return out else: - return uproot4.interpretation.jagged.AsJagged(out) + return uproot.interpretation.jagged.AsJagged(out) else: from_dtype = [] @@ -394,7 +385,7 @@ def interpretation_of(branch, context, simplify=True): if all( leaf.member("fLeafCount") is None for leaf in branch.member("fLeaves") ): - return uproot4.interpretation.numerical.AsDtype( + return uproot.interpretation.numerical.AsDtype( numpy.dtype((from_dtype, dims)), numpy.dtype((to_dtype, dims)) ) else: @@ -407,15 +398,15 @@ def interpretation_of(branch, context, simplify=True): except NotNumerical: if ( branch.member("fStreamerType", none_if_missing=True) - == uproot4.const.kTString + == uproot.const.kTString ): - return uproot4.interpretation.strings.AsStrings(typename="TString") + return uproot.interpretation.strings.AsStrings(typename="TString") if len(branch.member("fLeaves")) == 1: leaf = branch.member("fLeaves")[0] if leaf.classname == "TLeafC": - return uproot4.interpretation.strings.AsStrings() + return uproot.interpretation.strings.AsStrings() elif len(branch.member("fLeaves")) > 1: raise UnknownInterpretation( @@ -435,7 +426,7 @@ def interpretation_of(branch, context, simplify=True): string_header=False, ) - out = uproot4.interpretation.objects.AsObjects(model_cls, branch) + out = uproot.interpretation.objects.AsObjects(model_cls, branch) if simplify: return out.simplify() else: @@ -452,23 +443,23 @@ def interpretation_of(branch, context, simplify=True): # kObjectp/kAnyp (as opposed to kObjectP/kAnyP) are stored inline if isinstance( - model_cls, uproot4.containers.AsPointer + model_cls, uproot.containers.AsPointer ) and branch.streamer.member("fType") in ( - uproot4.const.kObjectp, - uproot4.const.kAnyp, + uproot.const.kObjectp, + uproot.const.kAnyp, ): - while isinstance(model_cls, uproot4.containers.AsPointer): + while isinstance(model_cls, uproot.containers.AsPointer): model_cls = model_cls.pointee if branch._streamer_isTClonesArray: - if isinstance(branch.streamer, uproot4.streamers.Model_TStreamerObject): - model_cls = uproot4.containers.AsArray(False, False, model_cls) + if isinstance(branch.streamer, uproot.streamers.Model_TStreamerObject): + model_cls = uproot.containers.AsArray(False, False, model_cls) else: if hasattr(model_cls, "header"): model_cls._header = False - model_cls = uproot4.containers.AsArray(True, False, model_cls) + model_cls = uproot.containers.AsArray(True, False, model_cls) - out = uproot4.interpretation.objects.AsObjects(model_cls, branch) + out = uproot.interpretation.objects.AsObjects(model_cls, branch) if simplify: return out.simplify() else: @@ -557,7 +548,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype("?"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype("?"))'.format( header ), quote, @@ -567,7 +558,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype("?"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype("?"))'.format( header ), quote, @@ -587,7 +578,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype("u1"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype("u1"))'.format( header ), quote, @@ -601,7 +592,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype("u1"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype("u1"))'.format( header ), quote, @@ -623,7 +614,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i2"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i2"))'.format( header ), quote, @@ -633,7 +624,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i2"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i2"))'.format( header ), quote, @@ -643,7 +634,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u2"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u2"))'.format( header ), quote, @@ -657,7 +648,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u2"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u2"))'.format( header ), quote, @@ -677,7 +668,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i4"))'.format( header ), quote, @@ -687,7 +678,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i4"))'.format( header ), quote, @@ -697,7 +688,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u4"))'.format( header ), quote, @@ -711,7 +702,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u4"))'.format( header ), quote, @@ -749,7 +740,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - 'uproot4.containers.AsArray({0}, numpy.dtype(">i8"))'.format(header), + 'uproot.containers.AsArray({0}, numpy.dtype(">i8"))'.format(header), quote, ), ) @@ -762,7 +753,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 3, _parse_maybe_quote( - 'uproot4.containers.AsArray({0}, numpy.dtype(">u8"))'.format(header), + 'uproot.containers.AsArray({0}, numpy.dtype(">u8"))'.format(header), quote, ), ) @@ -771,7 +762,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( header ), quote, @@ -781,7 +772,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( header ), quote, @@ -791,7 +782,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">i8"))'.format( header ), quote, @@ -801,7 +792,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( header ), quote, @@ -811,7 +802,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( header ), quote, @@ -825,7 +816,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">u8"))'.format( header ), quote, @@ -841,7 +832,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">f4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">f4"))'.format( header ), quote, @@ -851,7 +842,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">f4"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">f4"))'.format( header ), quote, @@ -867,7 +858,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">f8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">f8"))'.format( header ), quote, @@ -877,7 +868,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsArray(False, {0}, numpy.dtype(">f8"))'.format( + 'uproot.containers.AsArray(False, {0}, numpy.dtype(">f8"))'.format( header ), quote, @@ -888,7 +879,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsFIXME("Float16_t in another context")', quote + 'uproot.containers.AsFIXME("Float16_t in another context")', quote ), ) @@ -896,8 +887,8 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - "uproot4.containers.AsArray(False, {0}, " - 'uproot4.containers.AsFIXME("Float16_t in array"))'.format(header), + "uproot.containers.AsArray(False, {0}, " + 'uproot.containers.AsFIXME("Float16_t in array"))'.format(header), quote, ), ) @@ -906,7 +897,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - 'uproot4.containers.AsFIXME("Double32_t in another context")', quote + 'uproot.containers.AsFIXME("Double32_t in another context")', quote ), ) @@ -914,8 +905,8 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 1, _parse_maybe_quote( - "uproot4.containers.AsArray(False, {0}, " - 'uproot4.containers.AsFIXME("Double32_t in array ' + "uproot.containers.AsArray(False, {0}, " + 'uproot.containers.AsFIXME("Double32_t in array ' '(note: Event.root fClosestDistance has an example)"))'.format(header), quote, ), @@ -924,22 +915,20 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): elif tokens[i].group(0) == "string" or _simplify_token(tokens[i]) == "std::string": return ( i + 1, - _parse_maybe_quote( - "uproot4.containers.AsString({0})".format(header), quote - ), + _parse_maybe_quote("uproot.containers.AsString({0})".format(header), quote), ) elif tokens[i].group(0) == "TString": return ( i + 1, _parse_maybe_quote( - "uproot4.containers.AsString(False, typename='TString')", quote + "uproot.containers.AsString(False, typename='TString')", quote ), ) elif _simplify_token(tokens[i]) == "char*": return ( i + 1, _parse_maybe_quote( - "uproot4.containers.AsString(False, length_bytes='4', typename='char*')", + "uproot.containers.AsString(False, length_bytes='4', typename='char*')", quote, ), ) @@ -951,7 +940,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 2, _parse_maybe_quote( - "uproot4.containers.AsString(False, length_bytes='4', typename='char*')", + "uproot.containers.AsString(False, length_bytes='4', typename='char*')", quote, ), ) @@ -968,8 +957,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): return ( i + 4, _parse_maybe_quote( - 'uproot4.containers.AsFIXME("std::bitset<{0}>")'.format(num_bits), - quote, + 'uproot.containers.AsFIXME("std::bitset<{0}>")'.format(num_bits), quote, ), ) @@ -983,10 +971,10 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): if quote: return ( i + 1, - "uproot4.containers.AsVector({0}, {1})".format(header, values), + "uproot.containers.AsVector({0}, {1})".format(header, values), ) else: - return i + 1, uproot4.containers.AsVector(header, values) + return i + 1, uproot.containers.AsVector(header, values) elif tokens[i].group(0) == "set" or _simplify_token(tokens[i]) == "std::set": _parse_expect("<", tokens, i + 1, typename, file) @@ -996,9 +984,9 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): i = _parse_ignore_extra_arguments(tokens, i, typename, file, 2) _parse_expect(">", tokens, i, typename, file) if quote: - return i + 1, "uproot4.containers.AsSet({0}, {1})".format(header, keys) + return i + 1, "uproot.containers.AsSet({0}, {1})".format(header, keys) else: - return i + 1, uproot4.containers.AsSet(header, keys) + return i + 1, uproot.containers.AsSet(header, keys) elif tokens[i].group(0) == "map" or _simplify_token(tokens[i]) == "std::map": _parse_expect("<", tokens, i + 1, typename, file) @@ -1014,10 +1002,10 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): if quote: return ( i + 1, - "uproot4.containers.AsMap({0}, {1}, {2})".format(header, keys, values), + "uproot.containers.AsMap({0}, {1}, {2})".format(header, keys, values), ) else: - return i + 1, uproot4.containers.AsMap(header, keys, values) + return i + 1, uproot.containers.AsMap(header, keys, values) else: start, stop = tokens[i].span() @@ -1034,7 +1022,7 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): stop = tokens[i].span()[1] classname = _simplify_token(typename[start:stop], is_token=False) - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) pointers = 0 while classname.endswith("*"): @@ -1043,16 +1031,16 @@ def _parse_node(tokens, i, typename, file, quote, header, inner_header): if quote: cls = "c({0})".format(repr(classname)) - for x in uproot4._util.range(pointers): - cls = "uproot4.containers.AsPointer({0})".format(cls) + for x in uproot._util.range(pointers): + cls = "uproot.containers.AsPointer({0})".format(cls) elif file is None: - cls = uproot4.classes[classname] - for x in uproot4._util.range(pointers): - cls = uproot4.containers.AsPointer(cls) + cls = uproot.classes[classname] + for x in uproot._util.range(pointers): + cls = uproot.containers.AsPointer(cls) else: cls = file.class_named(classname) - for x in uproot4._util.range(pointers): - cls = uproot4.containers.AsPointer(cls) + for x in uproot._util.range(pointers): + cls = uproot.containers.AsPointer(cls) return i + 1, cls @@ -1068,19 +1056,19 @@ def parse_typename( """ Args: typename (str): The C++ type to parse. - file (None or :py:class:`~uproot4.reading.CommonFileMethods`): Used to provide + file (None or :py:class:`~uproot.reading.CommonFileMethods`): Used to provide error messages with the ``file_path``. quote (bool): If True, return the output as a string to evaluate. This - is used to build code for a :py:class:`~uproot4.model.Model`, rather than - the :py:class:`~uproot4.model.Model` itself. + is used to build code for a :py:class:`~uproot.model.Model`, rather than + the :py:class:`~uproot.model.Model` itself. outer_header (bool): If True, set the ``header`` flag for the outermost - :py:class:`~uproot4.containers.AsContainer` to True. + :py:class:`~uproot.containers.AsContainer` to True. inner_header (bool): If True, set the ``header`` flag for inner - :py:class:`~uproot4.containers.AsContainer` objects to True. + :py:class:`~uproot.containers.AsContainer` objects to True. string_header (bool): If True, set the ``header`` flag for - :py:class:`~uproot4.containers.AsString` objects to True. + :py:class:`~uproot.containers.AsString` objects to True. - Return a :py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer` + Return a :py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer` for the C++ ``typename``. """ tokens = list(_tokenize_typename_pattern.finditer(typename)) @@ -1093,7 +1081,7 @@ def parse_typename( or _simplify_token(tokens[0]) == "std::string" ) ): - i, out = 1, _parse_maybe_quote("uproot4.containers.AsString(False)", quote) + i, out = 1, _parse_maybe_quote("uproot.containers.AsString(False)", quote) else: i, out = _parse_node( @@ -1109,7 +1097,7 @@ def parse_typename( class NotNumerical(Exception): """ Exception used to stop searches for a numerical interpretation in - :py:func:`~uproot4.interpretation.identify.interpretation_of` as soon as a + :py:func:`~uproot.interpretation.identify.interpretation_of` as soon as a non-conforming type is found. """ @@ -1118,14 +1106,14 @@ class NotNumerical(Exception): class UnknownInterpretation(Exception): """ - Exception raised by :py:func:`~uproot4.interpretation.identify.interpretation_of` - if an :py:class:`~uproot4.interpretation.Interpretation` cannot be found. + Exception raised by :py:func:`~uproot.interpretation.identify.interpretation_of` + if an :py:class:`~uproot.interpretation.Interpretation` cannot be found. - The :py:attr:`~uproot4.behavior.TBranch.TBranch.interpretation` property may have - :py:exc:`~uproot4.interpretation.identify.UnknownInterpretation` as a value. + The :py:attr:`~uproot.behavior.TBranch.TBranch.interpretation` property may have + :py:exc:`~uproot.interpretation.identify.UnknownInterpretation` as a value. Any attempts to use this class as a - :py:class:`~uproot4.interpretation.Interpretation` causes it to raise itself. + :py:class:`~uproot.interpretation.Interpretation` causes it to raise itself. Thus, failing to find an interpretation for a ``TBranch`` is not a fatal error, but attempting to use it to deserialize arrays is a fatal error. """ diff --git a/uproot4/interpretation/jagged.py b/uproot/interpretation/jagged.py similarity index 88% rename from uproot4/interpretation/jagged.py rename to uproot/interpretation/jagged.py index 54635906b..187f6a180 100644 --- a/uproot4/interpretation/jagged.py +++ b/uproot/interpretation/jagged.py @@ -1,19 +1,19 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines an :py:class:`~uproot4.interpretation.Interpretation` and temporary array for +Defines an :py:class:`~uproot.interpretation.Interpretation` and temporary array for jagged (variable-length list) data. -The :py:class:`~uproot4.interpretation.jagged.JaggedArray` class only holds data while +The :py:class:`~uproot.interpretation.jagged.JaggedArray` class only holds data while an array is being built from ``TBaskets``. Its final form is determined by -:py:mod:`uproot4.interpretation.library`. +:py:mod:`uproot.interpretation.library`. """ from __future__ import absolute_import import numpy -import uproot4.interpretation +import uproot def fast_divide(array, divisor): @@ -33,27 +33,27 @@ def fast_divide(array, divisor): return numpy.floor_divide(array, divisor) -class AsJagged(uproot4.interpretation.Interpretation): +class AsJagged(uproot.interpretation.Interpretation): """ Args: - content (:py:class:`~uproot4.interpretation.numerical.AsDtype` or :py:class:`~uproot4.interpretation.objects.AsStridedObjects`): Interpretation + content (:py:class:`~uproot.interpretation.numerical.AsDtype` or :py:class:`~uproot.interpretation.objects.AsStridedObjects`): Interpretation for data in the nested, variable-length lists. header_bytes (int): Number of bytes to skip at the beginning of each entry. typename (None or str): If None, construct a plausible C++ typename. Otherwise, take the suggestion as given. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): If + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): If this interpretation is derived from - :py:meth:`~uproot4.interpretation.objects.AsObjects.simplify`, this is a + :py:meth:`~uproot.interpretation.objects.AsObjects.simplify`, this is a reminder of the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model`. Interpretation for any array that can be described as variable-length lists - of :py:class:`~uproot4.interpretation.numerical.AsDtype`. + of :py:class:`~uproot.interpretation.numerical.AsDtype`. """ def __init__(self, content, header_bytes=0, typename=None, original=None): - if not isinstance(content, uproot4.interpretation.numerical.Numerical): + if not isinstance(content, uproot.interpretation.numerical.Numerical): raise TypeError("AsJagged content can only be Numerical") self._content = content self._header_bytes = header_bytes @@ -63,8 +63,8 @@ def __init__(self, content, header_bytes=0, typename=None, original=None): @property def content(self): """ - The :py:class:`~uproot4.interpretation.numerical.AsDtype` or - :py:class:`~uproot4.interpretation.objects.AsStridedObjects` that interprets + The :py:class:`~uproot.interpretation.numerical.AsDtype` or + :py:class:`~uproot.interpretation.objects.AsStridedObjects` that interprets data in the nested, variable-length lists. """ return self._content @@ -80,9 +80,9 @@ def header_bytes(self): def original(self): """ If not None, this was the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model` from an - :py:class:`~uproot4.interpretation.objects.AsObjects` that was simplified - into this :py:class:`~uproot4.interpretation.jagged.AsJagged`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model` from an + :py:class:`~uproot.interpretation.objects.AsObjects` that was simplified + into this :py:class:`~uproot.interpretation.jagged.AsJagged`. """ return self._original @@ -106,11 +106,10 @@ def numpy_dtype(self): return numpy.dtype(numpy.object) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( self._content, file, index_format, header, tobject_header ), parameters={"uproot": {"as": "jagged", "header_bytes": self._header_bytes}}, @@ -150,7 +149,7 @@ def basket_array( if byte_offsets is None: counts = basket.counts if counts is None: - raise uproot4.deserialization.DeserializationError( + raise uproot.deserialization.DeserializationError( "missing offsets (and missing count branch) for jagged array", None, None, @@ -337,9 +336,9 @@ class JaggedArray(object): jagged array. Temporary array filled by - :py:meth:`~uproot4.interpretation.jagged.AsJagged.basket_array`, which will be + :py:meth:`~uproot.interpretation.jagged.AsJagged.basket_array`, which will be turned into a NumPy, Awkward, or other array, depending on the specified - :py:class:`~uproot4.interpretation.library.Library`. + :py:class:`~uproot.interpretation.library.Library`. """ def __init__(self, offsets, content): @@ -388,14 +387,14 @@ def parents_localindex(self, entry_start, entry_stop): Awkward 0 terminology. The "parents" is an array of integers with the same length as - :py:attr:`~uproot4.interpretation.jagged.JaggedArray.content` that indicates + :py:attr:`~uproot.interpretation.jagged.JaggedArray.content` that indicates which list each item belongs to. The "localindex" is an array of integers with the same length that indicates which subentry each item is, within its nested list. """ counts = self._offsets[1:] - self._offsets[:-1] - if uproot4._util.win: + if uproot._util.win: counts = counts.astype(numpy.int32) assert entry_stop - entry_start == len(self._offsets) - 1 diff --git a/uproot4/interpretation/library.py b/uproot/interpretation/library.py similarity index 81% rename from uproot4/interpretation/library.py rename to uproot/interpretation/library.py index 721320753..0e5e6ce2a 100644 --- a/uproot4/interpretation/library.py +++ b/uproot/interpretation/library.py @@ -4,26 +4,26 @@ Represents external libraries that define "array-like" types so that users can choose an output format. -The :py:class:`~uproot4.interpretation.library.NumPy` library always works (NumPy is +The :py:class:`~uproot.interpretation.library.NumPy` library always works (NumPy is Uproot's only strict dependency) and outputs NumPy arrays for single arrays and dict/tuple/list as groups. Objects and jagged arrays are not efficiently represented, but it provides a zero-dependency least common denominator. -The :py:class:`~uproot4.interpretation.library.Awkward` library is the default and -depends on Awkward Array (``awkward1``). It is usually the best option, as it +The :py:class:`~uproot.interpretation.library.Awkward` library is the default and +depends on Awkward Array (``awkward``). It is usually the best option, as it was designed for Uproot. -The :py:class:`~uproot4.interpretation.library.Pandas` library outputs +The :py:class:`~uproot.interpretation.library.Pandas` library outputs ``pandas.Series`` for single arrays and ``pandas.DataFrame`` as groups. Objects are not efficiently represented, but some jagged arrays are encoded as ``pandas.MultiIndex``. -The :py:class:`~uproot4.interpretation.library.CuPy` library outputs arrays on a +The :py:class:`~uproot.interpretation.library.CuPy` library outputs arrays on a GPU, but the types that it supports are limited. Note that Awkward Arrays can be GPU-resident as well. -Lazy arrays (:py:func:`~uproot4.behavior.TBranch.lazy`) can only use the -:py:class:`~uproot4.interpretation.library.Awkward` library. +Lazy arrays (:py:func:`~uproot.behavior.TBranch.lazy`) can only use the +:py:class:`~uproot.interpretation.library.Awkward` library. """ from __future__ import absolute_import @@ -33,11 +33,7 @@ import numpy -import uproot4.interpretation.jagged -import uproot4.interpretation.strings -import uproot4.interpretation.objects -import uproot4.containers -import uproot4.extras +import uproot def _rename(name, context): @@ -54,14 +50,14 @@ class Library(object): A library is used in the finalization and grouping stages of producing an array, converting it from internal representations like - :py:class:`~uproot4.interpretation.jagged.JaggedArray`, - :py:class:`~uproot4.interpretation.strings.StringArray`, and - :py:class:`~uproot4.interpretation.objects.ObjectArray` into the library's + :py:class:`~uproot.interpretation.jagged.JaggedArray`, + :py:class:`~uproot.interpretation.strings.StringArray`, and + :py:class:`~uproot.interpretation.objects.ObjectArray` into the library's equivalents. It can also be required for concatenation and other late-stage operations on the output arrays. Libraries are usually selected by a string name. These names are held in a - private registry in the :py:mod:`uproot4.interpretation.library` module. + private registry in the :py:mod:`uproot.interpretation.library` module. """ @property @@ -100,9 +96,9 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): Args: array (array): Internal, temporary, trimmed array. If this is a NumPy array, it may be identical to the output array. - branch (:py:class:`~uproot4.behavior.TBranch.TBranch`): The ``TBranch`` + branch (:py:class:`~uproot.behavior.TBranch.TBranch`): The ``TBranch`` that is represented by this array. - interpretation (:py:class:`~uproot4.interpretation.Interpretation`): The + interpretation (:py:class:`~uproot.interpretation.Interpretation`): The interpretation that produced the ``array``. entry_start (int): First entry that is included in the output. entry_stop (int): FIrst entry that is excluded (one greater than @@ -178,7 +174,7 @@ def __eq__(self, other): class NumPy(Library): u""" - A :py:class:`~uproot4.interpetation.library.Library` that presents ``TBranch`` + A :py:class:`~uproot.interpetation.library.Library` that presents ``TBranch`` data as NumPy arrays. The standard name for this library is ``"np"``. The single-``TBranch`` form for this library is a ``numpy.ndarray``. If @@ -206,8 +202,8 @@ def imported(self): return numpy def finalize(self, array, branch, interpretation, entry_start, entry_stop): - if isinstance(array, uproot4.interpretation.jagged.JaggedArray) and isinstance( - array.content, uproot4.interpretation.objects.StridedObjectArray, + if isinstance(array, uproot.interpretation.jagged.JaggedArray) and isinstance( + array.content, uproot.interpretation.objects.StridedObjectArray, ): out = numpy.zeros(len(array), dtype=numpy.object) for i, x in enumerate(array): @@ -219,10 +215,10 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): elif isinstance( array, ( - uproot4.interpretation.jagged.JaggedArray, - uproot4.interpretation.strings.StringArray, - uproot4.interpretation.objects.ObjectArray, - uproot4.interpretation.objects.StridedObjectArray, + uproot.interpretation.jagged.JaggedArray, + uproot.interpretation.strings.StringArray, + uproot.interpretation.objects.ObjectArray, + uproot.interpretation.objects.StridedObjectArray, ), ): out = numpy.zeros(len(array), dtype=numpy.object) @@ -238,7 +234,7 @@ def concatenate(self, all_arrays): return all_arrays if isinstance(all_arrays[0], (tuple, list)): - keys = uproot4._util.range(len(all_arrays[0])) + keys = uproot._util.range(len(all_arrays[0])) elif isinstance(all_arrays[0], dict): keys = list(all_arrays[0]) else: @@ -259,7 +255,7 @@ def concatenate(self, all_arrays): return concatenated -def _strided_to_awkward(awkward1, path, interpretation, data): +def _strided_to_awkward(awkward, path, interpretation, data): contents = [] names = [] for name, member in interpretation.members: @@ -267,25 +263,23 @@ def _strided_to_awkward(awkward1, path, interpretation, data): p = name if len(path) != 0: p = path + "/" + name - if isinstance(member, uproot4.interpretation.objects.AsStridedObjects): - contents.append(_strided_to_awkward(awkward1, p, member, data)) + if isinstance(member, uproot.interpretation.objects.AsStridedObjects): + contents.append(_strided_to_awkward(awkward, p, member, data)) else: contents.append( - awkward1.from_numpy( + awkward.from_numpy( numpy.array(data[p]), regulararray=True, highlevel=False ) ) names.append(name) parameters = { - "__record__": uproot4.model.classname_decode(interpretation.model.__name__)[0] + "__record__": uproot.model.classname_decode(interpretation.model.__name__)[0] } - return awkward1.layout.RecordArray( - contents, names, len(data), parameters=parameters - ) + return awkward.layout.RecordArray(contents, names, len(data), parameters=parameters) # FIXME: _object_to_awkward_json and _awkward_json_to_array are slow functions -# with the right outputs to be replaced by compiled versions in awkward1._io. +# with the right outputs to be replaced by compiled versions in awkward._io. def _object_to_awkward_json(form, obj): @@ -335,11 +329,11 @@ def _awkward_p(form): return out -def _awkward_json_to_array(awkward1, form, array): +def _awkward_json_to_array(awkward, form, array): if form["class"] == "NumpyArray": - if isinstance(array, awkward1.layout.EmptyArray): - dtype = awkward1.forms.Form.fromjson(json.dumps(form)).to_numpy() - return awkward1.layout.NumpyArray(numpy.empty(0, dtype=dtype)) + if isinstance(array, awkward.layout.EmptyArray): + dtype = awkward.forms.Form.fromjson(json.dumps(form)).to_numpy() + return awkward.layout.NumpyArray(numpy.empty(0, dtype=dtype)) else: return array @@ -348,36 +342,36 @@ def _awkward_json_to_array(awkward1, form, array): names = [] for name, subform in form["contents"].items(): if not name.startswith("@"): - contents.append(_awkward_json_to_array(awkward1, subform, array[name])) + contents.append(_awkward_json_to_array(awkward, subform, array[name])) names.append(name) - return awkward1.layout.RecordArray( + return awkward.layout.RecordArray( contents, names, len(array), parameters=_awkward_p(form) ) elif form["class"][:15] == "ListOffsetArray": if form["parameters"].get("__array__") == "string": - if isinstance(array, awkward1.layout.EmptyArray): - content = awkward1.layout.NumpyArray( + if isinstance(array, awkward.layout.EmptyArray): + content = awkward.layout.NumpyArray( numpy.empty(0, dtype=numpy.uint8), parameters=_awkward_p(form["content"]), ) - return awkward1.layout.ListOffsetArray64( - awkward1.layout.Index64(numpy.array([0], dtype=numpy.uint8)), + return awkward.layout.ListOffsetArray64( + awkward.layout.Index64(numpy.array([0], dtype=numpy.uint8)), content, parameters=_awkward_p(form), ) else: content = _awkward_json_to_array( - awkward1, form["content"], array.content + awkward, form["content"], array.content ) return type(array)(array.offsets, content, parameters=_awkward_p(form)) elif form["parameters"].get("__array__") == "sorted_map": key_form = form["content"]["contents"][0] value_form = form["content"]["contents"][1] - keys = _awkward_json_to_array(awkward1, key_form, array.content["0"]) - values = _awkward_json_to_array(awkward1, value_form, array.content["1"]) - content = awkward1.layout.RecordArray( + keys = _awkward_json_to_array(awkward, key_form, array.content["0"]) + values = _awkward_json_to_array(awkward, value_form, array.content["1"]) + content = awkward.layout.RecordArray( (keys, values), None, len(array.content), @@ -386,12 +380,12 @@ def _awkward_json_to_array(awkward1, form, array): return type(array)(array.offsets, content, parameters=_awkward_p(form)) else: - content = _awkward_json_to_array(awkward1, form["content"], array.content) + content = _awkward_json_to_array(awkward, form["content"], array.content) return type(array)(array.offsets, content, parameters=_awkward_p(form)) elif form["class"] == "RegularArray": - content = _awkward_json_to_array(awkward1, form["content"], array.content) - return awkward1.layout.RegularArray( + content = _awkward_json_to_array(awkward, form["content"], array.content) + return awkward.layout.RegularArray( content, form["size"], parameters=_awkward_p(form) ) @@ -401,14 +395,14 @@ def _awkward_json_to_array(awkward1, form, array): class Awkward(Library): u""" - A :py:class:`~uproot4.interpetation.library.Library` that presents ``TBranch`` + A :py:class:`~uproot.interpetation.library.Library` that presents ``TBranch`` data as Awkward Arrays. The standard name for this library is ``"ak"``. This is the default for all functions that require a - :py:class:`~uproot4.interpetation.library.Library`, though Uproot does not + :py:class:`~uproot.interpetation.library.Library`, though Uproot does not explicitly depend on Awkward Array. If you are confronted with a message - that Awkward Array is not installed, either install ``awkward1`` or - select another library (likely :py:class:`~uproot4.interpretation.library.NumPy`). + that Awkward Array is not installed, either install ``awkward`` or + select another library (likely :py:class:`~uproot.interpretation.library.NumPy`). Both the single-``TBranch`` and "group" forms for this library are ``ak.Array``, though groups are always arrays of records. Awkward Array @@ -430,79 +424,77 @@ class Awkward(Library): @property def imported(self): - return uproot4.extras.awkward1() + return uproot.extras.awkward() def finalize(self, array, branch, interpretation, entry_start, entry_stop): - awkward1 = self.imported + awkward = self.imported - if isinstance(array, awkward1.layout.Content): - return awkward1.Array(array) + if isinstance(array, awkward.layout.Content): + return awkward.Array(array) - elif isinstance(array, uproot4.interpretation.objects.StridedObjectArray): - return awkward1.Array( - _strided_to_awkward(awkward1, "", array.interpretation, array.array) + elif isinstance(array, uproot.interpretation.objects.StridedObjectArray): + return awkward.Array( + _strided_to_awkward(awkward, "", array.interpretation, array.array) ) - elif isinstance( - array, uproot4.interpretation.jagged.JaggedArray - ) and isinstance( - array.content, uproot4.interpretation.objects.StridedObjectArray + elif isinstance(array, uproot.interpretation.jagged.JaggedArray) and isinstance( + array.content, uproot.interpretation.objects.StridedObjectArray ): content = _strided_to_awkward( - awkward1, "", array.content.interpretation, array.content.array + awkward, "", array.content.interpretation, array.content.array ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward1.layout.Index32(array.offsets) - layout = awkward1.layout.ListOffsetArray32(offsets, content) + offsets = awkward.layout.Index32(array.offsets) + layout = awkward.layout.ListOffsetArray32(offsets, content) else: - offsets = awkward1.layout.Index64(array.offsets) - layout = awkward1.layout.ListOffsetArray64(offsets, content) - return awkward1.Array(layout) + offsets = awkward.layout.Index64(array.offsets) + layout = awkward.layout.ListOffsetArray64(offsets, content) + return awkward.Array(layout) - elif isinstance(array, uproot4.interpretation.jagged.JaggedArray): - content = awkward1.from_numpy( + elif isinstance(array, uproot.interpretation.jagged.JaggedArray): + content = awkward.from_numpy( array.content, regulararray=True, highlevel=False ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward1.layout.Index32(array.offsets) - layout = awkward1.layout.ListOffsetArray32(offsets, content) + offsets = awkward.layout.Index32(array.offsets) + layout = awkward.layout.ListOffsetArray32(offsets, content) else: - offsets = awkward1.layout.Index64(array.offsets) - layout = awkward1.layout.ListOffsetArray64(offsets, content) - return awkward1.Array(layout) + offsets = awkward.layout.Index64(array.offsets) + layout = awkward.layout.ListOffsetArray64(offsets, content) + return awkward.Array(layout) - elif isinstance(array, uproot4.interpretation.strings.StringArray): - content = awkward1.layout.NumpyArray( + elif isinstance(array, uproot.interpretation.strings.StringArray): + content = awkward.layout.NumpyArray( numpy.frombuffer(array.content, dtype=numpy.dtype(numpy.uint8)), parameters={"__array__": "char"}, ) if issubclass(array.offsets.dtype.type, numpy.int32): - offsets = awkward1.layout.Index32(array.offsets) - layout = awkward1.layout.ListOffsetArray32( + offsets = awkward.layout.Index32(array.offsets) + layout = awkward.layout.ListOffsetArray32( offsets, content, parameters={"__array__": "string"} ) elif issubclass(array.offsets.dtype.type, numpy.uint32): - offsets = awkward1.layout.IndexU32(array.offsets) - layout = awkward1.layout.ListOffsetArrayU32( + offsets = awkward.layout.IndexU32(array.offsets) + layout = awkward.layout.ListOffsetArrayU32( offsets, content, parameters={"__array__": "string"} ) elif issubclass(array.offsets.dtype.type, numpy.int64): - offsets = awkward1.layout.Index64(array.offsets) - layout = awkward1.layout.ListOffsetArray64( + offsets = awkward.layout.Index64(array.offsets) + layout = awkward.layout.ListOffsetArray64( offsets, content, parameters={"__array__": "string"} ) else: raise AssertionError(repr(array.offsets.dtype)) - return awkward1.Array(layout) + return awkward.Array(layout) - elif isinstance(interpretation, uproot4.interpretation.objects.AsObjects): + elif isinstance(interpretation, uproot.interpretation.objects.AsObjects): try: form = json.loads( interpretation.awkward_form(interpretation.branch.file).tojson( verbose=True ) ) - except uproot4.interpretation.objects.CannotBeAwkward as err: + except uproot.interpretation.objects.CannotBeAwkward as err: raise ValueError( """cannot produce Awkward Arrays for interpretation {0} because @@ -519,10 +511,10 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): ) ) - unlabeled = awkward1.from_iter( + unlabeled = awkward.from_iter( (_object_to_awkward_json(form, x) for x in array), highlevel=False ) - return awkward1.Array(_awkward_json_to_array(awkward1, form, unlabeled)) + return awkward.Array(_awkward_json_to_array(awkward, form, unlabeled)) elif array.dtype.names is not None: length, shape = array.shape[0], array.shape[1:] @@ -530,20 +522,20 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): contents = [] for name in array.dtype.names: contents.append( - awkward1.from_numpy( + awkward.from_numpy( numpy.array(array[name]), regulararray=True, highlevel=False ) ) - out = awkward1.layout.RecordArray(contents, array.dtype.names, length) + out = awkward.layout.RecordArray(contents, array.dtype.names, length) for size in shape[::-1]: - out = awkward1.layout.RegularArray(out, size) - return awkward1.Array(out) + out = awkward.layout.RegularArray(out, size) + return awkward.Array(out) else: - return awkward1.from_numpy(array, regulararray=True) + return awkward.from_numpy(array, regulararray=True) def group(self, arrays, expression_context, how): - awkward1 = self.imported + awkward = self.imported if how is tuple: return tuple(arrays[name] for name, _ in expression_context) @@ -555,9 +547,9 @@ def group(self, arrays, expression_context, how): ) elif how is None: if len(expression_context) == 0: - return awkward1.Array(awkward1.layout.RecordArray([], keys=[])) + return awkward.Array(awkward.layout.RecordArray([], keys=[])) else: - return awkward1.zip( + return awkward.zip( dict( (_rename(name, c), arrays[name]) for name, c in expression_context @@ -589,9 +581,9 @@ def group(self, arrays, expression_context, how): out = None if len(nonjagged) != 0: if len(nonjagged) == 0: - out = awkward1.Array(awkward1.layout.RecordArray([], keys=[])) + out = awkward.Array(awkward.layout.RecordArray([], keys=[])) else: - out = awkward1.zip( + out = awkward.zip( dict((name, renamed_arrays[name]) for name in nonjagged), depth_limit=1, ) @@ -609,31 +601,31 @@ def group(self, arrays, expression_context, how): if cut == 0: common = "jagged{0}".format(number) if len(jagged) == 0: - subarray = awkward1.Array( - awkward1.layout.RecordArray([], keys=[]) + subarray = awkward.Array( + awkward.layout.RecordArray([], keys=[]) ) else: - subarray = awkward1.zip( + subarray = awkward.zip( dict((name, renamed_arrays[name]) for name in jagged) ) else: common = jagged[0][:cut].strip("_./") if len(jagged) == 0: - subarray = awkward1.Array( - awkward1.layout.RecordArray([], keys=[]) + subarray = awkward.Array( + awkward.layout.RecordArray([], keys=[]) ) else: - subarray = awkward1.zip( + subarray = awkward.zip( dict( (name[cut:].strip("_./"), renamed_arrays[name]) for name in jagged ) ) if out is None: - out = awkward1.zip({common: subarray}, depth_limit=1) + out = awkward.zip({common: subarray}, depth_limit=1) else: for name in jagged: - out = awkward1.with_field(out, subarray, common) + out = awkward.with_field(out, subarray, common) return out else: raise TypeError( @@ -643,24 +635,24 @@ def group(self, arrays, expression_context, how): ) def concatenate(self, all_arrays): - awkward1 = self.imported + awkward = self.imported if len(all_arrays) == 0: return all_arrays if isinstance(all_arrays[0], (tuple, list)): - keys = uproot4._util.range(len(all_arrays[0])) + keys = uproot._util.range(len(all_arrays[0])) elif isinstance(all_arrays[0], dict): keys = list(all_arrays[0]) else: - return awkward1.concatenate(all_arrays) + return awkward.concatenate(all_arrays) to_concatenate = dict((k, []) for k in keys) for arrays in all_arrays: for k in keys: to_concatenate[k].append(arrays[k]) - concatenated = dict((k, awkward1.concatenate(to_concatenate[k])) for k in keys) + concatenated = dict((k, awkward.concatenate(to_concatenate[k])) for k in keys) if isinstance(all_arrays[0], tuple): return tuple(concatenated[k] for k in keys) @@ -680,7 +672,7 @@ def _strided_to_pandas(path, interpretation, data, arrays, columns): for name, member in interpretation.members: if not name.startswith("@"): p = path + (name,) - if isinstance(member, uproot4.interpretation.objects.AsStridedObjects): + if isinstance(member, uproot.interpretation.objects.AsStridedObjects): _strided_to_pandas(p, member, data, arrays, columns) else: arrays.append(data["/".join(p)]) @@ -691,7 +683,7 @@ def _pandas_basic_index(pandas, entry_start, entry_stop): if hasattr(pandas, "RangeIndex"): return pandas.RangeIndex(entry_start, entry_stop) else: - return pandas.Int64Index(uproot4._util.range(entry_start, entry_stop)) + return pandas.Int64Index(uproot._util.range(entry_start, entry_stop)) def _pandas_only_series(pandas, original_arrays, expression_context): @@ -718,7 +710,7 @@ def _pandas_only_series(pandas, original_arrays, expression_context): class Pandas(Library): u""" - A :py:class:`~uproot4.interpetation.library.Library` that presents ``TBranch`` + A :py:class:`~uproot.interpetation.library.Library` that presents ``TBranch`` data as Pandas Series and DataFrames. The standard name for this library is ``"pd"``. @@ -744,12 +736,12 @@ class Pandas(Library): @property def imported(self): - return uproot4.extras.pandas() + return uproot.extras.pandas() def finalize(self, array, branch, interpretation, entry_start, entry_stop): pandas = self.imported - if isinstance(array, uproot4.interpretation.objects.StridedObjectArray): + if isinstance(array, uproot.interpretation.objects.StridedObjectArray): arrays = [] columns = [] _strided_to_pandas((), array.interpretation, array.array, arrays, columns) @@ -767,10 +759,8 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): out.leaflist = maxlen != 1 return out - elif isinstance( - array, uproot4.interpretation.jagged.JaggedArray - ) and isinstance( - array.content, uproot4.interpretation.objects.StridedObjectArray + elif isinstance(array, uproot.interpretation.jagged.JaggedArray) and isinstance( + array.content, uproot.interpretation.objects.StridedObjectArray ): index = pandas.MultiIndex.from_arrays( array.parents_localindex(entry_start, entry_stop), @@ -794,7 +784,7 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): out.leaflist = maxlen != 1 return out - elif isinstance(array, uproot4.interpretation.jagged.JaggedArray): + elif isinstance(array, uproot.interpretation.jagged.JaggedArray): index = pandas.MultiIndex.from_arrays( array.parents_localindex(entry_start, entry_stop), names=["entry", "subentry"], @@ -804,8 +794,8 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): elif isinstance( array, ( - uproot4.interpretation.strings.StringArray, - uproot4.interpretation.objects.ObjectArray, + uproot.interpretation.strings.StringArray, + uproot.interpretation.objects.ObjectArray, ), ): out = numpy.zeros(len(array), dtype=numpy.object) @@ -819,7 +809,7 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): arrays = {} for n in array.dtype.names: for tup in itertools.product( - *[uproot4._util.range(d) for d in array.shape[1:]] + *[uproot._util.range(d) for d in array.shape[1:]] ): name = (n + "".join("[" + str(x) + "]" for x in tup),) names.append(name) @@ -841,7 +831,7 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): names = [] arrays = {} for tup in itertools.product( - *[uproot4._util.range(d) for d in array.shape[1:]] + *[uproot._util.range(d) for d in array.shape[1:]] ): name = "".join("[" + str(x) + "]" for x in tup) names.append(name) @@ -869,7 +859,7 @@ def group(self, arrays, expression_context, how): (_rename(name, c), arrays[name]) for name, c in expression_context ) - elif uproot4._util.isstr(how) or how is None: + elif uproot._util.isstr(how) or how is None: arrays, names = _pandas_only_series(pandas, arrays, expression_context) if any(isinstance(x, tuple) for x in names): @@ -1012,7 +1002,7 @@ def concatenate(self, all_arrays): return all_arrays if isinstance(all_arrays[0], (tuple, list)): - keys = uproot4._util.range(len(all_arrays[0])) + keys = uproot._util.range(len(all_arrays[0])) elif isinstance(all_arrays[0], dict): keys = list(all_arrays[0]) else: @@ -1035,7 +1025,7 @@ def concatenate(self, all_arrays): class CuPy(Library): u""" - A :py:class:`~uproot4.interpetation.library.Library` that presents ``TBranch`` + A :py:class:`~uproot.interpetation.library.Library` that presents ``TBranch`` data as CuPy arrays on a GPU. The standard name for this library is ``"cp"``. The single-``TBranch`` form for this library is a ``cupy.ndarray``. @@ -1057,7 +1047,7 @@ class CuPy(Library): @property def imported(self): - return uproot4.extras.cupy() + return uproot.extras.cupy() def empty(self, shape, dtype): cupy = self.imported @@ -1073,9 +1063,9 @@ def finalize(self, array, branch, interpretation, entry_start, entry_stop): if isinstance( array, ( - uproot4.interpretation.jagged.JaggedArray, - uproot4.interpretation.strings.StringArray, - uproot4.interpretation.objects.ObjectArray, + uproot.interpretation.jagged.JaggedArray, + uproot.interpretation.strings.StringArray, + uproot.interpretation.objects.ObjectArray, ), ): raise TypeError("jagged arrays and objects are not supported by CuPy") @@ -1091,7 +1081,7 @@ def concatenate(self, all_arrays): return all_arrays if isinstance(all_arrays[0], (tuple, list)): - keys = uproot4._util.range(len(all_arrays[0])) + keys = uproot._util.range(len(all_arrays[0])) elif isinstance(all_arrays[0], dict): keys = list(all_arrays[0]) else: @@ -1168,7 +1158,7 @@ def _regularize_library(library): except KeyError: raise ValueError( """library {0} not recognized (for this function); """ - """try "np" (NumPy), "ak" (Awkward1), "pd" (Pandas), or "cp" (CuPy) """ + """try "np" (NumPy), "ak" (Awkward Array), "pd" (Pandas), or "cp" (CuPy) """ """instead""".format(repr(library)) ) @@ -1210,6 +1200,6 @@ def _regularize_library_lazy(library): except KeyError: raise ValueError( """library {0} not recognized (for this function); """ - """try "ak" (Awkward1) """ + """try "ak" (Awkward Array) """ """instead""".format(repr(library)) ) diff --git a/uproot4/interpretation/numerical.py b/uproot/interpretation/numerical.py similarity index 88% rename from uproot4/interpretation/numerical.py rename to uproot/interpretation/numerical.py index 4705e699f..2c6098c5b 100644 --- a/uproot4/interpretation/numerical.py +++ b/uproot/interpretation/numerical.py @@ -1,27 +1,27 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines an :py:class:`~uproot4.interpretation.Interpretation` for several numerical +Defines an :py:class:`~uproot.interpretation.Interpretation` for several numerical types: -* :py:class:`~uproot4.interpretation.numerical.AsDtype`: numbers, which can simply be +* :py:class:`~uproot.interpretation.numerical.AsDtype`: numbers, which can simply be described as a ``numpy.dtype``. -* :py:class:`~uproot4.interpretation.numerical.AsDtypeInPlace`: a predefined array +* :py:class:`~uproot.interpretation.numerical.AsDtypeInPlace`: a predefined array into which data may be overwritten. -* :py:class:`~uproot4.interpretation.numerical.AsDouble32`: ROOT's ``Double32_t`` +* :py:class:`~uproot.interpretation.numerical.AsDouble32`: ROOT's ``Double32_t`` packed data type. -* :py:class:`~uproot4.interpretation.numerical.AsFloat16`: ROOT's ``Float16_t`` +* :py:class:`~uproot.interpretation.numerical.AsFloat16`: ROOT's ``Float16_t`` packed data type. -* :py:class:`~uproot4.interpretation.numerical.AsSTLBits`: an ``std::bitset`` +* :py:class:`~uproot.interpretation.numerical.AsSTLBits`: an ``std::bitset`` for some ``N``. """ from __future__ import absolute_import -import uproot4.interpretation - import numpy +import uproot + def _dtype_shape(dtype): shape = () @@ -31,13 +31,13 @@ def _dtype_shape(dtype): return dtype, shape -class Numerical(uproot4.interpretation.Interpretation): +class Numerical(uproot.interpretation.Interpretation): """ Abstract superclass of numerical interpretations, including - * :py:class:`~uproot4.interpretation.numerical.AsDtype` - * :py:class:`~uproot4.interpretation.numerical.AsSTLBits` - * :py:class:`~uproot4.interpretation.numerical.TruncatedNumerical` + * :py:class:`~uproot.interpretation.numerical.AsDtype` + * :py:class:`~uproot.interpretation.numerical.AsSTLBits` + * :py:class:`~uproot.interpretation.numerical.TruncatedNumerical` """ def _wrap_almost_finalized(self, array): @@ -199,7 +199,7 @@ def from_dtype(self): A shape (``dtype.shape``) can be used to construct a fixed-size array for each entry. (Not applicable to variable-length lists! See - :py:class:`~uproot4.interpretation.jagged.AsJagged`.) The finalized array's + :py:class:`~uproot.interpretation.jagged.AsJagged`.) The finalized array's ``array.shape[1:] == dtype.shape``. """ return self._from_dtype @@ -208,7 +208,7 @@ def from_dtype(self): def to_dtype(self): """ Data type to convert the data into. Usually the native-endian - equivalent of :py:meth:`~uproot4.interpretation.numerical.AsDtype.from_dtype`; + equivalent of :py:meth:`~uproot.interpretation.numerical.AsDtype.from_dtype`; may include named fields and a shape. Named fields (``dtype.names``) can be used to construct a NumPy @@ -216,7 +216,7 @@ def to_dtype(self): A shape (``dtype.shape``) can be used to construct a fixed-size array for each entry. (Not applicable to variable-length lists! See - :py:class:`~uproot4.interpretation.jagged.AsJagged`.) The finalized array's + :py:class:`~uproot.interpretation.jagged.AsJagged`.) The finalized array's ``array.shape[1:] == dtype.shape``. """ return self._to_dtype @@ -225,7 +225,7 @@ def to_dtype(self): def itemsize(self): """ Number of bytes per item of - :py:meth:`~uproot4.interpretation.numerical.AsDtype.from_dtype`. + :py:meth:`~uproot.interpretation.numerical.AsDtype.from_dtype`. This number of bytes includes the fields and shape, like ``dtype.itemsize`` in NumPy. @@ -237,12 +237,11 @@ def numpy_dtype(self): return self._to_dtype def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() d, s = _dtype_shape(self._to_dtype) - out = uproot4._util.awkward_form(d, file, index_format, header, tobject_header) + out = uproot._util.awkward_form(d, file, index_format, header, tobject_header) for size in s[::-1]: - out = awkward1.forms.RegularForm(out, size) + out = awkward.forms.RegularForm(out, size) return out @property @@ -347,7 +346,7 @@ def basket_array( class AsDtypeInPlace(AsDtype): """ - Like :py:class:`~uproot4.interpretation.numerical.AsDtype`, but a given array is + Like :py:class:`~uproot.interpretation.numerical.AsDtype`, but a given array is filled in-place, rather than creating a new output array. """ @@ -375,8 +374,8 @@ class TruncatedNumerical(Numerical): Subclasses are - * :py:class:`~uproot4.interpretation.numerical.AsDouble32` - * :py:class:`~uproot4.interpretation.numerical.AsFloat16` + * :py:class:`~uproot.interpretation.numerical.AsDouble32` + * :py:class:`~uproot.interpretation.numerical.AsFloat16` """ @property @@ -418,7 +417,7 @@ def from_dtype(self): def itemsize(self): """ Number of bytes in - :py:meth:`~uproot4.interpretation.numerical.TruncatedNumerical.from_dtype`. + :py:meth:`~uproot.interpretation.numerical.TruncatedNumerical.from_dtype`. """ return self.from_dtype.itemsize @@ -432,8 +431,8 @@ def to_dims(self): @property def is_truncated(self): """ - If True (:py:attr:`~uproot4.interpretation.numerical.TruncatedNumerical.low` - and :py:attr:`~uproot4.interpretation.numerical.TruncatedNumerical.high` are + If True (:py:attr:`~uproot.interpretation.numerical.TruncatedNumerical.low` + and :py:attr:`~uproot.interpretation.numerical.TruncatedNumerical.high` are both ``0``), the data are truly truncated. """ return self._low == 0.0 and self._high == 0.0 @@ -537,7 +536,7 @@ class AsDouble32(TruncatedNumerical): high (float): Upper bound on the range of expressible values. num_bits (int): Number of bits in the representation. to_dims (tuple of ints): Shape of - :py:meth:`~uproot4.interpretation.numerical.AsDouble32.to_dtype`. + :py:meth:`~uproot.interpretation.numerical.AsDouble32.to_dtype`. Interpretation for ROOT's ``Double32_t`` type. """ @@ -548,7 +547,7 @@ def __init__(self, low, high, num_bits, to_dims=()): self._num_bits = num_bits self._to_dims = to_dims - if not uproot4._util.isint(num_bits) or not 2 <= num_bits <= 32: + if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 32: raise TypeError("num_bits must be an integer between 2 and 32 (inclusive)") if high <= low and not self.is_truncated: raise ValueError( @@ -562,7 +561,7 @@ def to_dtype(self): A shape (``dtype.shape``) can be used to construct a fixed-size array for each entry. (Not applicable to variable-length lists! See - :py:class:`~uproot4.interpretation.jagged.AsJagged`.) The finalized array's + :py:class:`~uproot.interpretation.jagged.AsJagged`.) The finalized array's ``array.shape[1:] == dtype.shape``. """ return numpy.dtype((numpy.float64, self.to_dims)) @@ -572,9 +571,8 @@ def typename(self): return "Double32_t" + "".join("[" + str(dim) + "]" for dim in self._to_dims) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - out = awkward1.forms.NumpyForm( + awkward = uproot.extras.awkward() + out = awkward.forms.NumpyForm( (), 8, "d", @@ -588,7 +586,7 @@ def awkward_form(self, file, index_format="i64", header=False, tobject_header=Tr }, ) for size in self._to_dims[::-1]: - out = awkward1.forms.RegularForm(out, size) + out = awkward.forms.RegularForm(out, size) return out @@ -599,7 +597,7 @@ class AsFloat16(TruncatedNumerical): high (float): Upper bound on the range of expressible values. num_bits (int): Number of bits in the representation. to_dims (tuple of ints): Shape of - :py:attr:`~uproot4.interpretation.numerical.AsFloat16.to_dtype`. + :py:attr:`~uproot.interpretation.numerical.AsFloat16.to_dtype`. Interpretation for ROOT's ``Float16_t`` type. """ @@ -610,7 +608,7 @@ def __init__(self, low, high, num_bits, to_dims=()): self._num_bits = num_bits self._to_dims = to_dims - if not uproot4._util.isint(num_bits) or not 2 <= num_bits <= 16: + if not uproot._util.isint(num_bits) or not 2 <= num_bits <= 16: raise TypeError("num_bits must be an integer between 2 and 16 (inclusive)") if high <= low and not self.is_truncated: raise ValueError( @@ -624,7 +622,7 @@ def to_dtype(self): A shape (``dtype.shape``) can be used to construct a fixed-size array for each entry. (Not applicable to variable-length lists! See - :py:class:`~uproot4.interpretation.jagged.AsJagged`.) The finalized array's + :py:class:`~uproot.interpretation.jagged.AsJagged`.) The finalized array's ``array.shape[1:] == dtype.shape``. """ return numpy.dtype((numpy.float32, self.to_dims)) @@ -634,9 +632,8 @@ def typename(self): return "Float16_t" + "".join("[" + str(dim) + "]" for dim in self._to_dims) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - out = awkward1.forms.NumpyForm( + awkward = uproot.extras.awkward() + out = awkward.forms.NumpyForm( (), 4, "f", @@ -650,5 +647,5 @@ def awkward_form(self, file, index_format="i64", header=False, tobject_header=Tr }, ) for size in self._to_dims[::-1]: - out = awkward1.forms.RegularForm(out, size) + out = awkward.forms.RegularForm(out, size) return out diff --git a/uproot4/interpretation/objects.py b/uproot/interpretation/objects.py similarity index 71% rename from uproot4/interpretation/objects.py rename to uproot/interpretation/objects.py index fed17a4ec..7140abc41 100644 --- a/uproot4/interpretation/objects.py +++ b/uproot/interpretation/objects.py @@ -1,70 +1,62 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines an :py:class:`~uproot4.interpretation.Interpretation` and temporary array for +Defines an :py:class:`~uproot.interpretation.Interpretation` and temporary array for object data (Python objects or Awkward Array data structures). -The :py:class:`~uproot4.interpretation.objects.AsObjects` describes fully generic -objects using a :py:class:`~uproot4.interpretation.model.Model` (or a -:py:class:`~uproot4.interpretation.containers.AsContainer`). These objects require a +The :py:class:`~uproot.interpretation.objects.AsObjects` describes fully generic +objects using a :py:class:`~uproot.interpretation.model.Model` (or a +:py:class:`~uproot.interpretation.containers.AsContainer`). These objects require a non-vectorized loop to deserialize. -The :py:class:`~uproot4.interpretation.objects.AsStridedObjects` describes fixed-width +The :py:class:`~uproot.interpretation.objects.AsStridedObjects` describes fixed-width objects that can be described as a ``numpy.dtype``. These objects can be interpreted as a single, vectorized cast, and are therefore much faster to deserialize. -The :py:class:`~uproot4.interpretation.object.ObjectArray` and -:py:class:`~uproot4.interpretation.object.StridedObjectArray` classes only hold data +The :py:class:`~uproot.interpretation.object.ObjectArray` and +:py:class:`~uproot.interpretation.object.StridedObjectArray` classes only hold data while an array is being built from ``TBaskets``. Its final form is determined -by the :py:class:`~uproot4.interpretation.library.Library`. +by the :py:class:`~uproot.interpretation.library.Library`. """ from __future__ import absolute_import import numpy -import uproot4.interpretation -import uproot4.interpretation.strings -import uproot4.interpretation.jagged -import uproot4.interpretation.numerical -import uproot4.containers -import uproot4.model -import uproot4.source.chunk -import uproot4.source.cursor -import uproot4._util +import uproot def awkward_can_optimize(interpretation, form): """ If True, the Awkward Array library can convert data of a given - :py:class:`~uproot4.interpretation.Interpretation` and ``ak.forms.Form`` into + :py:class:`~uproot.interpretation.Interpretation` and ``ak.forms.Form`` into arrays without resorting to ``ak.from_iter`` (i.e. rapidly). - If ``awkward1._connect._uproot`` cannot be imported, this function always + If ``awkward._connect._uproot`` cannot be imported, this function always returns False. """ try: - import awkward1._connect._uproot + import awkward._connect._uproot except ImportError: return False else: - return awkward1._connect._uproot.can_optimize(interpretation, form) + return awkward._connect._uproot.can_optimize(interpretation, form) -class AsObjects(uproot4.interpretation.Interpretation): +class AsObjects(uproot.interpretation.Interpretation): """ Args: - model (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`): The + model (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`): The full Uproot deserialization model for the data. - branch (None or :py:class:`~uproot4.behavior.TBranch.TBranch`): The ``TBranch`` + branch (None or :py:class:`~uproot.behavior.TBranch.TBranch`): The ``TBranch`` from which the data are drawn. Integerpretation for arrays of any kind of data that might reside in a ROOT ``TTree``. This interpretation prescribes the full (slow) deserialization process. - :py:meth:`~uproot4.interpretation.objects.AsObjects.simplify` attempts to + :py:meth:`~uproot.interpretation.objects.AsObjects.simplify` attempts to replace this interpretation with a faster-to-read equivalent, but not all data types can be simplified. """ @@ -77,7 +69,7 @@ def __init__(self, model, branch=None): def model(self): """ The full Uproot deserialization model for the data - (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`). + (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`). """ return self._model @@ -104,15 +96,15 @@ def numpy_dtype(self): @property def cache_key(self): - content_key = uproot4.containers._content_cache_key(self._model) + content_key = uproot.containers._content_cache_key(self._model) return "{0}({1})".format(type(self).__name__, content_key) @property def typename(self): - if isinstance(self._model, uproot4.containers.AsContainer): + if isinstance(self._model, uproot.containers.AsContainer): return self._model.typename else: - return uproot4.model.classname_decode(self._model.__name__)[0] + return uproot.model.classname_decode(self._model.__name__)[0] def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): if isinstance(self._model, type): @@ -139,11 +131,11 @@ def basket_array( assert basket.byte_offsets is not None output = None - if isinstance(library, uproot4.interpretation.library.Awkward): + if isinstance(library, uproot.interpretation.library.Awkward): form = self.awkward_form(branch.file, index_format="i64") if awkward_can_optimize(self, form): - import awkward1._connect._uproot + import awkward._connect._uproot extra = { "interpretation": self, @@ -152,7 +144,7 @@ def basket_array( "context": context, "cursor_offset": cursor_offset, } - output = awkward1._connect._uproot.basket_array( + output = awkward._connect._uproot.basket_array( form, data, byte_offsets, extra ) @@ -209,11 +201,11 @@ def final_array( start = stop if all( - type(x).__module__.startswith("awkward1") for x in basket_arrays.values() + type(x).__module__.startswith("awkward") for x in basket_arrays.values() ): - assert isinstance(library, uproot4.interpretation.library.Awkward) - awkward1 = library.imported - output = awkward1.concatenate(trimmed, mergebool=False, highlevel=False) + assert isinstance(library, uproot.interpretation.library.Awkward) + awkward = library.imported + output = awkward.concatenate(trimmed, mergebool=False, highlevel=False) else: output = numpy.concatenate(trimmed) @@ -243,7 +235,7 @@ def final_array( def simplify(self): """ - Attempts to replace this :py:class:`~uproot4.interpretation.objects.AsObjects` + Attempts to replace this :py:class:`~uproot.interpretation.objects.AsObjects` with an interpretation that can be executed more quickly. If there isn't a simpler interpretation, then this method returns @@ -260,11 +252,11 @@ def simplify(self): except CannotBeStrided: pass - if isinstance(self._model, uproot4.containers.AsString): + if isinstance(self._model, uproot.containers.AsString): header_bytes = 0 if self._model.header: header_bytes = 6 - return uproot4.interpretation.strings.AsStrings( + return uproot.interpretation.strings.AsStrings( header_bytes, self._model.length_bytes, self._model.typename, @@ -272,23 +264,23 @@ def simplify(self): ) if isinstance( - self._model, (uproot4.containers.AsArray, uproot4.containers.AsVector), + self._model, (uproot.containers.AsArray, uproot.containers.AsVector), ): header_bytes = 0 if ( - isinstance(self._model, uproot4.containers.AsArray) + isinstance(self._model, uproot.containers.AsArray) and self._model.speedbump ): header_bytes += 1 if ( - isinstance(self._model, uproot4.containers.AsVector) + isinstance(self._model, uproot.containers.AsVector) and self._model.header ): header_bytes += 10 if isinstance(self._model.values, numpy.dtype): - content = uproot4.interpretation.numerical.AsDtype(self._model.values) - return uproot4.interpretation.jagged.AsJagged( + content = uproot.interpretation.numerical.AsDtype(self._model.values) + return uproot.interpretation.jagged.AsJagged( content, header_bytes, self._model.typename, original=self._model ) @@ -300,7 +292,7 @@ def simplify(self): tobject_header=True, original=self._model.values, ) - return uproot4.interpretation.jagged.AsJagged( + return uproot.interpretation.jagged.AsJagged( content, header_bytes, self._model.typename, @@ -324,14 +316,14 @@ def _unravel_members(members): def _strided_awkward_form( - awkward1, classname, members, file, index_format, header, tobject_header + awkward, classname, members, file, index_format, header, tobject_header ): contents = {} for name, member in members: if isinstance(member, AsStridedObjects): - cname = uproot4.model.classname_decode(member._model.__name__)[0] + cname = uproot.model.classname_decode(member._model.__name__)[0] contents[name] = _strided_awkward_form( - awkward1, + awkward, cname, member._members, file, @@ -340,39 +332,39 @@ def _strided_awkward_form( tobject_header, ) else: - contents[name] = uproot4._util.awkward_form( + contents[name] = uproot._util.awkward_form( member, file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm(contents, parameters={"__record__": classname}) + return awkward.forms.RecordForm(contents, parameters={"__record__": classname}) -class AsStridedObjects(uproot4.interpretation.numerical.AsDtype): +class AsStridedObjects(uproot.interpretation.numerical.AsDtype): """ Args: - model (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`): The + model (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`): The full Uproot deserialization model for the data. - members (list of (str, :py:class:`~uproot4.interpretation.Interpretation`) tuples): The + members (list of (str, :py:class:`~uproot.interpretation.Interpretation`) tuples): The name and fixed-width interpretation for each member of the objects. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.AsContainer`): If + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.AsContainer`): If this interpretation is derived from - :py:meth:`~uproot4.interpretation.objects.AsObjects.simplify`, this is a + :py:meth:`~uproot.interpretation.objects.AsObjects.simplify`, this is a reminder of the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model`. Interpretation for an array (possibly - :py:class:`~uproot4.interpretation.jagged.AsJagged`) of fixed-size objects. Since + :py:class:`~uproot.interpretation.jagged.AsJagged`) of fixed-size objects. Since the objects have a fixed number of fields with a fixed number of bytes each, - the whole array (or :py:attr:`~uproot4.interpretation.jagged.AsJagged.content`) + the whole array (or :py:attr:`~uproot.interpretation.jagged.AsJagged.content`) can be interpreted in one vectorized array-cast. Therefore, this - interpretation is faster than :py:class:`~uproot4.interpretation.objects.AsObjects` + interpretation is faster than :py:class:`~uproot.interpretation.objects.AsObjects` *when it is possible*. - Unlike :py:class:`~uproot4.interpretation.numerical.AsDtype` with a + Unlike :py:class:`~uproot.interpretation.numerical.AsDtype` with a `structured array `__, the objects in the final array have the methods required by its ``model``. - If the ``library`` is :py:class:`~uproot4.interpretation.library.NumPy`, these + If the ``library`` is :py:class:`~uproot.interpretation.library.NumPy`, these are instantiated as Python objects (slow); if - :py:class:`~uproot4.interpretation.library.Awkward`, they are behaviors passed to + :py:class:`~uproot.interpretation.library.Awkward`, they are behaviors passed to the Awkward Array's local `behavior `__. """ @@ -387,7 +379,7 @@ def __init__(self, model, members, original=None): def model(self): """ The full Uproot deserialization model for the data - (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`). + (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`). """ return self._model @@ -395,7 +387,7 @@ def model(self): def members(self): """ The name (str) and fixed-width - :py:class:`~uproot4.interpretation.Interpretation` for each member of the + :py:class:`~uproot.interpretation.Interpretation` for each member of the objects as a list of 2-tuple pairs. """ return self._members @@ -404,9 +396,9 @@ def members(self): def original(self): """ If not None, this was the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model` from an - :py:class:`~uproot4.interpretation.objects.AsObjects` that was simplified - into this :py:class:`~uproot4.interpretation.objects.AsStridedObjects`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model` from an + :py:class:`~uproot.interpretation.objects.AsObjects` that was simplified + into this :py:class:`~uproot.interpretation.objects.AsStridedObjects`. """ return self._original @@ -421,11 +413,10 @@ def numpy_dtype(self): return numpy.dtype(numpy.object) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - cname = uproot4.model.classname_decode(self._model.__name__)[0] + awkward = uproot.extras.awkward() + cname = uproot.model.classname_decode(self._model.__name__)[0] return _strided_awkward_form( - awkward1, cname, self._members, file, index_format, header, tobject_header + awkward, cname, self._members, file, index_format, header, tobject_header ) @property @@ -434,7 +425,7 @@ def cache_key(self): @property def typename(self): - return uproot4.model.classname_decode(self._model.__name__)[0] + return uproot.model.classname_decode(self._model.__name__)[0] def _wrap_almost_finalized(self, array): return StridedObjectArray(self, array) @@ -443,8 +434,8 @@ def _wrap_almost_finalized(self, array): class CannotBeStrided(Exception): """ Exception used to stop recursion over - :py:meth:`~uproot4.model.Model.strided_interpretation` and - :py:meth:`~uproot4.containers.AsContainer.strided_interpretation` as soon as a + :py:meth:`~uproot.model.Model.strided_interpretation` and + :py:meth:`~uproot.containers.AsContainer.strided_interpretation` as soon as a non-conforming type is found. """ @@ -454,9 +445,9 @@ class CannotBeStrided(Exception): class CannotBeAwkward(Exception): """ Exception used to stop recursion over - :py:meth:`~uproot4.interpretation.Interpretation.awkward_form`, - :py:meth:`~uproot4.model.Model.awkward_form` and - :py:meth:`~uproot4.containers.AsContainer.awkward_form` as soon as a + :py:meth:`~uproot.interpretation.Interpretation.awkward_form`, + :py:meth:`~uproot.model.Model.awkward_form` and + :py:meth:`~uproot.containers.AsContainer.awkward_form` as soon as a non-conforming type is found. """ @@ -467,24 +458,24 @@ def __init__(self, because): class ObjectArray(object): """ Args: - model (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`): The + model (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`): The full Uproot deserialization model for the data. - branch (:py:class:`~uproot4.behavior.TBranch.TBranch`): The ``TBranch`` from + branch (:py:class:`~uproot.behavior.TBranch.TBranch`): The ``TBranch`` from which the data are drawn. context (dict): Auxiliary data used in deserialization. byte_offsets (array of ``numpy.int32``): Index where each entry of the ``byte_content`` starts and stops. byte_content (array of ``numpy.uint8``): Raw but uncompressed data, directly from - :py:meth:`~uproot4.interpretation.Interpretation.basket_array`. + :py:meth:`~uproot.interpretation.Interpretation.basket_array`. cursor_offset (int): Correction to the integer keys used in - :py:attr:`~uproot4.source.cursor.Cursor.refs` for objects deserialized - by reference (:py:func:`~uproot4.deserialization.read_object_any`). + :py:attr:`~uproot.source.cursor.Cursor.refs` for objects deserialized + by reference (:py:func:`~uproot.deserialization.read_object_any`). Temporary array filled by - :py:meth:`~uproot4.interpretation.objects.AsObjects.basket_array`, which will be + :py:meth:`~uproot.interpretation.objects.AsObjects.basket_array`, which will be turned into a NumPy, Awkward, or other array, depending on the specified - :py:class:`~uproot4.interpretation.library.Library`. + :py:class:`~uproot.interpretation.library.Library`. """ def __init__( @@ -512,7 +503,7 @@ def __repr__(self): def model(self): """ The full Uproot deserialization model for the data - (:py:class:`~uproot4.model.Model` or :py:class:`~uproot4.containers.AsContainer`). + (:py:class:`~uproot.model.Model` or :py:class:`~uproot.containers.AsContainer`). """ return self._model @@ -541,7 +532,7 @@ def byte_offsets(self): def byte_content(self): """ Raw but uncompressed data, directly from - :py:meth:`~uproot4.interpretation.Interpretation.basket_array`. + :py:meth:`~uproot.interpretation.Interpretation.basket_array`. """ return self._byte_content @@ -549,8 +540,8 @@ def byte_content(self): def cursor_offset(self): """ Correction to the integer keys used in - :py:attr:`~uproot4.source.cursor.Cursor.refs` for objects deserialized by - reference (:py:func:`~uproot4.deserialization.read_object_any`). + :py:attr:`~uproot.source.cursor.Cursor.refs` for objects deserialized by + reference (:py:func:`~uproot.deserialization.read_object_any`). """ return self._cursor_offset @@ -567,12 +558,12 @@ def __len__(self): return len(self._byte_offsets) - 1 def __getitem__(self, where): - if uproot4._util.isint(where): + if uproot._util.isint(where): byte_start = self._byte_offsets[where] byte_stop = self._byte_offsets[where + 1] data = self._byte_content[byte_start:byte_stop] - chunk = uproot4.source.chunk.Chunk.wrap(self._branch.file.source, data) - cursor = uproot4.source.cursor.Cursor( + chunk = uproot.source.chunk.Chunk.wrap(self._branch.file.source, data) + cursor = uproot.source.cursor.Cursor( 0, origin=-(byte_start + self._cursor_offset) ) return self._model.read( @@ -606,8 +597,8 @@ def __iter__(self): byte_start = self._byte_offsets[0] for byte_stop in self._byte_offsets[1:]: data = self._byte_content[byte_start:byte_stop] - chunk = uproot4.source.chunk.Chunk.wrap(source, data) - cursor = uproot4.source.cursor.Cursor(0, origin=-self._cursor_offset) + chunk = uproot.source.chunk.Chunk.wrap(source, data) + cursor = uproot.source.cursor.Cursor(0, origin=-self._cursor_offset) yield self._model.read(chunk, cursor, context, file, selffile, branch) byte_start = byte_stop @@ -628,15 +619,15 @@ def _strided_object(path, interpretation, data): class StridedObjectArray(object): """ Args: - interpretation (:py:class:`~uproot4.interpretation.objects.AsStridedObjects`): The + interpretation (:py:class:`~uproot.interpretation.objects.AsStridedObjects`): The interpretation that produced this array. array (array): Underlying array object, which may be NumPy or another temporary array. Temporary array filled by - :py:meth:`~uproot4.interpretation.objects.AsStridedObjects.basket_array`, which + :py:meth:`~uproot.interpretation.objects.AsStridedObjects.basket_array`, which will be turned into a NumPy, Awkward, or other array, depending on the - specified :py:class:`~uproot4.interpretation.library.Library`. + specified :py:class:`~uproot.interpretation.library.Library`. """ def __init__(self, interpretation, array): @@ -664,7 +655,7 @@ def __len__(self): return len(self._array) def __getitem__(self, where): - if uproot4._util.isint(where): + if uproot._util.isint(where): return _strided_object("", self._interpretation, self._array[where]) else: diff --git a/uproot4/interpretation/strings.py b/uproot/interpretation/strings.py similarity index 86% rename from uproot4/interpretation/strings.py rename to uproot/interpretation/strings.py index eea51b1b0..71488d24f 100644 --- a/uproot4/interpretation/strings.py +++ b/uproot/interpretation/strings.py @@ -1,16 +1,16 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines an :py:class:`~uproot4.interpretation.Interpretation` and temporary array for +Defines an :py:class:`~uproot.interpretation.Interpretation` and temporary array for string data. -Note that :py:class:`~uproot4.interpretation.strings.AsStrings` is an interpretation for -top-level strings, but :py:class:`~uproot4.containers.AsString` can be nested within any -other :py:class:`~uproot4.containers.AsContainer`. +Note that :py:class:`~uproot.interpretation.strings.AsStrings` is an interpretation for +top-level strings, but :py:class:`~uproot.containers.AsString` can be nested within any +other :py:class:`~uproot.containers.AsContainer`. -The :py:class:`~uproot4.interpretation.strings.StringArray` class only holds data while +The :py:class:`~uproot.interpretation.strings.StringArray` class only holds data while an array is being built from ``TBaskets``. Its final form is determined by the -:py:class:`~uproot4.interpretation.library.Library`. +:py:class:`~uproot.interpretation.library.Library`. """ from __future__ import absolute_import @@ -19,13 +19,13 @@ import numpy -import uproot4.interpretation +import uproot _string_4byte_size = struct.Struct(">I") -class AsStrings(uproot4.interpretation.Interpretation): +class AsStrings(uproot.interpretation.Interpretation): """ Args: header_bytes (int): Number of bytes to skip at the beginning of each @@ -36,26 +36,26 @@ class AsStrings(uproot4.interpretation.Interpretation): always four bytes. typename (None or str): If None, construct a plausible C++ typename. Otherwise, take the suggestion as given. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): If + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): If this interpretation is derived from - :py:meth:`~uproot4.interpretation.objects.AsObjects.simplify`, this is a + :py:meth:`~uproot.interpretation.objects.AsObjects.simplify`, this is a reminder of the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model`. - An :py:class:`~uproot4.interpretation.Interpretation` for an array of strings. + An :py:class:`~uproot.interpretation.Interpretation` for an array of strings. This cannot be nested within other - :py:class:`~uproot4.interpretation.Interpretation` objects; it can only represent + :py:class:`~uproot.interpretation.Interpretation` objects; it can only represent a ``TBranch`` that only contains strings (not strings within ``std::vector``, for instance). - Note that the :py:class:`~uproot4.containers.AsString` class is for strings nested + Note that the :py:class:`~uproot.containers.AsString` class is for strings nested within other objects. - (:py:meth:`~uproot4.interpretation.objects.AsObjects.simplify` converts an - :py:class:`~uproot4.interpretation.objects.AsObjects` of - :py:class:`~uproot4.containers.AsString` into a - :py:class:`~uproot4.interpretation.strings.AsStrings`.) + (:py:meth:`~uproot.interpretation.objects.AsObjects.simplify` converts an + :py:class:`~uproot.interpretation.objects.AsObjects` of + :py:class:`~uproot.containers.AsString` into a + :py:class:`~uproot.interpretation.strings.AsStrings`.) """ def __init__( @@ -89,9 +89,9 @@ def length_bytes(self): def original(self): """ If not None, this was the original - :py:attr:`~uproot4.interpretation.objects.AsObjects.model` from an - :py:class:`~uproot4.interpretation.objects.AsObjects` that was simplified - into this :py:class:`~uproot4.interpretation.jagged.AsJagged`. + :py:attr:`~uproot.interpretation.objects.AsObjects.model` from an + :py:class:`~uproot.interpretation.objects.AsObjects` that was simplified + into this :py:class:`~uproot.interpretation.jagged.AsJagged`. """ return self._original @@ -122,11 +122,10 @@ def numpy_dtype(self): return numpy.dtype(numpy.object) def awkward_form(self, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - awkward1.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": { @@ -359,9 +358,9 @@ class StringArray(object): the array. Temporary array filled by - :py:meth:`~uproot4.interpretation.strings.AsStrings.basket_array`, which will be + :py:meth:`~uproot.interpretation.strings.AsStrings.basket_array`, which will be turned into a NumPy, Awkward, or other array, depending on the specified - :py:class:`~uproot4.interpretation.library.Library`. + :py:class:`~uproot.interpretation.library.Library`. """ def __init__(self, offsets, content): @@ -393,7 +392,7 @@ def content(self): def __getitem__(self, where): data = self._content[self._offsets[where] : self._offsets[where + 1]] - return uproot4._util.ensure_str(data) + return uproot._util.ensure_str(data) def __len__(self): return len(self._offsets) - 1 @@ -402,5 +401,5 @@ def __iter__(self): start = self._offsets[0] content = self._content for stop in self._offsets[1:]: - yield uproot4._util.ensure_str(content[start:stop]) + yield uproot._util.ensure_str(content[start:stop]) start = stop diff --git a/uproot/language/__init__.py b/uproot/language/__init__.py new file mode 100644 index 000000000..733215386 --- /dev/null +++ b/uproot/language/__init__.py @@ -0,0 +1,24 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE + +""" +Defines languages for expressions passed to +:py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` (and similar). + +The default is :py:class:`~uproot.language.python.PythonLanguage`. + +All languages must be subclasses of :py:class:`~uproot.language.Language`. +""" + +from __future__ import absolute_import + + +class Language(object): + """ + Abstract class for all languages, which are used to compute the expressions + that are passed to :py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` (and + similar). + + The default is :py:class:`~uproot.language.python.PythonLanguage`. + """ + + pass diff --git a/uproot4/language/python.py b/uproot/language/python.py similarity index 95% rename from uproot4/language/python.py rename to uproot/language/python.py index a0919dc73..46913c1d4 100644 --- a/uproot4/language/python.py +++ b/uproot/language/python.py @@ -1,10 +1,10 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines a :py:class:`~uproot4.language.Language` for expressions passed to -:py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` (and similar). +Defines a :py:class:`~uproot.language.Language` for expressions passed to +:py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` (and similar). -The :py:class:`~uproot4.language.python.PythonLanguage` evaluates Python code. It is +The :py:class:`~uproot.language.python.PythonLanguage` evaluates Python code. It is the default language. """ @@ -14,7 +14,7 @@ import numpy -import uproot4.language +import uproot def _expression_to_node(expression, file_path, object_path): @@ -169,7 +169,7 @@ def _expression_to_function( node.body[0].value, keys, aliases, functions, getter ) except KeyError as err: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( err.args[0], keys=sorted(keys) + list(aliases), file_path=file_path, @@ -238,7 +238,7 @@ def lgamma(values): _lgamma = _vectorized_gamma(True) -class PythonLanguage(uproot4.language.Language): +class PythonLanguage(uproot.language.Language): """ Args: functions (None or dict): Mapping from function name to function, or @@ -247,9 +247,9 @@ class PythonLanguage(uproot4.language.Language): needed for branches whose names are not valid Python symbols. Default is "get". - PythonLanguage is the default :py:class:`~uproot4.language.Language` for + PythonLanguage is the default :py:class:`~uproot.language.Language` for interpreting expressions passed to - :py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` (and similar). This + :py:meth:`~uproot.behavior.TBranch.HasBranches.arrays` (and similar). This interpretation assumes that the expressions have Python syntax and semantics, with math functions loaded into the namespace. @@ -379,7 +379,7 @@ def free_symbols(self, expression, keys, aliases, file_path, object_path): ) ) except KeyError as err: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( err.args[0], file_path=file_path, object_path=object_path ) @@ -395,7 +395,7 @@ def compute_expressions( ): """ Args: - hasbranches (:py:class:`~uproot4.behavior.TBranch.HasBranches`): The + hasbranches (:py:class:`~uproot.behavior.TBranch.HasBranches`): The ``TTree`` or ``TBranch`` that is requesting a computation. arrays (dict of arrays): Inputs to the computation. expression_context (list of (str, dict) tuples): Expression strings diff --git a/uproot4/model.py b/uproot/model.py similarity index 71% rename from uproot4/model.py rename to uproot/model.py index 34381ac6f..153ebca92 100644 --- a/uproot4/model.py +++ b/uproot/model.py @@ -2,17 +2,17 @@ """ Defines utilities for modeling C++ objects as Python objects and the -:py:class:`~uproot4.model.Model` class, which is the superclass of all objects that +:py:class:`~uproot.model.Model` class, which is the superclass of all objects that are read from ROOT files. -The :py:class:`~uproot4.model.VersionedModel` class is the superclass of all models +The :py:class:`~uproot.model.VersionedModel` class is the superclass of all models whose deserialization routines are specialized by ROOT class version. -A :py:class:`~uproot4.model.DispatchByVersion` subclass selects a versioned model +A :py:class:`~uproot.model.DispatchByVersion` subclass selects a versioned model after reading its version bytes. -The :py:exc:`~uproot4.model.UnknownClass` and -:py:exc:`~uproot4.model.UnknownClassVersion` are placeholders for data that could +The :py:exc:`~uproot.model.UnknownClass` and +:py:exc:`~uproot.model.UnknownClassVersion` are placeholders for data that could not be modeled, either because the class has no streamer or no streamer for its version. """ @@ -25,9 +25,7 @@ import numpy -import uproot4.const -import uproot4._util -import uproot4.interpretation.objects +import uproot bootstrap_classnames = [ "TStreamerInfo", @@ -55,47 +53,47 @@ def bootstrap_classes(): Returns the basic classes that are needed to load other classes (streamers, TList, TObjArray, TObjString). """ - import uproot4.streamers - import uproot4.models.TList - import uproot4.models.TObjArray - import uproot4.models.TObjString + import uproot.streamers + import uproot.models.TList + import uproot.models.TObjArray + import uproot.models.TObjString custom_classes = {} for classname in bootstrap_classnames: - custom_classes[classname] = uproot4.classes[classname] + custom_classes[classname] = uproot.classes[classname] return custom_classes def reset_classes(): """ - Removes all classes from ``uproot4.classes`` and ``uproot4.unknown_classes`` - and refills ``uproot4.classes`` with original versions of these classes. + Removes all classes from ``uproot.classes`` and ``uproot.unknown_classes`` + and refills ``uproot.classes`` with original versions of these classes. """ - if uproot4._util.py2: + if uproot._util.py2: reload = __builtins__["reload"] else: from importlib import reload - uproot4.classes = {} - uproot4.unknown_classes = {} - - reload(uproot4.streamers) - reload(uproot4.models.TObject) - reload(uproot4.models.TString) - reload(uproot4.models.TArray) - reload(uproot4.models.TNamed) - reload(uproot4.models.TList) - reload(uproot4.models.THashList) - reload(uproot4.models.TObjArray) - reload(uproot4.models.TObjString) - reload(uproot4.models.TAtt) - reload(uproot4.models.TRef) - reload(uproot4.models.TTree) - reload(uproot4.models.TBranch) - reload(uproot4.models.TLeaf) - reload(uproot4.models.TBasket) - reload(uproot4.models.RNTuple) + uproot.classes = {} + uproot.unknown_classes = {} + + reload(uproot.streamers) + reload(uproot.models.TObject) + reload(uproot.models.TString) + reload(uproot.models.TArray) + reload(uproot.models.TNamed) + reload(uproot.models.TList) + reload(uproot.models.THashList) + reload(uproot.models.TObjArray) + reload(uproot.models.TObjString) + reload(uproot.models.TAtt) + reload(uproot.models.TRef) + reload(uproot.models.TTree) + reload(uproot.models.TBranch) + reload(uproot.models.TLeaf) + reload(uproot.models.TBasket) + reload(uproot.models.RNTuple) _classname_regularize = re.compile(r"\s*(<|>|::)\s*") @@ -104,12 +102,12 @@ def reset_classes(): _classname_decode_version = re.compile(br".*_v([0-9]+)$") _classname_decode_pattern = re.compile(br"_(([0-9a-f][0-9a-f])+)_") -if uproot4._util.py2: +if uproot._util.py2: def _classname_decode_convert(hex_characters): g = hex_characters.group(1) return b"".join( - chr(int(g[i : i + 2], 16)) for i in uproot4._util.range(0, len(g), 2) + chr(int(g[i : i + 2], 16)) for i in uproot._util.range(0, len(g), 2) ) def _classname_encode_convert(bad_characters): @@ -121,7 +119,7 @@ def _classname_encode_convert(bad_characters): def _classname_decode_convert(hex_characters): g = hex_characters.group(1) - return bytes(int(g[i : i + 2], 16) for i in uproot4._util.range(0, len(g), 2)) + return bytes(int(g[i : i + 2], 16) for i in uproot._util.range(0, len(g), 2)) def _classname_encode_convert(bad_characters): g = bad_characters.group(0) @@ -235,28 +233,28 @@ def class_named(classname, version=None, custom_classes=None): If ``version`` is None, no attempt is made to find a specific version. - * If the class is a :py:class:`~uproot4.model.DispatchByVersion`, then this is + * If the class is a :py:class:`~uproot.model.DispatchByVersion`, then this is object returned. * If the class is a versionless model, then this is the object returned. If ``version`` is an integer, an attempt is made to find the specific version. - * If the class is a :py:class:`~uproot4.model.DispatchByVersion`, then it is + * If the class is a :py:class:`~uproot.model.DispatchByVersion`, then it is queried for a versioned model. * If the class is a versionless model, then this is the object returned. If ``custom_classes`` are provided, then these are searched (exclusively) - for the class. If ``custom_classes`` is None, then ``uproot4.classes`` is + for the class. If ``custom_classes`` is None, then ``uproot.classes`` is used. No classes are created if a class is not found (an error is raised). """ if custom_classes is None: - classes = uproot4.classes + classes = uproot.classes where = "the 'custom_classes' dict" else: - where = "uproot4.classes" + where = "uproot.classes" cls = classes.get(classname) if cls is None: @@ -279,7 +277,7 @@ def class_named(classname, version=None, custom_classes=None): def has_class_named(classname, version=None, custom_classes=None): """ - Returns True if :py:func:`~uproot4.model.class_named` would find a class, + Returns True if :py:func:`~uproot.model.class_named` would find a class, False if it would raise an exception. """ cls = maybe_custom_classes(custom_classes).get(classname) @@ -295,10 +293,10 @@ def has_class_named(classname, version=None, custom_classes=None): def maybe_custom_classes(custom_classes): """ Passes through ``custom_classes`` if it is not None; returns - ``uproot4.classes`` otherwise. + ``uproot.classes`` otherwise. """ if custom_classes is None: - return uproot4.classes + return uproot.classes else: return custom_classes @@ -306,23 +304,23 @@ def maybe_custom_classes(custom_classes): class Model(object): """ Abstract class for all objects extracted from ROOT files (except for - :py:class:`~uproot4.reading.ReadOnlyFile`, :py:class:`~uproot4.reading.ReadOnlyDirectory`, - and :py:class:`~uproot4.reading.ReadOnlyKey`). + :py:class:`~uproot.reading.ReadOnlyFile`, :py:class:`~uproot.reading.ReadOnlyDirectory`, + and :py:class:`~uproot.reading.ReadOnlyKey`). - A model is instantiated from a file using the :py:meth:`~uproot4.model.Model.read` - classmethod or synthetically using the :py:meth:`~uproot4.model.Model.empty` + A model is instantiated from a file using the :py:meth:`~uproot.model.Model.read` + classmethod or synthetically using the :py:meth:`~uproot.model.Model.empty` classmethod, not through a normal constructor. Models point back to the file from which they were created, though only a - few classes (named in ``uproot4.reading.must_be_attached``) have an open, - readable file attached; the rest have a :py:class:`~uproot4.reading.DetachedFile` + few classes (named in ``uproot.reading.must_be_attached``) have an open, + readable file attached; the rest have a :py:class:`~uproot.reading.DetachedFile` with information about the file, while not holding the file open. Uproot recognizes *some* of ROOT's thousands of classes, by way of methods - and properties defined in :py:mod:`uproot4.behaviors`. Examples include + and properties defined in :py:mod:`uproot.behaviors`. Examples include - * :py:class:`~uproot4.behaviors.TTree.TTree` - * :py:class:`~uproot4.behaviors.TH1.TH1` + * :py:class:`~uproot.behaviors.TTree.TTree` + * :py:class:`~uproot.behaviors.TH1.TH1` These classes are the most convenient to work with and have specialized documentation. @@ -330,13 +328,13 @@ class Model(object): Classes that don't have any predefined behaviors are still usable through their member data. - * :py:attr:`~uproot4.model.Model.members`: a dict of C++ member names and values + * :py:attr:`~uproot.model.Model.members`: a dict of C++ member names and values directly in this class. - * :py:attr:`~uproot4.model.Model.all_members`: a dict of C++ member names and + * :py:attr:`~uproot.model.Model.all_members`: a dict of C++ member names and values in this class or any superclasses. - * :py:meth:`~uproot4.model.Model.member`: method that takes a C++ member name + * :py:meth:`~uproot.model.Model.member`: method that takes a C++ member name and returns its value (from this or any superclass). - * :py:meth:`~uproot4.model.Model.has_member`: method that takes a C++ member + * :py:meth:`~uproot.model.Model.has_member`: method that takes a C++ member name and returns True if it exists (in this or any superclass), False otherwise. @@ -347,11 +345,11 @@ class Model(object): Pythonic models don't follow the same class inheritance tree as their C++ counterparts: most of them are direct subclasses of - :py:class:`~uproot4.model.Model`, :py:class:`~uproot4.model.DispatchByVersion`, or - :py:class:`~uproot4.model.VersionedModel`. To separate an object's members + :py:class:`~uproot.model.Model`, :py:class:`~uproot.model.DispatchByVersion`, or + :py:class:`~uproot.model.VersionedModel`. To separate an object's members from its superclass members, a model instance is created for each and the superclass parts are included in a list called - :py:attr:`~uproot4.model.Model.bases`. + :py:attr:`~uproot.model.Model.bases`. """ class_streamer = None @@ -365,12 +363,12 @@ def __repr__(self): return "<{0}{1} at 0x{2:012x}>".format(self.classname, version, id(self)) def __enter__(self): - if isinstance(self._file, uproot4.reading.ReadOnlyFile): + if isinstance(self._file, uproot.reading.ReadOnlyFile): self._file.source.__enter__() return self def __exit__(self, exception_type, exception_value, traceback): - if isinstance(self._file, uproot4.reading.ReadOnlyFile): + if isinstance(self._file, uproot.reading.ReadOnlyFile): self._file.source.__exit__(exception_type, exception_value, traceback) @property @@ -378,9 +376,9 @@ def classname(self): """ The C++ (decoded) classname of the modeled class. - See :py:func:`~uproot4.model.classname_decode`, - :py:func:`~uproot4.model.classname_encode`, and - :py:func:`~uproot4.model.classname_version`. + See :py:func:`~uproot.model.classname_decode`, + :py:func:`~uproot.model.classname_encode`, and + :py:func:`~uproot.model.classname_version`. """ return classname_decode(self.encoded_classname)[0] @@ -390,9 +388,9 @@ def encoded_classname(self): The Python (encoded) classname of the modeled class. May or may not include version. - See :py:func:`~uproot4.model.classname_decode`, - :py:func:`~uproot4.model.classname_encode`, and - :py:func:`~uproot4.model.classname_version`. + See :py:func:`~uproot.model.classname_decode`, + :py:func:`~uproot.model.classname_encode`, and + :py:func:`~uproot.model.classname_version`. """ return type(self).__name__ @@ -401,9 +399,9 @@ def class_version(self): """ The version number of the modeled class (int) if any; None otherwise. - See :py:func:`~uproot4.model.classname_decode`, - :py:func:`~uproot4.model.classname_encode`, and - :py:func:`~uproot4.model.classname_version`. + See :py:func:`~uproot.model.classname_decode`, + :py:func:`~uproot.model.classname_encode`, and + :py:func:`~uproot.model.classname_version`. """ return classname_decode(self.encoded_classname)[1] @@ -411,15 +409,15 @@ def class_version(self): def cursor(self): """ A cursor pointing to the start of this instance in the byte stream - (before :py:meth:`~uproot4.model.Model.read_numbytes_version`). + (before :py:meth:`~uproot.model.Model.read_numbytes_version`). """ return self._cursor @property def file(self): """ - A :py:class:`~uproot4.reading.ReadOnlyFile`, which may be open and readable, - or a :py:class:`~uproot4.reading.DetachedFile`, which only contains + A :py:class:`~uproot.reading.ReadOnlyFile`, which may be open and readable, + or a :py:class:`~uproot.reading.DetachedFile`, which only contains information about the original file (not an open file handle). """ return self._file @@ -427,9 +425,9 @@ def file(self): def close(self): """ Closes the file from which this object is derived, if such a file is - still attached (i.e. not :py:class:`~uproot4.reading.DetachedFile`). + still attached (i.e. not :py:class:`~uproot.reading.DetachedFile`). """ - if isinstance(self._file, uproot4.reading.ReadOnlyFile): + if isinstance(self._file, uproot.reading.ReadOnlyFile): self._file.close() @property @@ -437,9 +435,9 @@ def closed(self): """ True if the associated file is known to be closed; False if it is known to be open. If the associated file is detached - (:py:class:`~uproot4.reading.DetachedFile`), then the value is None. + (:py:class:`~uproot.reading.DetachedFile`), then the value is None. """ - if isinstance(self._file, uproot4.reading.ReadOnlyFile): + if isinstance(self._file, uproot.reading.ReadOnlyFile): return self._file.closed else: return None @@ -459,7 +457,7 @@ def concrete(self): in C++, which is ``self`` if this is the concrete class or another object if this is actually a holder of superclass members for that other object (i.e. if this object is in the other's - :py:attr:`~uproot4.model.Model.bases`). + :py:attr:`~uproot.model.Model.bases`). """ return self._concrete @@ -468,7 +466,7 @@ def members(self): """ A dict of C++ member data directly associated with this class (i.e. not its superclasses). For all members, see - :py:attr:`~uproot4.model.Model.all_members`. + :py:attr:`~uproot.model.Model.all_members`. """ return self._members @@ -476,7 +474,7 @@ def members(self): def all_members(self): """ A dict of C++ member data for this class and its superclasses. For only - direct members, see :py:attr:`~uproot4.model.Model.members`. + direct members, see :py:attr:`~uproot.model.Model.members`. """ out = {} for base in self._bases: @@ -486,7 +484,7 @@ def all_members(self): def has_member(self, name, all=True): """ - Returns True if calling :py:meth:`~uproot4.model.Model.member` with the same + Returns True if calling :py:meth:`~uproot.model.Model.member` with the same arguments would return a value; False if the member is missing. """ if name in self._members: @@ -502,7 +500,7 @@ def member(self, name, all=True, none_if_missing=False): Args: name (str): The name of the member datum to retrieve. all (bool): If True, recursively search all superclasses in - :py:attr:`~uproot4.model.Model.bases`. Otherwise, search the + :py:attr:`~uproot.model.Model.bases`. Otherwise, search the direct class only. none_if_missing (bool): If a member datum doesn't exist in the search path, ``none_if_missing=True`` has this function return @@ -522,7 +520,7 @@ def member(self, name, all=True, none_if_missing=False): if none_if_missing: return None else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( name, because="""{0}.{1} has only the following members: @@ -538,7 +536,7 @@ def member(self, name, all=True, none_if_missing=False): @property def bases(self): """ - List of :py:class:`~uproot4.model.Model` objects representing superclass data + List of :py:class:`~uproot.model.Model` objects representing superclass data for this object in the order given in C++ (opposite method resolution order). @@ -557,13 +555,13 @@ def bases(self): def base(self, *cls): """ - Extracts instances from :py:attr:`~uproot4.model.Model.bases` by Python class + Extracts instances from :py:attr:`~uproot.model.Model.bases` by Python class type. The ``cls`` arguments may be Python classes or C++ classname strings to match. """ - cpp_names = [classname_regularize(x) for x in cls if uproot4._util.isstr(x)] - py_types = tuple(x for x in cls if not uproot4._util.isstr(x)) + cpp_names = [classname_regularize(x) for x in cls if uproot._util.isstr(x)] + py_types = tuple(x for x in cls if not uproot._util.isstr(x)) out = [] for x in getattr(self, "_bases", []): @@ -581,8 +579,8 @@ def is_instance(self, *cls): The ``cls`` arguments may be Python classes or C++ classname strings to match. """ - cpp_names = [classname_regularize(x) for x in cls if uproot4._util.isstr(x)] - py_types = tuple(x for x in cls if not uproot4._util.isstr(x)) + cpp_names = [classname_regularize(x) for x in cls if uproot._util.isstr(x)] + py_types = tuple(x for x in cls if not uproot._util.isstr(x)) if isinstance(self, py_types) or any(self.classname == n for n in cpp_names): return True @@ -598,7 +596,7 @@ def num_bytes(self): This value may be None (unknown before reading) or an integer. If the value is an integer and the object exists (no exceptions in - :py:meth:`~uproot4.model.Model.read`), then the expected number of bytes + :py:meth:`~uproot.model.Model.read`), then the expected number of bytes agreed with the actual number of bytes, and this numer is reliable. If this object is re-serialized, it won't necessarily occupy the same @@ -611,9 +609,9 @@ def instance_version(self): """ Version of this instance as read from the byte stream. - If this model is versioned (:py:class:`~uproot4.model.VersionedModel`), the + If this model is versioned (:py:class:`~uproot.model.VersionedModel`), the ``instance_version`` ought to be equal to the - :py:func:`~uproot4.model.class_version`. + :py:func:`~uproot.model.class_version`. If this model is versionless, the ``instance_version`` contains new information about the actual version deserialized. @@ -632,23 +630,23 @@ def is_memberwise(self): def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): """ Args: - cls (subclass of :py:class:`~uproot4.model.Model`): This class. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + cls (subclass of :py:class:`~uproot.model.Model`): This class. + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. index_format (str): Format to use for indexes of the - ``awkward1.forms.Form``; may be ``"i32"``, ``"u32"``, or + ``awkward.forms.Form``; may be ``"i32"``, ``"u32"``, or ``"i64"``. header (bool): If True, include headers in the Form's ``"uproot"`` parameters. tobject_header (bool): If True, include headers for ``TObject`` classes in the Form's ``"uproot"`` parameters. - The ``awkward1.forms.Form`` to use to put objects of type type in an + The ``awkward.forms.Form`` to use to put objects of type type in an Awkward Array. """ - raise uproot4.interpretation.objects.CannotBeAwkward( + raise uproot.interpretation.objects.CannotBeAwkward( classname_decode(cls.__name__)[0] ) @@ -658,20 +656,20 @@ def strided_interpretation( ): """ Args: - cls (subclass of :py:class:`~uproot4.model.Model`): This class. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + cls (subclass of :py:class:`~uproot.model.Model`): This class. + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. header (bool): If True, assume the outermost object has a header. tobject_header (bool): If True, assume that ``TObjects`` have headers. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): The + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): The original, non-strided model or container. Returns a list of (str, ``numpy.dtype``) pairs to build a - :py:class:`~uproot4.interpretation.objects.AsStridedObjects` interpretation. + :py:class:`~uproot.interpretation.objects.AsStridedObjects` interpretation. """ - raise uproot4.interpretation.objects.CannotBeStrided( + raise uproot.interpretation.objects.CannotBeStrided( classname_decode(cls.__name__)[0] ) @@ -716,20 +714,20 @@ def empty(cls): def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): """ Args: - cls (subclass of :py:class:`~uproot4.model.Model`): Class to instantiate. - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + cls (subclass of :py:class:`~uproot.model.Model`): Class to instantiate. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. - selffile (:py:class:`~uproot4.reading.CommonFileMethods`): A possibly - :py:class:`~uproot4.reading.DetachedFile` associated with this object. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. + selffile (:py:class:`~uproot.reading.CommonFileMethods`): A possibly + :py:class:`~uproot.reading.DetachedFile` associated with this object. parent (None or calling object): The previous ``read`` in the recursive descent. - concrete (None or :py:class:`~uproot4.model.Model` instance): If None, + concrete (None or :py:class:`~uproot.model.Model` instance): If None, this model corresponds to the concrete (instantiated) class in C++. Otherwise, this model represents a superclass part of the object, and ``concrete`` points to the concrete instance. @@ -806,9 +804,9 @@ def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): def read_numbytes_version(self, chunk, cursor, context): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. @@ -819,28 +817,28 @@ def read_numbytes_version(self, chunk, cursor, context): Some types don't have a 6-byte header or handle it differently; in those cases, this method should be overridden. """ - import uproot4.deserialization + import uproot.deserialization ( self._num_bytes, self._instance_version, self._is_memberwise, - ) = uproot4.deserialization.numbytes_version(chunk, cursor, context) + ) = uproot.deserialization.numbytes_version(chunk, cursor, context) def read_members(self, chunk, cursor, context, file): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. Reads the member data for this class. The abstract class - :py:class:`~uproot4.model.Model` has an empty ``read_members`` method; this + :py:class:`~uproot.model.Model` has an empty ``read_members`` method; this *must* be overridden by subclasses. """ pass @@ -848,25 +846,25 @@ def read_members(self, chunk, cursor, context, file): def check_numbytes(self, chunk, cursor, context): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. Reads nothing; checks the expected number of bytes against the actual movement of the ``cursor`` at the end of the object, possibly raising - a :py:exc:`~uproot4.deserialization.DeserializationError` exception. + a :py:exc:`~uproot.deserialization.DeserializationError` exception. - If :py:attr:`~uproot4.model.Model.num_bytes` is None, this method does + If :py:attr:`~uproot.model.Model.num_bytes` is None, this method does nothing. It is *possible* that a subclass would override this method, but not likely. """ - import uproot4.deserialization + import uproot.deserialization - uproot4.deserialization.numbytes_check( + uproot.deserialization.numbytes_check( chunk, self._cursor, cursor, @@ -879,59 +877,59 @@ def check_numbytes(self, chunk, cursor, context): def postprocess(self, chunk, cursor, context, file): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. Called for any additional processing after the object has been fully read. The return value from this method is the object that actually represents the ROOT data, which might be a different instance or even a different - type from this class. The default in :py:class:`~uproot4.model.Model` is to + type from this class. The default in :py:class:`~uproot.model.Model` is to return ``self``. Note that for versioned models, - :py:meth:`~uproot4.model.VersionedModel.postprocess` is called first, then - :py:meth:`~uproot4.model.DispatchByVersion.postprocess` is called on its - output, allowing a :py:class:`~uproot4.model.DispatchByVersion` to refine all + :py:meth:`~uproot.model.VersionedModel.postprocess` is called first, then + :py:meth:`~uproot.model.DispatchByVersion.postprocess` is called on its + output, allowing a :py:class:`~uproot.model.DispatchByVersion` to refine all data of its type, regardless of version. """ return self def hook_before_read(self, **kwargs): """ - Called in :py:meth:`~uproot4.model.Model.read`, before any data have been + Called in :py:meth:`~uproot.model.Model.read`, before any data have been read. """ pass def hook_before_read_members(self, **kwargs): """ - Called in :py:meth:`~uproot4.model.Model.read`, after - :py:meth:`~uproot4.model.Model.read_numbytes_version` and before - :py:meth:`~uproot4.model.Model.read_members`. + Called in :py:meth:`~uproot.model.Model.read`, after + :py:meth:`~uproot.model.Model.read_numbytes_version` and before + :py:meth:`~uproot.model.Model.read_members`. """ pass def hook_after_read_members(self, **kwargs): """ - Called in :py:meth:`~uproot4.model.Model.read`, after - :py:meth:`~uproot4.model.Model.read_members` and before - :py:meth:`~uproot4.model.Model.check_numbytes`. + Called in :py:meth:`~uproot.model.Model.read`, after + :py:meth:`~uproot.model.Model.read_members` and before + :py:meth:`~uproot.model.Model.check_numbytes`. """ pass def hook_before_postprocess(self, **kwargs): """ - Called in :py:meth:`~uproot4.model.Model.read`, after - :py:meth:`~uproot4.model.Model.check_numbytes` and before - :py:meth:`~uproot4.model.Model.postprocess`. + Called in :py:meth:`~uproot.model.Model.read`, after + :py:meth:`~uproot.model.Model.check_numbytes` and before + :py:meth:`~uproot.model.Model.postprocess`. """ pass @@ -940,16 +938,16 @@ class VersionedModel(Model): """ A Python class that models a specific version of a ROOT C++ class. - Classes that inherit directly from :py:class:`~uproot4.model.Model` are versionless, - classes that inherit from :py:class:`~uproot4.model.VersionedModel` depend on + Classes that inherit directly from :py:class:`~uproot.model.Model` are versionless, + classes that inherit from :py:class:`~uproot.model.VersionedModel` depend on version. - Note that automatically generated :py:class:`~uproot4.model.VersionedModel` classes - are placed in the ``uproot4.dynamic`` namespace. This namespace can generate - :py:class:`~uproot4.model.DynamicModel` classes on demand in Python 3.7 and above, - which automatically generated :py:class:`~uproot4.model.VersionedModel` classes + Note that automatically generated :py:class:`~uproot.model.VersionedModel` classes + are placed in the ``uproot.dynamic`` namespace. This namespace can generate + :py:class:`~uproot.model.DynamicModel` classes on demand in Python 3.7 and above, + which automatically generated :py:class:`~uproot.model.VersionedModel` classes rely upon to be pickleable. Therefore, ROOT object types without predefined - :py:class:`~uproot4.model.Model` classes cannot be pickled in Python versions + :py:class:`~uproot.model.Model` classes cannot be pickled in Python versions before 3.7. """ @@ -974,20 +972,20 @@ def __setstate__(self, state): class DispatchByVersion(object): """ A Python class that models all versions of a ROOT C++ class by maintaining - a dict of :py:class:`~uproot4.model.VersionedModel` classes. + a dict of :py:class:`~uproot.model.VersionedModel` classes. - The :py:meth:`~uproot4.model.DispatchByVersion.read` classmethod reads the + The :py:meth:`~uproot.model.DispatchByVersion.read` classmethod reads the instance version number from the byte stream, backs up the - :py:class:`~uproot4.source.cursor.Cursor` to the starting position, and invokes - the appropriate :py:class:`~uproot4.model.VersionedModel`'s ``read`` classmethod. + :py:class:`~uproot.source.cursor.Cursor` to the starting position, and invokes + the appropriate :py:class:`~uproot.model.VersionedModel`'s ``read`` classmethod. - If a :py:class:`~uproot4.model.VersionedModel` does not exist for the specified + If a :py:class:`~uproot.model.VersionedModel` does not exist for the specified version, the ``file``'s ``TStreamerInfo`` is queried to attempt to create - one, and failing that, an :py:exc:`~uproot4.model.UnknownClassVersion` is + one, and failing that, an :py:exc:`~uproot.model.UnknownClassVersion` is created instead. - Note that :py:class:`~uproot4.model.DispatchByVersion` is not a subclass of - :py:class:`~uproot4.model.Model`. Instances of this class are not usable as + Note that :py:class:`~uproot.model.DispatchByVersion` is not a subclass of + :py:class:`~uproot.model.Model`. Instances of this class are not usable as stand-ins for ROOT data. """ @@ -995,20 +993,20 @@ class DispatchByVersion(object): def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): """ Args: - cls (subclass of :py:class:`~uproot4.model.DispatchByVersion`): This class. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + cls (subclass of :py:class:`~uproot.model.DispatchByVersion`): This class. + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. index_format (str): Format to use for indexes of the - ``awkward1.forms.Form``; may be ``"i32"``, ``"u32"``, or + ``awkward.forms.Form``; may be ``"i32"``, ``"u32"``, or ``"i64"``. header (bool): If True, include headers in the Form's ``"uproot"`` parameters. tobject_header (bool): If True, include headers for ``TObject`` classes in the Form's ``"uproot"`` parameters. - The ``awkward1.forms.Form`` to use to put objects of type type in an + The ``awkward.forms.Form`` to use to put objects of type type in an Awkward Array. """ versioned_cls = file.class_named(classname_decode(cls.__name__)[0], "max") @@ -1020,18 +1018,18 @@ def strided_interpretation( ): """ Args: - cls (subclass of :py:class:`~uproot4.model.DispatchByVersion`): This class. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + cls (subclass of :py:class:`~uproot.model.DispatchByVersion`): This class. + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. header (bool): If True, assume the outermost object has a header. tobject_header (bool): If True, assume that ``TObjects`` have headers. - original (None, :py:class:`~uproot4.model.Model`, or :py:class:`~uproot4.containers.Container`): The + original (None, :py:class:`~uproot.model.Model`, or :py:class:`~uproot.containers.Container`): The original, non-strided model or container. Returns a list of (str, ``numpy.dtype``) pairs to build a - :py:class:`~uproot4.interpretation.objects.AsStridedObjects` interpretation. + :py:class:`~uproot.interpretation.objects.AsStridedObjects` interpretation. """ versioned_cls = file.class_named(classname_decode(cls.__name__)[0], "max") return versioned_cls.strided_interpretation( @@ -1062,11 +1060,11 @@ def new_class(cls, file, version): Uses ``file`` to create a new class for a specified ``version``. As a side-effect, this new class is added to ``cls.known_versions`` - (for :py:func:`~uproot4.model.class_of_version` and - :py:func:`~uproot4.model.has_version`). + (for :py:func:`~uproot.model.class_of_version` and + :py:func:`~uproot.model.has_version`). If the ``file`` lacks a ``TStreamerInfo`` for the class, this function - returns a :py:exc:`~uproot4.model.UnknownClassVersion` (adding it to + returns a :py:exc:`~uproot.model.UnknownClassVersion` (adding it to ``uproo4.unknown_classes`` if it's not already there). """ classname, _ = classname_decode(cls.__name__) @@ -1083,52 +1081,52 @@ def new_class(cls, file, version): return versioned_cls else: - unknown_cls = uproot4.unknown_classes.get(classname) + unknown_cls = uproot.unknown_classes.get(classname) if unknown_cls is None: - unknown_cls = uproot4._util.new_class( + unknown_cls = uproot._util.new_class( classname_encode(classname, version, unknown=True), (UnknownClassVersion,), {}, ) - uproot4.unknown_classes[classname] = unknown_cls + uproot.unknown_classes[classname] = unknown_cls return unknown_cls @classmethod def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): """ Args: - cls (subclass of :py:class:`~uproot4.model.DispatchByVersion`): This class. - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + cls (subclass of :py:class:`~uproot.model.DispatchByVersion`): This class. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. - selffile (:py:class:`~uproot4.reading.CommonFileMethods`): A possibly - :py:class:`~uproot4.reading.DetachedFile` associated with this object. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. + selffile (:py:class:`~uproot.reading.CommonFileMethods`): A possibly + :py:class:`~uproot.reading.DetachedFile` associated with this object. parent (None or calling object): The previous ``read`` in the recursive descent. - concrete (None or :py:class:`~uproot4.model.Model` instance): If None, + concrete (None or :py:class:`~uproot.model.Model` instance): If None, this model corresponds to the concrete (instantiated) class in C++. Otherwise, this model represents a superclass part of the object, and ``concrete`` points to the concrete instance. Reads the instance version number from the byte stream, backs up the - :py:class:`~uproot4.source.cursor.Cursor` to the starting position, and - invokes the appropriate :py:class:`~uproot4.model.VersionedModel`'s ``read`` + :py:class:`~uproot.source.cursor.Cursor` to the starting position, and + invokes the appropriate :py:class:`~uproot.model.VersionedModel`'s ``read`` classmethod. - If a :py:class:`~uproot4.model.VersionedModel` does not exist for the + If a :py:class:`~uproot.model.VersionedModel` does not exist for the specified version, the ``file``'s ``TStreamerInfo`` is queried to attempt to create one, and failing that, an - :py:class:`~uproot4.model.UnknownClassVersion` is created instead. + :py:class:`~uproot.model.UnknownClassVersion` is created instead. """ - import uproot4.deserialization + import uproot.deserialization start_cursor = cursor.copy() - (num_bytes, version, is_memberwise,) = uproot4.deserialization.numbytes_version( + (num_bytes, version, is_memberwise,) = uproot.deserialization.numbytes_version( chunk, cursor, context, move=False ) @@ -1167,28 +1165,28 @@ def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): def postprocess(cls, self, chunk, cursor, context, file): """ Args: - cls (subclass of :py:class:`~uproot4.model.DispatchByVersion`): This class. - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in + cls (subclass of :py:class:`~uproot.model.DispatchByVersion`): This class. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in that ``chunk``. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): An open file object, - capable of generating new :py:class:`~uproot4.model.Model` classes - from its :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + file (:py:class:`~uproot.reading.ReadOnlyFile`): An open file object, + capable of generating new :py:class:`~uproot.model.Model` classes + from its :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. Called for any additional processing after the object has been fully read. The return value from this method is the object that actually represents the ROOT data, which might be a different instance or even a different - type from this class. The default in :py:class:`~uproot4.model.Model` is to + type from this class. The default in :py:class:`~uproot.model.Model` is to return ``self``. Note that for versioned models, - :py:meth:`~uproot4.model.VersionedModel.postprocess` is called first, then - :py:meth:`~uproot4.model.DispatchByVersion.postprocess` is called on its - output, allowing a :py:class:`~uproot4.model.DispatchByVersion` to refine all + :py:meth:`~uproot.model.VersionedModel.postprocess` is called first, then + :py:meth:`~uproot.model.DispatchByVersion.postprocess` is called on its + output, allowing a :py:class:`~uproot.model.DispatchByVersion` to refine all data of its type, regardless of version. """ return self @@ -1197,8 +1195,8 @@ def postprocess(cls, self, chunk, cursor, context, file): class UnknownClass(Model): """ Placeholder for a C++ class instance that has no - :py:class:`~uproot4.model.DispatchByVersion` and no ``TStreamerInfo`` in the - current :py:class:`~uproot4.reading.ReadOnlyFile` to produce one. + :py:class:`~uproot.model.DispatchByVersion` and no ``TStreamerInfo`` in the + current :py:class:`~uproot.reading.ReadOnlyFile` to produce one. """ @property @@ -1206,10 +1204,10 @@ def chunk(self): """ The ``chunk`` of data associated with the unknown class, referred to by a weak reference (to avoid memory leaks in - :py:exc:`~uproot4.model.UnknownClass` objects). If the original ``chunk`` + :py:exc:`~uproot.model.UnknownClass` objects). If the original ``chunk`` has been garbage-collected, this raises ``RuntimeError``. - Primarily useful in the :py:meth:`~uproot4.model.UnknownClass.debug` method. + Primarily useful in the :py:meth:`~uproot.model.UnknownClass.debug` method. """ chunk = self._chunk() if chunk is None: @@ -1224,7 +1222,7 @@ def context(self): """ The auxiliary data used in deserialization. - Primarily useful in the :py:meth:`~uproot4.model.UnknownClass.debug` method. + Primarily useful in the :py:meth:`~uproot.model.UnknownClass.debug` method. """ return self._context @@ -1237,15 +1235,15 @@ def debug( """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted instantiation. The default, ``0``, starts where the number of bytes and version number would be (just before - :py:meth:`~uproot4.model.Model.read_numbytes_version`). + :py:meth:`~uproot.model.Model.read_numbytes_version`). limit_bytes (None or int): Number of bytes to limit the output to. A line of debugging output (without any ``offset``) is 20 bytes, so multiples of 20 show full lines. If None, everything is - shown to the end of the :py:class:`~uproot4.source.chunk.Chunk`, + shown to the end of the :py:class:`~uproot.source.chunk.Chunk`, which might be large. dtype (None, ``numpy.dtype``, or its constructor argument): If None, present only the bytes as decimal values (0-255). Otherwise, @@ -1294,16 +1292,16 @@ def debug_array(self, skip_bytes=0, dtype=numpy.dtype("u1")): """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted instantiation. The default, ``0``, starts where the number of bytes and version number would be (just before - :py:meth:`~uproot4.model.Model.read_numbytes_version`). + :py:meth:`~uproot.model.Model.read_numbytes_version`). dtype (``numpy.dtype`` or its constructor argument): Data type in which to interpret the data. (The size of the array returned is truncated to this ``dtype.itemsize``.) - Like :py:meth:`~uproot4.model.UnknownClass.debug`, but returns a NumPy array + Like :py:meth:`~uproot.model.UnknownClass.debug`, but returns a NumPy array for further inspection. """ dtype = numpy.dtype(dtype) @@ -1332,7 +1330,7 @@ def read_members(self, chunk, cursor, context, file): class UnknownClassVersion(VersionedModel): """ Placeholder for a C++ class instance that has no ``TStreamerInfo`` in the - current :py:class:`~uproot4.reading.ReadOnlyFile` to produce one. + current :py:class:`~uproot.reading.ReadOnlyFile` to produce one. """ @property @@ -1340,10 +1338,10 @@ def chunk(self): """ The ``chunk`` of data associated with the class of unknown version, referred to by a weak reference (to avoid memory leaks in - :py:class:`~uproot4.model.UnknownClassVersion` objects). If the original + :py:class:`~uproot.model.UnknownClassVersion` objects). If the original ``chunk`` has been garbage-collected, this raises ``RuntimeError``. - Primarily useful in the :py:meth:`~uproot4.model.UnknownClassVersion.debug` + Primarily useful in the :py:meth:`~uproot.model.UnknownClassVersion.debug` method. """ chunk = self._chunk() @@ -1360,7 +1358,7 @@ def context(self): """ The auxiliary data used in deserialization. - Primarily useful in the :py:meth:`~uproot4.model.UnknownClass.debug` method. + Primarily useful in the :py:meth:`~uproot.model.UnknownClass.debug` method. """ return self._context @@ -1370,15 +1368,15 @@ def debug( """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted instantiation. The default, ``0``, starts where the number of bytes and version number would be (just before - :py:meth:`~uproot4.model.Model.read_numbytes_version`). + :py:meth:`~uproot.model.Model.read_numbytes_version`). limit_bytes (None or int): Number of bytes to limit the output to. A line of debugging output (without any ``offset``) is 20 bytes, so multiples of 20 show full lines. If None, everything is - shown to the end of the :py:class:`~uproot4.source.chunk.Chunk`, + shown to the end of the :py:class:`~uproot.source.chunk.Chunk`, which might be large. dtype (None, ``numpy.dtype``, or its constructor argument): If None, present only the bytes as decimal values (0-255). Otherwise, @@ -1427,16 +1425,16 @@ def debug_array(self, skip_bytes=0, dtype=numpy.dtype("u1")): """ Args: skip_bytes (int): Number of bytes to skip before presenting the - remainder of the :py:class:`~uproot4.source.chunk.Chunk`. May be + remainder of the :py:class:`~uproot.source.chunk.Chunk`. May be negative, to examine the byte stream leading up to the attempted instantiation. The default, ``0``, starts where the number of bytes and version number would be (just before - :py:meth:`~uproot4.model.Model.read_numbytes_version`). + :py:meth:`~uproot.model.Model.read_numbytes_version`). dtype (``numpy.dtype`` or its constructor argument): Data type in which to interpret the data. (The size of the array returned is truncated to this ``dtype.itemsize``.) - Like :py:meth:`~uproot4.model.UnknownClassVersion.debug`, but returns a + Like :py:meth:`~uproot.model.UnknownClassVersion.debug`, but returns a NumPy array for further inspection. """ dtype = numpy.dtype(dtype) @@ -1469,11 +1467,11 @@ def __repr__(self): class DynamicModel(VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` subclass generated by any attempt to - extract it from the ``uproot4.dynamic`` namespace in Python 3.7 and later. + A :py:class:`~uproot.model.VersionedModel` subclass generated by any attempt to + extract it from the ``uproot.dynamic`` namespace in Python 3.7 and later. This dynamically generated model allows ROOT object types without predefined - :py:class:`~uproot4.model.Model` classes to be pickled in Python 3.7 and later. + :py:class:`~uproot.model.Model` classes to be pickled in Python 3.7 and later. """ def __setstate__(self, state): diff --git a/uproot4/models/RNTuple.py b/uproot/models/RNTuple.py similarity index 83% rename from uproot4/models/RNTuple.py rename to uproot/models/RNTuple.py index beaf199f5..f6b78cc8e 100644 --- a/uproot4/models/RNTuple.py +++ b/uproot/models/RNTuple.py @@ -8,16 +8,15 @@ import struct -import uproot4.model -import uproot4.deserialization +import uproot _rntuple_format1 = struct.Struct(">IIQIIQIIQ") -class Model_ROOT_3a3a_Experimental_3a3a_RNTuple(uproot4.model.Model): +class Model_ROOT_3a3a_Experimental_3a3a_RNTuple(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``ROOT::Experimental::RNTuple``. + A versionless :py:class:`~uproot.model.Model` for ``ROOT::Experimental::RNTuple``. """ def read_members(self, chunk, cursor, context, file): @@ -43,6 +42,6 @@ def read_members(self, chunk, cursor, context, file): ) = cursor.fields(chunk, _rntuple_format1, context) -uproot4.classes[ +uproot.classes[ "ROOT::Experimental::RNTuple" ] = Model_ROOT_3a3a_Experimental_3a3a_RNTuple diff --git a/uproot4/models/TArray.py b/uproot/models/TArray.py similarity index 75% rename from uproot4/models/TArray.py rename to uproot/models/TArray.py index 471db2052..3b29f42c5 100644 --- a/uproot4/models/TArray.py +++ b/uproot/models/TArray.py @@ -15,16 +15,15 @@ import numpy -import uproot4.model -import uproot4._util +import uproot _tarray_format1 = struct.Struct(">i") -class Model_TArray(uproot4.model.Model, Sequence): +class Model_TArray(uproot.model.Model, Sequence): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArray`` and its subclasses. + A versionless :py:class:`~uproot.model.Model` for ``TArray`` and its subclasses. These also satisfy Python's abstract ``Sequence`` protocol. """ @@ -82,11 +81,10 @@ def tojson(self): @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - uproot4._util.awkward_form( + uproot._util.awkward_form( cls.dtype, file, index_format, header, tobject_header ), parameters={"uproot": {"as": "TArray"}}, @@ -95,7 +93,7 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class Model_TArrayC(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayC`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayC`` (``dtype(">i1")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -106,7 +104,7 @@ class Model_TArrayC(Model_TArray): class Model_TArrayS(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayS`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayS`` (``dtype(">i2")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -117,7 +115,7 @@ class Model_TArrayS(Model_TArray): class Model_TArrayI(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayI`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayI`` (``dtype(">i4")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -128,7 +126,7 @@ class Model_TArrayI(Model_TArray): class Model_TArrayL(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayL`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayL`` (``dtype(">i8")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -139,7 +137,7 @@ class Model_TArrayL(Model_TArray): class Model_TArrayL64(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayL64`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayL64`` (``dtype(">i8")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -150,7 +148,7 @@ class Model_TArrayL64(Model_TArray): class Model_TArrayF(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayF`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayF`` (``dtype(">f4")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -161,7 +159,7 @@ class Model_TArrayF(Model_TArray): class Model_TArrayD(Model_TArray): """ - A versionless :py:class:`~uproot4.model.Model` for ``TArrayD`` + A versionless :py:class:`~uproot.model.Model` for ``TArrayD`` (``dtype(">f8")``). It also satisfies Python's abstract ``Sequence`` protocol. @@ -170,11 +168,11 @@ class Model_TArrayD(Model_TArray): dtype = numpy.dtype(">f8") -uproot4.classes["TArray"] = Model_TArray -uproot4.classes["TArrayC"] = Model_TArrayC -uproot4.classes["TArrayS"] = Model_TArrayS -uproot4.classes["TArrayI"] = Model_TArrayI -uproot4.classes["TArrayL"] = Model_TArrayL -uproot4.classes["TArrayL64"] = Model_TArrayL64 -uproot4.classes["TArrayF"] = Model_TArrayF -uproot4.classes["TArrayD"] = Model_TArrayD +uproot.classes["TArray"] = Model_TArray +uproot.classes["TArrayC"] = Model_TArrayC +uproot.classes["TArrayS"] = Model_TArrayS +uproot.classes["TArrayI"] = Model_TArrayI +uproot.classes["TArrayL"] = Model_TArrayL +uproot.classes["TArrayL64"] = Model_TArrayL64 +uproot.classes["TArrayF"] = Model_TArrayF +uproot.classes["TArrayD"] = Model_TArrayD diff --git a/uproot4/models/TAtt.py b/uproot/models/TAtt.py similarity index 71% rename from uproot4/models/TAtt.py rename to uproot/models/TAtt.py index 9efb026cf..4adf8d1da 100644 --- a/uproot4/models/TAtt.py +++ b/uproot/models/TAtt.py @@ -10,16 +10,15 @@ import numpy -import uproot4.model -import uproot4._util +import uproot _tattline1_format1 = struct.Struct(">hhh") -class Model_TAttLine_v1(uproot4.model.VersionedModel): +class Model_TAttLine_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TAttLine`` version 1. + A :py:class:`~uproot.model.VersionedModel` for ``TAttLine`` version 1. """ def read_members(self, chunk, cursor, context, file): @@ -47,34 +46,31 @@ def strided_interpretation( members.append(("fLineColor", numpy.dtype(">i2"))) members.append(("fLineStyle", numpy.dtype(">i2"))) members.append(("fLineWidth", numpy.dtype(">i2"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fLineColor"] = uproot4._util.awkward_form( + contents["fLineColor"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fLineStyle"] = uproot4._util.awkward_form( + contents["fLineStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fLineWidth"] = uproot4._util.awkward_form( + contents["fLineWidth"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( - contents, parameters={"__record__": "TAttLine"} - ) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttLine"}) base_names_versions = [] member_names = ["fLineColor", "fLineStyle", "fLineWidth"] @@ -82,9 +78,9 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class_code = None -class Model_TAttLine_v2(uproot4.model.VersionedModel): +class Model_TAttLine_v2(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TAttLine`` version 2. + A :py:class:`~uproot.model.VersionedModel` for ``TAttLine`` version 2. """ def read_members(self, chunk, cursor, context, file): @@ -112,34 +108,31 @@ def strided_interpretation( members.append(("fLineColor", numpy.dtype(">i2"))) members.append(("fLineStyle", numpy.dtype(">i2"))) members.append(("fLineWidth", numpy.dtype(">i2"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fLineColor"] = uproot4._util.awkward_form( + contents["fLineColor"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fLineStyle"] = uproot4._util.awkward_form( + contents["fLineStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fLineWidth"] = uproot4._util.awkward_form( + contents["fLineWidth"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( - contents, parameters={"__record__": "TAttLine"} - ) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttLine"}) base_names_versions = [] member_names = ["fLineColor", "fLineStyle", "fLineWidth"] @@ -147,9 +140,9 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class_code = None -class Model_TAttLine(uproot4.model.DispatchByVersion): +class Model_TAttLine(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TAttLine``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TAttLine``. """ known_versions = {1: Model_TAttLine_v1, 2: Model_TAttLine_v2} @@ -159,9 +152,9 @@ class Model_TAttLine(uproot4.model.DispatchByVersion): _tattfill2_format1 = struct.Struct(">hh") -class Model_TAttFill_v1(uproot4.model.VersionedModel): +class Model_TAttFill_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TAttFill`` version 1. + A :py:class:`~uproot.model.VersionedModel` for ``TAttFill`` version 1. """ def read_members(self, chunk, cursor, context, file): @@ -186,31 +179,28 @@ def strided_interpretation( members.append(("@instance_version", numpy.dtype(">u2"))) members.append(("fFillColor", numpy.dtype(">i2"))) members.append(("fFillStyle", numpy.dtype(">i2"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fFillColor"] = uproot4._util.awkward_form( + contents["fFillColor"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fFillStyle"] = uproot4._util.awkward_form( + contents["fFillStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( - contents, parameters={"__record__": "TAttFill"} - ) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttFill"}) base_names_versions = [] member_names = ["fFillColor", "fFillStyle"] @@ -218,9 +208,9 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class_code = None -class Model_TAttFill_v2(uproot4.model.VersionedModel): +class Model_TAttFill_v2(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TAttFill`` version 2. + A :py:class:`~uproot.model.VersionedModel` for ``TAttFill`` version 2. """ def read_members(self, chunk, cursor, context, file): @@ -245,31 +235,28 @@ def strided_interpretation( members.append(("@instance_version", numpy.dtype(">u2"))) members.append(("fFillColor", numpy.dtype(">i2"))) members.append(("fFillStyle", numpy.dtype(">i2"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fFillColor"] = uproot4._util.awkward_form( + contents["fFillColor"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fFillStyle"] = uproot4._util.awkward_form( + contents["fFillStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( - contents, parameters={"__record__": "TAttFill"} - ) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TAttFill"}) base_names_versions = [] member_names = ["fFillColor", "fFillStyle"] @@ -277,9 +264,9 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class_code = None -class Model_TAttFill(uproot4.model.DispatchByVersion): +class Model_TAttFill(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TAttFill``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TAttFill``. """ known_versions = {1: Model_TAttFill_v1, 2: Model_TAttFill_v2} @@ -288,9 +275,9 @@ class Model_TAttFill(uproot4.model.DispatchByVersion): _tattmarker2_format1 = struct.Struct(">hhf") -class Model_TAttMarker_v2(uproot4.model.VersionedModel): +class Model_TAttMarker_v2(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TAttMarker`` version 2. + A :py:class:`~uproot.model.VersionedModel` for ``TAttMarker`` version 2. """ def read_members(self, chunk, cursor, context, file): @@ -318,32 +305,31 @@ def strided_interpretation( members.append(("fMarkerColor", numpy.dtype(">i2"))) members.append(("fMarkerStyle", numpy.dtype(">i2"))) members.append(("fMarkerSize", numpy.dtype(">f4"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fMarkerColor"] = uproot4._util.awkward_form( + contents["fMarkerColor"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fMarkerStyle"] = uproot4._util.awkward_form( + contents["fMarkerStyle"] = uproot._util.awkward_form( numpy.dtype("i2"), file, index_format, header, tobject_header ) - contents["fMarkerSize"] = uproot4._util.awkward_form( + contents["fMarkerSize"] = uproot._util.awkward_form( numpy.dtype("f4"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( + return awkward.forms.RecordForm( contents, parameters={"__record__": "TAttMarker"} ) @@ -353,14 +339,14 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru class_code = None -class Model_TAttMarker(uproot4.model.DispatchByVersion): +class Model_TAttMarker(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TAttMarker``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TAttMarker``. """ known_versions = {2: Model_TAttMarker_v2} -uproot4.classes["TAttLine"] = Model_TAttLine -uproot4.classes["TAttFill"] = Model_TAttFill -uproot4.classes["TAttMarker"] = Model_TAttMarker +uproot.classes["TAttLine"] = Model_TAttLine +uproot.classes["TAttFill"] = Model_TAttFill +uproot.classes["TAttMarker"] = Model_TAttMarker diff --git a/uproot4/models/TBasket.py b/uproot/models/TBasket.py similarity index 86% rename from uproot4/models/TBasket.py rename to uproot/models/TBasket.py index e01e7889c..f761bba0c 100644 --- a/uproot4/models/TBasket.py +++ b/uproot/models/TBasket.py @@ -14,11 +14,7 @@ import numpy -import uproot4.model -import uproot4.deserialization -import uproot4.compression -import uproot4.behaviors.TBranch -import uproot4.const +import uproot _tbasket_format1 = struct.Struct(">ihiIhh") @@ -26,9 +22,9 @@ _tbasket_offsets_dtype = numpy.dtype(">i4") -class Model_TBasket(uproot4.model.Model): +class Model_TBasket(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TBasket``. + A versionless :py:class:`~uproot.model.Model` for ``TBasket``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -48,7 +44,7 @@ def raw_data(self): content with entry offsets, if the latter exists. If there are no entry offsets, this is identical to - :py:attr:`~uproot4.models.TBasket.TBasket.data`. + :py:attr:`~uproot.models.TBasket.TBasket.data`. """ return self._raw_data @@ -59,7 +55,7 @@ def data(self): entry offsets, if they exist. If there are no entry offsets, this is identical to - :py:attr:`~uproot4.models.TBasket.TBasket.raw_data`. + :py:attr:`~uproot.models.TBasket.TBasket.raw_data`. """ return self._data @@ -67,24 +63,24 @@ def data(self): def byte_offsets(self): """ The index where each entry starts and stops in the - :py:attr:`~uproot4.models.TBasket.TBasket.data`, not including header. + :py:attr:`~uproot.models.TBasket.TBasket.data`, not including header. The first offset is ``0`` and the number of offsets is one greater than the number of entries, such that the last offset is the length of - :py:attr:`~uproot4.models.TBasket.TBasket.data`. + :py:attr:`~uproot.models.TBasket.TBasket.data`. """ return self._byte_offsets def array(self, interpretation=None, library="ak"): """ The ``TBasket`` data and entry offsets as an array, given an - :py:class:`~uproot4.interpretation.Interpretation` (or the ``TBranch`` parent's - :py:class:`~uproot4.behaviors.TBranch.TBranch.interpretation`) and a + :py:class:`~uproot.interpretation.Interpretation` (or the ``TBranch`` parent's + :py:class:`~uproot.behaviors.TBranch.TBranch.interpretation`) and a ``library``. """ if interpretation is None: interpretation = self._parent.interpretation - library = uproot4.interpretation.library._regularize_library(library) + library = uproot.interpretation.library._regularize_library(library) basket_array = interpretation.basket_array( self.data, @@ -110,7 +106,7 @@ def counts(self): """ The number of items in each entry as a NumPy array, derived from the parent ``TBranch``'s - :py:attr:`~uproot4.behavior.TBranch.TBranch.count_branch`. If there is + :py:attr:`~uproot.behavior.TBranch.TBranch.count_branch`. If there is no such branch (e.g. the data are ``std::vector``), then this method returns None. """ @@ -171,7 +167,7 @@ def uncompressed_bytes(self): The number of bytes for the uncompressed data, not including the header. If the ``TBasket`` is uncompressed, this is equal to - :py:attr:`~uproot4.models.TBasket.TBasket.compressed_bytes`. + :py:attr:`~uproot.models.TBasket.TBasket.compressed_bytes`. """ if self.is_embedded: if self._byte_offsets is None: @@ -188,7 +184,7 @@ def compressed_bytes(self): (which is always uncompressed). If the ``TBasket`` is uncompressed, this is equal to - :py:attr:`~uproot4.models.TBasket.TBasket.uncompressed_bytes`. + :py:attr:`~uproot.models.TBasket.TBasket.uncompressed_bytes`. """ if self.is_embedded: if self._byte_offsets is None: @@ -211,7 +207,7 @@ def read_numbytes_version(self, chunk, cursor, context): pass def read_members(self, chunk, cursor, context, file): - assert isinstance(self._parent, uproot4.behaviors.TBranch.TBranch) + assert isinstance(self._parent, uproot.behaviors.TBranch.TBranch) self._basket_num = context.get("basket_num") ( @@ -261,14 +257,11 @@ def read_members(self, chunk, cursor, context, file): else: if self.compressed_bytes != self.uncompressed_bytes: - uncompressed = uproot4.compression.decompress( + uncompressed = uproot.compression.decompress( chunk, cursor, {}, self.compressed_bytes, self.uncompressed_bytes, ) self._raw_data = uncompressed.get( - 0, - self.uncompressed_bytes, - uproot4.source.cursor.Cursor(0), - context, + 0, self.uncompressed_bytes, uproot.source.cursor.Cursor(0), context, ) else: self._raw_data = cursor.bytes(chunk, self.uncompressed_bytes, context) @@ -289,4 +282,4 @@ def read_members(self, chunk, cursor, context, file): self._byte_offsets = None -uproot4.classes["TBasket"] = Model_TBasket +uproot.classes["TBasket"] = Model_TBasket diff --git a/uproot4/models/TBranch.py b/uproot/models/TBranch.py similarity index 91% rename from uproot4/models/TBranch.py rename to uproot/models/TBranch.py index 5eb851884..53fe3e0cd 100644 --- a/uproot4/models/TBranch.py +++ b/uproot/models/TBranch.py @@ -3,7 +3,7 @@ """ Defines versioned models for ``TBranch`` and its subclasses. -See :py:class:`~uproot4.behaviors.TBranch` for definitions of ``TTree``-reading +See :py:class:`~uproot.behaviors.TBranch` for definitions of ``TTree``-reading functions. """ @@ -13,9 +13,7 @@ import numpy -import uproot4.model -import uproot4.deserialization -import uproot4.behaviors.TBranch +import uproot _tbranch10_format1 = struct.Struct(">iiiiqiIiqqq") @@ -24,11 +22,9 @@ _tbranch10_dtype3 = numpy.dtype(">i8") -class Model_TBranch_v10( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel -): +class Model_TBranch_v10(uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranch`` version 10. + A :py:class:`~uproot.model.VersionedModel` for ``TBranch`` version 10. """ def read_members(self, chunk, cursor, context, file): @@ -154,11 +150,9 @@ def member_names(self): _tbranch11_dtype3 = numpy.dtype(">i8") -class Model_TBranch_v11( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel -): +class Model_TBranch_v11(uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranch`` version 11. + A :py:class:`~uproot.model.VersionedModel` for ``TBranch`` version 11. """ def read_members(self, chunk, cursor, context, file): @@ -286,11 +280,9 @@ def member_names(self): _tbranch12_dtype3 = numpy.dtype(">i8") -class Model_TBranch_v12( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel -): +class Model_TBranch_v12(uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranch`` version 12. + A :py:class:`~uproot.model.VersionedModel` for ``TBranch`` version 12. """ def read_members(self, chunk, cursor, context, file): @@ -419,11 +411,9 @@ def member_names(self): _tbranch13_dtype3 = numpy.dtype(">i8") -class Model_TBranch_v13( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel -): +class Model_TBranch_v13(uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranch`` version 13. + A :py:class:`~uproot.model.VersionedModel` for ``TBranch`` version 13. """ def read_members(self, chunk, cursor, context, file): @@ -551,9 +541,9 @@ def member_names(self): class_code = None -class Model_TBranch(uproot4.model.DispatchByVersion): +class Model_TBranch(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TBranch``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TBranch``. """ known_versions = { @@ -568,10 +558,10 @@ class Model_TBranch(uproot4.model.DispatchByVersion): class Model_TBranchElement_v8( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel + uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel ): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranchElement`` version 8. + A :py:class:`~uproot.model.VersionedModel` for ``TBranchElement`` version 8. """ def read_members(self, chunk, cursor, context, file): @@ -611,10 +601,10 @@ def read_members(self, chunk, cursor, context, file): self._members["fStreamerType"], self._members["fMaximum"], ) = cursor.fields(chunk, _tbranchelement8_format1, context) - self._members["fBranchCount"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchCount2"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount2"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -640,10 +630,10 @@ def read_members(self, chunk, cursor, context, file): class Model_TBranchElement_v9( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel + uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel ): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranchElement`` version 9. + A :py:class:`~uproot.model.VersionedModel` for ``TBranchElement`` version 9. """ def read_members(self, chunk, cursor, context, file): @@ -683,10 +673,10 @@ def read_members(self, chunk, cursor, context, file): self._members["fStreamerType"], self._members["fMaximum"], ) = cursor.fields(chunk, _tbranchelement9_format1, context) - self._members["fBranchCount"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchCount2"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount2"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -712,10 +702,10 @@ def read_members(self, chunk, cursor, context, file): class Model_TBranchElement_v10( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel + uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel ): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranchElement`` version 10. + A :py:class:`~uproot.model.VersionedModel` for ``TBranchElement`` version 10. """ def read_members(self, chunk, cursor, context, file): @@ -755,10 +745,10 @@ def read_members(self, chunk, cursor, context, file): self._members["fStreamerType"], self._members["fMaximum"], ) = cursor.fields(chunk, _tbranchelement10_format1, context) - self._members["fBranchCount"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchCount2"] = uproot4.deserialization.read_object_any( + self._members["fBranchCount2"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -780,9 +770,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TBranchElement(uproot4.model.DispatchByVersion): +class Model_TBranchElement(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TBranchElement``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TBranchElement``. """ known_versions = { @@ -793,10 +783,10 @@ class Model_TBranchElement(uproot4.model.DispatchByVersion): class Model_TBranchObject_v1( - uproot4.behaviors.TBranch.TBranch, uproot4.model.VersionedModel + uproot.behaviors.TBranch.TBranch, uproot.model.VersionedModel ): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TBranchObject`` version 1. + A :py:class:`~uproot.model.VersionedModel` for ``TBranchObject`` version 1. """ def read_members(self, chunk, cursor, context, file): @@ -827,9 +817,9 @@ def read_members(self, chunk, cursor, context, file): class_flags = {} -class Model_TBranchObject(uproot4.model.DispatchByVersion): +class Model_TBranchObject(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TBranchObject``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TBranchObject``. """ known_versions = { @@ -837,6 +827,6 @@ class Model_TBranchObject(uproot4.model.DispatchByVersion): } -uproot4.classes["TBranch"] = Model_TBranch -uproot4.classes["TBranchElement"] = Model_TBranchElement -uproot4.classes["TBranchObject"] = Model_TBranchObject +uproot.classes["TBranch"] = Model_TBranch +uproot.classes["TBranchElement"] = Model_TBranchElement +uproot.classes["TBranchObject"] = Model_TBranchObject diff --git a/uproot4/models/THashList.py b/uproot/models/THashList.py similarity index 83% rename from uproot4/models/THashList.py rename to uproot/models/THashList.py index 7b9a17227..2aa2ae6a3 100644 --- a/uproot4/models/THashList.py +++ b/uproot/models/THashList.py @@ -6,12 +6,12 @@ from __future__ import absolute_import -import uproot4.models.TList +import uproot -class Model_THashList(uproot4.model.Model): +class Model_THashList(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``THashList``. + A versionless :py:class:`~uproot.model.Model` for ``THashList``. """ def read_numbytes_version(self, chunk, cursor, context): @@ -26,7 +26,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TList.Model_TList.read( + uproot.models.TList.Model_TList.read( chunk, cursor, context, @@ -53,4 +53,4 @@ def __len__(self): return len(self._bases[0]) -uproot4.classes["THashList"] = Model_THashList +uproot.classes["THashList"] = Model_THashList diff --git a/uproot4/models/TLeaf.py b/uproot/models/TLeaf.py similarity index 76% rename from uproot4/models/TLeaf.py rename to uproot/models/TLeaf.py index 095591cb1..d92f9bfeb 100644 --- a/uproot4/models/TLeaf.py +++ b/uproot/models/TLeaf.py @@ -8,16 +8,15 @@ import struct -import uproot4.model -import uproot4.deserialization +import uproot _tleaf2_format0 = struct.Struct(">iii??") -class Model_TLeaf_v2(uproot4.model.VersionedModel): +class Model_TLeaf_v2(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeaf`` version 2. + A :py:class:`~uproot.model.VersionedModel` for ``TLeaf`` version 2. """ def read_members(self, chunk, cursor, context, file): @@ -46,7 +45,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fIsRange"], self._members["fIsUnsigned"], ) = cursor.fields(chunk, _tleaf2_format0, context) - self._members["fLeafCount"] = uproot4.deserialization.read_object_any( + self._members["fLeafCount"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -63,9 +62,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeaf(uproot4.model.DispatchByVersion): +class Model_TLeaf(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeaf``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeaf``. """ known_versions = {2: Model_TLeaf_v2} @@ -74,9 +73,9 @@ class Model_TLeaf(uproot4.model.DispatchByVersion): _tleafO1_format1 = struct.Struct(">??") -class Model_TLeafO_v1(uproot4.model.VersionedModel): +class Model_TLeafO_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafO`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafO`` version 1 (``numpy.bool_``). """ @@ -109,9 +108,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafO(uproot4.model.DispatchByVersion): +class Model_TLeafO(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafO`` (``numpy.bool_``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafO`` (``numpy.bool_``). """ known_versions = {1: Model_TLeafO_v1} @@ -120,9 +119,9 @@ class Model_TLeafO(uproot4.model.DispatchByVersion): _tleafb1_format1 = struct.Struct(">bb") -class Model_TLeafB_v1(uproot4.model.VersionedModel): +class Model_TLeafB_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafB`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafB`` version 1 (``numpy.int8``). """ @@ -155,9 +154,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafB(uproot4.model.DispatchByVersion): +class Model_TLeafB(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafB`` (``numpy.int8``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafB`` (``numpy.int8``). """ known_versions = {1: Model_TLeafB_v1} @@ -166,9 +165,9 @@ class Model_TLeafB(uproot4.model.DispatchByVersion): _tleafs1_format1 = struct.Struct(">hh") -class Model_TLeafS_v1(uproot4.model.VersionedModel): +class Model_TLeafS_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafS`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafS`` version 1 (``numpy.int16``). """ @@ -201,9 +200,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafS(uproot4.model.DispatchByVersion): +class Model_TLeafS(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafS`` (``numpy.int16``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafS`` (``numpy.int16``). """ known_versions = {1: Model_TLeafS_v1} @@ -212,9 +211,9 @@ class Model_TLeafS(uproot4.model.DispatchByVersion): _tleafi1_format1 = struct.Struct(">ii") -class Model_TLeafI_v1(uproot4.model.VersionedModel): +class Model_TLeafI_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafI`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafI`` version 1 (``numpy.int32``). """ @@ -247,9 +246,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafI(uproot4.model.DispatchByVersion): +class Model_TLeafI(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafI`` (``numpy.int32``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafI`` (``numpy.int32``). """ known_versions = {1: Model_TLeafI_v1} @@ -258,9 +257,9 @@ class Model_TLeafI(uproot4.model.DispatchByVersion): _tleafl1_format0 = struct.Struct(">qq") -class Model_TLeafL_v1(uproot4.model.VersionedModel): +class Model_TLeafL_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafL`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafL`` version 1 (``numpy.int64``). """ @@ -293,9 +292,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafL(uproot4.model.DispatchByVersion): +class Model_TLeafL(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByversion` for ``TLeafL`` (``numpy.int64``). + A :py:class:`~uproot.model.DispatchByversion` for ``TLeafL`` (``numpy.int64``). """ known_versions = {1: Model_TLeafL_v1} @@ -304,9 +303,9 @@ class Model_TLeafL(uproot4.model.DispatchByVersion): _tleaff1_format1 = struct.Struct(">ff") -class Model_TLeafF_v1(uproot4.model.VersionedModel): +class Model_TLeafF_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafF`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafF`` version 1 (``numpy.float32``). """ @@ -339,9 +338,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafF(uproot4.model.DispatchByVersion): +class Model_TLeafF(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafF`` (``numpy.float32``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafF`` (``numpy.float32``). """ known_versions = {1: Model_TLeafF_v1} @@ -350,9 +349,9 @@ class Model_TLeafF(uproot4.model.DispatchByVersion): _tleafd1_format1 = struct.Struct(">dd") -class Model_TLeafD_v1(uproot4.model.VersionedModel): +class Model_TLeafD_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafD`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafD`` version 1 (``numpy.float64``). """ @@ -385,9 +384,9 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafD(uproot4.model.DispatchByVersion): +class Model_TLeafD(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafD`` (``numpy.float64``). + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafD`` (``numpy.float64``). """ known_versions = {1: Model_TLeafD_v1} @@ -396,9 +395,9 @@ class Model_TLeafD(uproot4.model.DispatchByVersion): _tleafc1_format1 = struct.Struct(">ii") -class Model_TLeafC_v1(uproot4.model.VersionedModel): +class Model_TLeafC_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafC`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafC`` version 1 (variable-length strings). """ @@ -431,18 +430,18 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafC(uproot4.model.DispatchByVersion): +class Model_TLeafC(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafC`` (variable-length + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafC`` (variable-length strings). """ known_versions = {1: Model_TLeafC_v1} -class Model_TLeafF16_v1(uproot4.model.VersionedModel): +class Model_TLeafF16_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafF16`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafF16`` version 1 (ROOT's ``Float16_t``). """ @@ -473,18 +472,18 @@ def read_members(self, chunk, cursor, context, file): class_flags = {} -class Model_TLeafF16(uproot4.model.DispatchByVersion): +class Model_TLeafF16(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafF16`` (ROOT's + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafF16`` (ROOT's ``Float16_t``). """ known_versions = {1: Model_TLeafF16_v1} -class Model_TLeafD32_v1(uproot4.model.VersionedModel): +class Model_TLeafD32_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafD32`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafD32`` version 1 (ROOT's ``Double32_t``). """ @@ -515,9 +514,9 @@ def read_members(self, chunk, cursor, context, file): class_flags = {} -class Model_TLeafD32(uproot4.model.DispatchByVersion): +class Model_TLeafD32(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafD32`` (ROOT's + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafD32`` (ROOT's ``Double32_t``). """ @@ -527,9 +526,9 @@ class Model_TLeafD32(uproot4.model.DispatchByVersion): _tleafelement1_format1 = struct.Struct(">ii") -class Model_TLeafElement_v1(uproot4.model.VersionedModel): +class Model_TLeafElement_v1(uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TLeafElement`` version 1 + A :py:class:`~uproot.model.VersionedModel` for ``TLeafElement`` version 1 (arbitrary objects, associated with ``TBranchElement``). """ @@ -562,24 +561,24 @@ def read_members(self, chunk, cursor, context, file): class_code = None -class Model_TLeafElement(uproot4.model.DispatchByVersion): +class Model_TLeafElement(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TLeafElement`` + A :py:class:`~uproot.model.DispatchByVersion` for ``TLeafElement`` (arbitrary objects, associated with ``TBranchElement``). """ known_versions = {1: Model_TLeafElement_v1} -uproot4.classes["TLeaf"] = Model_TLeaf -uproot4.classes["TLeafB"] = Model_TLeafB -uproot4.classes["TLeafS"] = Model_TLeafS -uproot4.classes["TLeafI"] = Model_TLeafI -uproot4.classes["TLeafL"] = Model_TLeafL -uproot4.classes["TLeafF"] = Model_TLeafF -uproot4.classes["TLeafD"] = Model_TLeafD -uproot4.classes["TLeafC"] = Model_TLeafC -uproot4.classes["TLeafO"] = Model_TLeafO -uproot4.classes["TLeafF16"] = Model_TLeafF16 -uproot4.classes["TLeafD32"] = Model_TLeafD32 -uproot4.classes["TLeafElement"] = Model_TLeafElement +uproot.classes["TLeaf"] = Model_TLeaf +uproot.classes["TLeafB"] = Model_TLeafB +uproot.classes["TLeafS"] = Model_TLeafS +uproot.classes["TLeafI"] = Model_TLeafI +uproot.classes["TLeafL"] = Model_TLeafL +uproot.classes["TLeafF"] = Model_TLeafF +uproot.classes["TLeafD"] = Model_TLeafD +uproot.classes["TLeafC"] = Model_TLeafC +uproot.classes["TLeafO"] = Model_TLeafO +uproot.classes["TLeafF16"] = Model_TLeafF16 +uproot.classes["TLeafD32"] = Model_TLeafD32 +uproot.classes["TLeafElement"] = Model_TLeafElement diff --git a/uproot4/models/TList.py b/uproot/models/TList.py similarity index 82% rename from uproot4/models/TList.py rename to uproot/models/TList.py index 9cfc35636..0b6386968 100644 --- a/uproot4/models/TList.py +++ b/uproot/models/TList.py @@ -13,18 +13,16 @@ except ImportError: from collections import Sequence -import uproot4.model -import uproot4.deserialization -import uproot4.models.TObject +import uproot _tlist_format1 = struct.Struct(">i") _tlist_format2 = struct.Struct(">B") -class Model_TList(uproot4.model.Model, Sequence): +class Model_TList(uproot.model.Model, Sequence): """ - A versionless :py:class:`~uproot4.model.Model` for ``TList``. + A versionless :py:class:`~uproot.model.Model` for ``TList``. """ def read_members(self, chunk, cursor, context, file): @@ -36,7 +34,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TObject.Model_TObject.read( + uproot.models.TObject.Model_TObject.read( chunk, cursor, context, @@ -51,8 +49,8 @@ def read_members(self, chunk, cursor, context, file): self._members["fSize"] = cursor.field(chunk, _tlist_format1, context) self._data = [] - for i in uproot4._util.range(self._members["fSize"]): - item = uproot4.deserialization.read_object_any( + for i in uproot._util.range(self._members["fSize"]): + item = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._parent ) self._data.append(item) @@ -85,4 +83,4 @@ def tojson(self): } -uproot4.classes["TList"] = Model_TList +uproot.classes["TList"] = Model_TList diff --git a/uproot4/models/TNamed.py b/uproot/models/TNamed.py similarity index 72% rename from uproot4/models/TNamed.py rename to uproot/models/TNamed.py index 7f3a7cc2f..1c0925292 100644 --- a/uproot4/models/TNamed.py +++ b/uproot/models/TNamed.py @@ -8,14 +8,12 @@ import numpy -import uproot4.model -import uproot4.models.TObject -import uproot4.containers +import uproot -class Model_TNamed(uproot4.model.Model): +class Model_TNamed(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TNamed``. + A versionless :py:class:`~uproot.model.Model` for ``TNamed``. """ def read_members(self, chunk, cursor, context, file): @@ -27,7 +25,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TObject.Model_TObject.read( + uproot.models.TObject.Model_TObject.read( chunk, cursor, context, @@ -51,23 +49,22 @@ def __repr__(self): @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if header: - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["fName"] = uproot4.containers.AsString( + contents["fName"] = uproot.containers.AsString( False, typename="TString" ).awkward_form(file, index_format, header, tobject_header) - contents["fTitle"] = uproot4.containers.AsString( + contents["fTitle"] = uproot.containers.AsString( False, typename="TString" ).awkward_form(file, index_format, header, tobject_header) - return awkward1.forms.RecordForm(contents, parameters={"__record__": "TNamed"},) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TNamed"},) -uproot4.classes["TNamed"] = Model_TNamed +uproot.classes["TNamed"] = Model_TNamed diff --git a/uproot4/models/TObjArray.py b/uproot/models/TObjArray.py similarity index 78% rename from uproot4/models/TObjArray.py rename to uproot/models/TObjArray.py index 06130ce06..317ef0261 100644 --- a/uproot4/models/TObjArray.py +++ b/uproot/models/TObjArray.py @@ -13,18 +13,15 @@ except ImportError: from collections import Sequence -import uproot4.model -import uproot4.deserialization -import uproot4.models.TObject -import uproot4.models.TBasket +import uproot _tobjarray_format1 = struct.Struct(">ii") -class Model_TObjArray(uproot4.model.Model, Sequence): +class Model_TObjArray(uproot.model.Model, Sequence): """ - A versionless :py:class:`~uproot4.model.Model` for ``TObjArray``. + A versionless :py:class:`~uproot.model.Model` for ``TObjArray``. This also satisfies Python's abstract ``Sequence`` protocol. """ @@ -38,7 +35,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TObject.Model_TObject.read( + uproot.models.TObject.Model_TObject.read( chunk, cursor, context, @@ -54,8 +51,8 @@ def read_members(self, chunk, cursor, context, file): chunk, _tobjarray_format1, context ) self._data = [] - for i in uproot4._util.range(self._members["fSize"]): - item = uproot4.deserialization.read_object_any( + for i in uproot._util.range(self._members["fSize"]): + item = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._parent ) self._data.append(item) @@ -83,12 +80,12 @@ def tojson(self): } -uproot4.classes["TObjArray"] = Model_TObjArray +uproot.classes["TObjArray"] = Model_TObjArray class Model_TObjArrayOfTBaskets(Model_TObjArray): """ - A specialized :py:class:`~uproot4.model.Model` for a ``TObjArray`` of ``TBaskets``. + A specialized :py:class:`~uproot.model.Model` for a ``TObjArray`` of ``TBaskets``. """ def read_members(self, chunk, cursor, context, file): @@ -100,7 +97,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TObject.Model_TObject.read( + uproot.models.TObject.Model_TObject.read( chunk, cursor, context, @@ -117,14 +114,14 @@ def read_members(self, chunk, cursor, context, file): ) self._data = [] - for i in uproot4._util.range(self._members["fSize"]): - item = uproot4.deserialization.read_object_any( + for i in uproot._util.range(self._members["fSize"]): + item = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._parent, - as_class=uproot4.models.TBasket.Model_TBasket, + as_class=uproot.models.TBasket.Model_TBasket, ) self._data.append(item) diff --git a/uproot4/models/TObjString.py b/uproot/models/TObjString.py similarity index 80% rename from uproot4/models/TObjString.py rename to uproot/models/TObjString.py index 4d37fac2d..8fd5cdd4b 100644 --- a/uproot4/models/TObjString.py +++ b/uproot/models/TObjString.py @@ -6,13 +6,12 @@ from __future__ import absolute_import -import uproot4.model -import uproot4.models.TObject +import uproot -class Model_TObjString(uproot4.model.Model, str): +class Model_TObjString(uproot.model.Model, str): """ - A versionless :py:class:`~uproot4.model.Model` for ``TObjString``. + A versionless :py:class:`~uproot.model.Model` for ``TObjString``. This is also a Python ``str`` (string). """ @@ -26,7 +25,7 @@ def read_members(self, chunk, cursor, context, file): ) ) self._bases.append( - uproot4.models.TObject.Model_TObject.read( + uproot.models.TObject.Model_TObject.read( chunk, cursor, context, @@ -60,11 +59,10 @@ def __repr__(self): @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - - return awkward1.forms.ListOffsetForm( + awkward = uproot.extras.awkward() + return awkward.forms.ListOffsetForm( index_format, - awkward1.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), + awkward.forms.NumpyForm((), 1, "B", parameters={"__array__": "char"}), parameters={ "__array__": "string", "uproot": {"as": "TObjString", "header": True, "length_bytes": "1-5"}, @@ -72,4 +70,4 @@ def awkward_form(cls, file, index_format="i64", header=False, tobject_header=Tru ) -uproot4.classes["TObjString"] = Model_TObjString +uproot.classes["TObjString"] = Model_TObjString diff --git a/uproot4/models/TObject.py b/uproot/models/TObject.py similarity index 73% rename from uproot4/models/TObject.py rename to uproot/models/TObject.py index 23cc2f5fb..6db63a3a7 100644 --- a/uproot4/models/TObject.py +++ b/uproot/models/TObject.py @@ -10,17 +10,16 @@ import numpy -import uproot4.model -import uproot4.deserialization +import uproot _tobject_format1 = struct.Struct(">h") _tobject_format2 = struct.Struct(">II") -class Model_TObject(uproot4.model.Model): +class Model_TObject(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TObject``. + A versionless :py:class:`~uproot.model.Model` for ``TObject``. """ def read_numbytes_version(self, chunk, cursor, context): @@ -35,15 +34,15 @@ def read_members(self, chunk, cursor, context, file): ) ) self._instance_version = cursor.field(chunk, _tobject_format1, context) - if numpy.int64(self._instance_version) & uproot4.const.kByteCountVMask: + if numpy.int64(self._instance_version) & uproot.const.kByteCountVMask: cursor.skip(4) self._members["@fUniqueID"], self._members["@fBits"] = cursor.fields( chunk, _tobject_format2, context ) self._members["@fBits"] = ( - numpy.uint32(self._members["@fBits"]) | uproot4.const.kIsOnHeap + numpy.uint32(self._members["@fBits"]) | uproot.const.kIsOnHeap ) - if self._members["@fBits"] & uproot4.const.kIsReferenced: + if self._members["@fBits"] & uproot.const.kIsReferenced: cursor.skip(2) self._members["@fBits"] = int(self._members["@fBits"]) @@ -58,34 +57,31 @@ def strided_interpretation( members.append(("@fUniqueID", numpy.dtype(">u4"))) members.append(("@fBits", numpy.dtype(">u4"))) members.append(("@pidf", numpy.dtype(">u2"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if tobject_header: - contents["@instance_version"] = uproot4._util.awkward_form( + contents["@instance_version"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["@num_bytes"] = uproot4._util.awkward_form( + contents["@num_bytes"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@fUniqueID"] = uproot4._util.awkward_form( + contents["@fUniqueID"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@fBits"] = uproot4._util.awkward_form( + contents["@fBits"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@pidf"] = uproot4._util.awkward_form( + contents["@pidf"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( - contents, parameters={"__record__": "TObject"}, - ) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TObject"},) def __repr__(self): return "".format( @@ -100,4 +96,4 @@ def tojson(self): } -uproot4.classes["TObject"] = Model_TObject +uproot.classes["TObject"] = Model_TObject diff --git a/uproot4/models/TRef.py b/uproot/models/TRef.py similarity index 80% rename from uproot4/models/TRef.py rename to uproot/models/TRef.py index 7768334a7..e660fd94c 100644 --- a/uproot4/models/TRef.py +++ b/uproot/models/TRef.py @@ -15,15 +15,15 @@ import numpy -import uproot4.model +import uproot _tref_format1 = struct.Struct(">xxIxxxxxx") -class Model_TRef(uproot4.model.Model): +class Model_TRef(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TRef``. + A versionless :py:class:`~uproot.model.Model` for ``TRef``. This model does not deserialize all fields, only the reference number. """ @@ -61,38 +61,37 @@ def strided_interpretation( members.append(("@other1", numpy.dtype(">u2"))) members.append(("@other2", numpy.dtype(">u4"))) - return uproot4.interpretation.objects.AsStridedObjects( + return uproot.interpretation.objects.AsStridedObjects( cls, members, original=original ) @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} if tobject_header: - contents["@pidf"] = uproot4._util.awkward_form( + contents["@pidf"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["ref"] = uproot4._util.awkward_form( + contents["ref"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - contents["@other1"] = uproot4._util.awkward_form( + contents["@other1"] = uproot._util.awkward_form( numpy.dtype("u2"), file, index_format, header, tobject_header ) - contents["@other2"] = uproot4._util.awkward_form( + contents["@other2"] = uproot._util.awkward_form( numpy.dtype("u4"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm(contents, parameters={"__record__": "TRef"}) + return awkward.forms.RecordForm(contents, parameters={"__record__": "TRef"}) _trefarray_format1 = struct.Struct(">i") _trefarray_dtype = numpy.dtype(">i4") -class Model_TRefArray(uproot4.model.Model, Sequence): +class Model_TRefArray(uproot.model.Model, Sequence): """ - A versionless :py:class:`~uproot4.model.Model` for ``TRefArray``. + A versionless :py:class:`~uproot.model.Model` for ``TRefArray``. This also satisfies Python's abstract ``Sequence`` protocol. """ @@ -107,7 +106,7 @@ def refs(self): @property def nbytes(self): """ - The number of bytes in :py:attr:`~uproot4.models.TRef.TRefArray.refs`. + The number of bytes in :py:attr:`~uproot.models.TRef.TRefArray.refs`. """ return self._data.nbytes @@ -160,23 +159,21 @@ def __repr__(self): @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - import awkward1 - + awkward = uproot.extras.awkward() contents = {} - - contents["fName"] = uproot4.containers.AsString( + contents["fName"] = uproot.containers.AsString( False, typename="TString" ).awkward_form(file, index_format, header, tobject_header) - contents["fSize"] = uproot4._util.awkward_form( + contents["fSize"] = uproot._util.awkward_form( numpy.dtype("i4"), file, index_format, header, tobject_header ) - contents["refs"] = uproot4._util.awkward_form( + contents["refs"] = uproot._util.awkward_form( numpy.dtype("i4"), file, index_format, header, tobject_header ) - return awkward1.forms.RecordForm( + return awkward.forms.RecordForm( contents, parameters={"__record__": "TRefArray"} ) -uproot4.classes["TRef"] = Model_TRef -uproot4.classes["TRefArray"] = Model_TRefArray +uproot.classes["TRef"] = Model_TRef +uproot.classes["TRefArray"] = Model_TRefArray diff --git a/uproot4/models/TString.py b/uproot/models/TString.py similarity index 85% rename from uproot4/models/TString.py rename to uproot/models/TString.py index 89c570069..f4c5a33c1 100644 --- a/uproot4/models/TString.py +++ b/uproot/models/TString.py @@ -6,12 +6,12 @@ from __future__ import absolute_import -import uproot4.model +import uproot -class Model_TString(uproot4.model.Model, str): +class Model_TString(uproot.model.Model, str): """ - A versionless :py:class:`~uproot4.model.Model` for ``TString``. + A versionless :py:class:`~uproot.model.Model` for ``TString``. This is also a Python ``str`` (string). """ @@ -54,9 +54,9 @@ def tojson(self): @classmethod def awkward_form(cls, file, index_format="i64", header=False, tobject_header=True): - return uproot4.containers.AsString(False, typename="TString").awkward_form( + return uproot.containers.AsString(False, typename="TString").awkward_form( file, index_format, header, tobject_header ) -uproot4.classes["TString"] = Model_TString +uproot.classes["TString"] = Model_TString diff --git a/uproot4/models/TTree.py b/uproot/models/TTree.py similarity index 88% rename from uproot4/models/TTree.py rename to uproot/models/TTree.py index 1fd8ba0b7..de3569bc6 100644 --- a/uproot4/models/TTree.py +++ b/uproot/models/TTree.py @@ -3,7 +3,7 @@ """ Defines versioned models for ``TTree``. -See :py:mod:`uproot4.behaviors.TBranch` for definitions of ``TTree``-reading +See :py:mod:`uproot.behaviors.TBranch` for definitions of ``TTree``-reading functions. """ @@ -13,17 +13,16 @@ import numpy -import uproot4.model -import uproot4.deserialization -import uproot4.behaviors.TTree +import uproot +import uproot.behaviors.TTree _ttree16_format1 = struct.Struct(">qqqqdiiiqqqqq") -class Model_TTree_v16(uproot4.behaviors.TTree.TTree, uproot4.model.VersionedModel): +class Model_TTree_v16(uproot.behaviors.TTree.TTree, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TTree`` version 16. + A :py:class:`~uproot.model.VersionedModel` for ``TTree`` version 16. """ def read_members(self, chunk, cursor, context, file): @@ -99,7 +98,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fLeaves"] = file.class_named("TObjArray").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fAliases"] = uproot4.deserialization.read_object_any( + self._members["fAliases"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -112,16 +111,16 @@ def read_members(self, chunk, cursor, context, file): self._members["fIndex"] = file.class_named("TArrayI").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fTreeIndex"] = uproot4.deserialization.read_object_any( + self._members["fTreeIndex"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fFriends"] = uproot4.deserialization.read_object_any( + self._members["fFriends"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fUserInfo"] = uproot4.deserialization.read_object_any( + self._members["fUserInfo"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchRef"] = uproot4.deserialization.read_object_any( + self._members["fBranchRef"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -171,9 +170,9 @@ def member_names(self): _ttree17_format1 = struct.Struct(">qqqqdiiiiqqqqq") -class Model_TTree_v17(uproot4.behaviors.TTree.TTree, uproot4.model.VersionedModel): +class Model_TTree_v17(uproot.behaviors.TTree.TTree, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TTree`` version 17. + A :py:class:`~uproot.model.VersionedModel` for ``TTree`` version 17. """ def read_members(self, chunk, cursor, context, file): @@ -250,7 +249,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fLeaves"] = file.class_named("TObjArray").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fAliases"] = uproot4.deserialization.read_object_any( + self._members["fAliases"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) if file.options["minimal_ttree_metadata"]: @@ -262,16 +261,16 @@ def read_members(self, chunk, cursor, context, file): self._members["fIndex"] = file.class_named("TArrayI").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fTreeIndex"] = uproot4.deserialization.read_object_any( + self._members["fTreeIndex"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fFriends"] = uproot4.deserialization.read_object_any( + self._members["fFriends"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fUserInfo"] = uproot4.deserialization.read_object_any( + self._members["fUserInfo"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchRef"] = uproot4.deserialization.read_object_any( + self._members["fBranchRef"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -322,9 +321,9 @@ def member_names(self): _ttree18_format1 = struct.Struct(">qqqqqdiiiiqqqqqq") -class Model_TTree_v18(uproot4.behaviors.TTree.TTree, uproot4.model.VersionedModel): +class Model_TTree_v18(uproot.behaviors.TTree.TTree, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TTree`` version 18. + A :py:class:`~uproot.model.VersionedModel` for ``TTree`` version 18. """ def read_members(self, chunk, cursor, context, file): @@ -403,7 +402,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fLeaves"] = file.class_named("TObjArray").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fAliases"] = uproot4.deserialization.read_object_any( + self._members["fAliases"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) if file.options["minimal_ttree_metadata"]: @@ -415,16 +414,16 @@ def read_members(self, chunk, cursor, context, file): self._members["fIndex"] = file.class_named("TArrayI").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fTreeIndex"] = uproot4.deserialization.read_object_any( + self._members["fTreeIndex"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fFriends"] = uproot4.deserialization.read_object_any( + self._members["fFriends"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fUserInfo"] = uproot4.deserialization.read_object_any( + self._members["fUserInfo"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchRef"] = uproot4.deserialization.read_object_any( + self._members["fBranchRef"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -479,9 +478,9 @@ def member_values(self): _ttree19_dtype2 = numpy.dtype(">i8") -class Model_TTree_v19(uproot4.behaviors.TTree.TTree, uproot4.model.VersionedModel): +class Model_TTree_v19(uproot.behaviors.TTree.TTree, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TTree`` version 19. + A :py:class:`~uproot.model.VersionedModel` for ``TTree`` version 19. """ def read_members(self, chunk, cursor, context, file): @@ -573,7 +572,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fLeaves"] = file.class_named("TObjArray").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fAliases"] = uproot4.deserialization.read_object_any( + self._members["fAliases"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) if file.options["minimal_ttree_metadata"]: @@ -585,16 +584,16 @@ def read_members(self, chunk, cursor, context, file): self._members["fIndex"] = file.class_named("TArrayI").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fTreeIndex"] = uproot4.deserialization.read_object_any( + self._members["fTreeIndex"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fFriends"] = uproot4.deserialization.read_object_any( + self._members["fFriends"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fUserInfo"] = uproot4.deserialization.read_object_any( + self._members["fUserInfo"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchRef"] = uproot4.deserialization.read_object_any( + self._members["fBranchRef"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -652,9 +651,9 @@ def member_names(self): _ttree20_dtype2 = numpy.dtype(">i8") -class Model_TTree_v20(uproot4.behaviors.TTree.TTree, uproot4.model.VersionedModel): +class Model_TTree_v20(uproot.behaviors.TTree.TTree, uproot.model.VersionedModel): """ - A :py:class:`~uproot4.model.VersionedModel` for ``TTree`` version 20. + A :py:class:`~uproot.model.VersionedModel` for ``TTree`` version 20. """ def read_members(self, chunk, cursor, context, file): @@ -749,7 +748,7 @@ def read_members(self, chunk, cursor, context, file): self._members["fLeaves"] = file.class_named("TObjArray").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fAliases"] = uproot4.deserialization.read_object_any( + self._members["fAliases"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) if file.options["minimal_ttree_metadata"]: @@ -761,16 +760,16 @@ def read_members(self, chunk, cursor, context, file): self._members["fIndex"] = file.class_named("TArrayI").read( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fTreeIndex"] = uproot4.deserialization.read_object_any( + self._members["fTreeIndex"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fFriends"] = uproot4.deserialization.read_object_any( + self._members["fFriends"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fUserInfo"] = uproot4.deserialization.read_object_any( + self._members["fUserInfo"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) - self._members["fBranchRef"] = uproot4.deserialization.read_object_any( + self._members["fBranchRef"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -824,9 +823,9 @@ def member_names(self): class_code = None -class Model_TTree(uproot4.model.DispatchByVersion): +class Model_TTree(uproot.model.DispatchByVersion): """ - A :py:class:`~uproot4.model.DispatchByVersion` for ``TTree``. + A :py:class:`~uproot.model.DispatchByVersion` for ``TTree``. """ known_versions = { @@ -841,9 +840,9 @@ class Model_TTree(uproot4.model.DispatchByVersion): _tiofeatures_format1 = struct.Struct(">B") -class Model_ROOT_3a3a_TIOFeatures(uproot4.model.Model): +class Model_ROOT_3a3a_TIOFeatures(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``ROOT::TIOFeatures``. + A versionless :py:class:`~uproot.model.Model` for ``ROOT::TIOFeatures``. """ def read_members(self, chunk, cursor, context, file): @@ -858,5 +857,5 @@ def read_members(self, chunk, cursor, context, file): self._members["fIOBits"] = cursor.field(chunk, _tiofeatures_format1, context) -uproot4.classes["TTree"] = Model_TTree -uproot4.classes["ROOT::TIOFeatures"] = Model_ROOT_3a3a_TIOFeatures +uproot.classes["TTree"] = Model_TTree +uproot.classes["ROOT::TIOFeatures"] = Model_ROOT_3a3a_TIOFeatures diff --git a/uproot4/models/__init__.py b/uproot/models/__init__.py similarity index 66% rename from uproot4/models/__init__.py rename to uproot/models/__init__.py index 69ea33679..9320a3d5d 100644 --- a/uproot4/models/__init__.py +++ b/uproot/models/__init__.py @@ -3,9 +3,9 @@ """ Defines models, which are classes of objects read from ROOT files. -Models must be subclasses of :py:class:`~uproot4.model.Model`, and models for a +Models must be subclasses of :py:class:`~uproot.model.Model`, and models for a specific version of a ROOT class must be subclasses of -:py:class:`~uproot4.model.VersionedModel`. +:py:class:`~uproot.model.VersionedModel`. If a C++ class has no associated model, a new model class will be generated from the ROOT file's ``TStreamerInfo``. @@ -13,10 +13,10 @@ To add a versionless model for a ROOT class: 1. Translate the ROOT class name from C++ to Python with - :py:func:`~uproot4.model.classname_encode`. For example, + :py:func:`~uproot.model.classname_encode`. For example, ``"ROOT::RThing"`` becomes ``"Model_ROOT_3a3a_RThing"``. 2. Define a class with that name. -3. Explicitly add it to ``uproot4.classes``. +3. Explicitly add it to ``uproot.classes``. A versionless model is instantiated for any ROOT object with a given class name, regardless of its version. The deserialization procedure may need to @@ -25,23 +25,23 @@ To add a versioned model for a ROOT class: 1. Translate the ROOT class name from C++ to Python with - :py:func:`~uproot4.model.classname_encode` with a specific ``version``. + :py:func:`~uproot.model.classname_encode` with a specific ``version``. For example version ``2`` of ``"ROOT::RThing"`` becomes ``"Model_ROOT_3a3a_RThing_v2"``. 2. Define a class with that name. -3. Explicitly add it to a :py:class:`~uproot4.model.DispatchByVersion` for that - class. You might also need to add a :py:class:`~uproot4.model.DispatchByVersion` - to the ``uproot4.classes``. +3. Explicitly add it to a :py:class:`~uproot.model.DispatchByVersion` for that + class. You might also need to add a :py:class:`~uproot.model.DispatchByVersion` + to the ``uproot.classes``. A versioned model is only instantiated for a ROOT object with a given class -name and version. Uproot has common versions of :py:class:`~uproot4.models.TBranch` -and :py:class:`~uproot4.models.TTree` predefined so that it can usually avoid reading +name and version. Uproot has common versions of :py:class:`~uproot.models.TBranch` +and :py:class:`~uproot.models.TTree` predefined so that it can usually avoid reading a ROOT file's ``TStreamerInfo``. High-level methods and properties should not be defined on the model class; add them as behavior classes. -See also :py:mod:`uproot4.behaviors`. +See also :py:mod:`uproot.behaviors`. """ from __future__ import absolute_import diff --git a/uproot4/reading.py b/uproot/reading.py similarity index 78% rename from uproot4/reading.py rename to uproot/reading.py index 1f5faf66e..d90af9da3 100644 --- a/uproot4/reading.py +++ b/uproot/reading.py @@ -1,11 +1,11 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines the entry-point for opening a file, :py:func:`~uproot4.reading.open`, and +Defines the entry-point for opening a file, :py:func:`~uproot.reading.open`, and the classes that are too fundamental to be models: -:py:class:`~uproot4.reading.ReadOnlyFile` (``TFile``), -:py:class:`~uproot4.reading.ReadOnlyDirectory` (``TDirectory`` or ``TDirectoryFile``), -and :py:class:`~uproot4.reading.ReadOnlyKey` (``TKey``). +:py:class:`~uproot.reading.ReadOnlyFile` (``TFile``), +:py:class:`~uproot.reading.ReadOnlyDirectory` (``TDirectory`` or ``TDirectoryFile``), +and :py:class:`~uproot.reading.ReadOnlyKey` (``TKey``). """ from __future__ import absolute_import @@ -21,17 +21,9 @@ from collections import Mapping from collections import MutableMapping -import uproot4.compression -import uproot4.cache -import uproot4.source.cursor -import uproot4.source.chunk -import uproot4.source.http -import uproot4.source.xrootd -import uproot4.streamers -import uproot4.model -import uproot4.behaviors.TBranch -import uproot4._util -from uproot4._util import no_filter +import uproot +import uproot.behaviors.TBranch +from uproot._util import no_filter def open( @@ -61,15 +53,15 @@ def open( drawn from ``TTrees``; if None, do not use a cache; if a memory size, create a new cache of this size. custom_classes (None or MutableMapping): If None, classes come from - uproot4.classes; otherwise, a container of class definitions that + uproot.classes; otherwise, a container of class definitions that is both used to fill with new classes and search for dependencies. decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, a - :py:class:`~uproot4.source.futures.TrivialExecutor` is created. + :py:class:`~uproot.source.futures.TrivialExecutor` is created. Executors attached to a file are ``shutdown`` when the file is closed. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, a :py:class:`~uproot4.source.futures.TrivialExecutor` + arrays; if None, a :py:class:`~uproot.source.futures.TrivialExecutor` is created. Executors attached to a file are ``shutdown`` when the file is closed. options: See below. @@ -78,20 +70,20 @@ def open( If an object path is given, the return type of this function can be anything that can be extracted from a ROOT file (subclass of - :py:class:`~uproot4.model.Model`). + :py:class:`~uproot.model.Model`). If an object path is not given, the return type is a - :py:class:`~uproot4.reading.ReadOnlyDirectory` *and not* - :py:class:`~uproot4.reading.ReadOnlyFile`. ROOT objects can be extracted from a - :py:class:`~uproot4.reading.ReadOnlyDirectory` but not a - :py:class:`~uproot4.reading.ReadOnlyFile`. + :py:class:`~uproot.reading.ReadOnlyDirectory` *and not* + :py:class:`~uproot.reading.ReadOnlyFile`. ROOT objects can be extracted from a + :py:class:`~uproot.reading.ReadOnlyDirectory` but not a + :py:class:`~uproot.reading.ReadOnlyFile`. Options (type; default): - * file_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.file.MemmapSource`) - * xrootd_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.xrootd.XRootDSource`) - * http_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.http.HTTPSource`) - * object_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.object.ObjectSource`) + * file_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.file.MemmapSource`) + * xrootd_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.xrootd.XRootDSource`) + * http_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.http.HTTPSource`) + * object_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.object.ObjectSource`) * timeout (float for HTTP, int for XRootD; 30) * max_num_elements (None or int; None) * num_workers (int; 1) @@ -101,41 +93,41 @@ def open( Any object derived from a ROOT file is a context manager (works in Python's ``with`` statement) that closes the file when exiting the ``with`` block. - Therefore, the :py:func:`~uproot4.reading.open` function can and usually should + Therefore, the :py:func:`~uproot.reading.open` function can and usually should be used in a ``with`` statement to clean up file handles and threads associated with open files: .. code-block:: python - with uproot4.open("/path/to/file.root:path/to/histogram") as h: + with uproot.open("/path/to/file.root:path/to/histogram") as h: h.to_hist().plot() # file is now closed, even if an exception was raised in the block Other file entry points: - * :py:func:`~uproot4.reading.open` (this function): opens one file to read any + * :py:func:`~uproot.reading.open` (this function): opens one file to read any of its objects. - * :py:func:`~uproot4.behaviors.TBranch.iterate`: iterates through chunks of + * :py:func:`~uproot.behaviors.TBranch.iterate`: iterates through chunks of contiguous entries in ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.concatenate`: returns a single concatenated + * :py:func:`~uproot.behaviors.TBranch.concatenate`: returns a single concatenated array from ``TTrees``. - * :py:func:`~uproot4.behaviors.TBranch.lazy`: returns a lazily read array from + * :py:func:`~uproot.behaviors.TBranch.lazy`: returns a lazily read array from ``TTrees``. """ if isinstance(path, dict) and len(path) == 1: ((file_path, object_path),) = path.items() - elif uproot4._util.isstr(path): - file_path, object_path = uproot4._util.file_object_path_split(path) + elif uproot._util.isstr(path): + file_path, object_path = uproot._util.file_object_path_split(path) else: file_path = path object_path = None - file_path = uproot4._util.regularize_path(file_path) + file_path = uproot._util.regularize_path(file_path) - if not uproot4._util.isstr(file_path) and not ( + if not uproot._util.isstr(file_path) and not ( hasattr(file_path, "read") and hasattr(file_path, "seek") ): raise ValueError( @@ -161,10 +153,10 @@ def open( open.defaults = { - "file_handler": uproot4.source.file.MemmapSource, - "xrootd_handler": uproot4.source.xrootd.XRootDSource, - "http_handler": uproot4.source.http.HTTPSource, - "object_handler": uproot4.source.object.ObjectSource, + "file_handler": uproot.source.file.MemmapSource, + "xrootd_handler": uproot.source.xrootd.XRootDSource, + "http_handler": uproot.source.http.HTTPSource, + "object_handler": uproot.source.object.ObjectSource, "timeout": 30, "max_num_elements": None, "num_workers": 1, @@ -191,19 +183,19 @@ def open( class CommonFileMethods(object): """ - Abstract class for :py:class:`~uproot4.reading.ReadOnlyFile` and - :py:class:`~uproot4.reading.DetachedFile`. The latter is a placeholder for file - information, such as the :py:attr:`~uproot4.reading.CommonFileMethods.file_path` + Abstract class for :py:class:`~uproot.reading.ReadOnlyFile` and + :py:class:`~uproot.reading.DetachedFile`. The latter is a placeholder for file + information, such as the :py:attr:`~uproot.reading.CommonFileMethods.file_path` used in many error messages, without holding a reference to the active - :py:class:`~uproot4.source.chunk.Source`. + :py:class:`~uproot.source.chunk.Source`. This allows the file to be closed and deleted while objects that were read from it still exist. Also, only objects that hold detached file references, rather than active ones, can be pickled. The (unpickleable) objects that must hold a reference to an active - :py:class:`~uproot4.reading.ReadOnlyFile` are listed by C++ (decoded) classname - in ``uproot4.must_be_attached``. + :py:class:`~uproot.reading.ReadOnlyFile` are listed by C++ (decoded) classname + in ``uproot.must_be_attached``. """ @property @@ -218,7 +210,7 @@ def file_path(self): def options(self): """ The dict of ``options`` originally passed to the - :py:class:`~uproot4.reading.ReadOnlyFile` constructor. + :py:class:`~uproot.reading.ReadOnlyFile` constructor. """ return self._options @@ -227,8 +219,8 @@ def root_version(self): """ Version of ROOT used to write the file as a string. - See :py:attr:`~uproot4.reading.CommonFileMethods.root_version_tuple` and - :py:attr:`~uproot4.reading.CommonFileMethods.fVersion`. + See :py:attr:`~uproot.reading.CommonFileMethods.root_version_tuple` and + :py:attr:`~uproot.reading.CommonFileMethods.fVersion`. """ return "{0}.{1:02d}/{2:02d}".format(*self.root_version_tuple) @@ -237,8 +229,8 @@ def root_version_tuple(self): """ Version of ROOT used to write teh file as a tuple. - See :py:attr:`~uproot4.reading.CommonFileMethods.root_version` and - :py:attr:`~uproot4.reading.CommonFileMethods.fVersion`. + See :py:attr:`~uproot.reading.CommonFileMethods.root_version` and + :py:attr:`~uproot.reading.CommonFileMethods.fVersion`. """ version = self._fVersion if version >= 1000000: @@ -258,18 +250,18 @@ def is_64bit(self): A file that is larger than 4 GiB must be 64-bit ready, though any file might be. This refers to seek points like - :py:attr:`~uproot4.reading.ReadOnlyFile.fSeekFree` being 64-bit integers, + :py:attr:`~uproot.reading.ReadOnlyFile.fSeekFree` being 64-bit integers, rather than 32-bit. Note that a file being 64-bit is distinct from a ``TDirectory`` being - 64-bit; see :py:attr:`~uproot4.reading.ReadOnlyDirectory.is_64bit`. + 64-bit; see :py:attr:`~uproot.reading.ReadOnlyDirectory.is_64bit`. """ return self._fVersion >= 1000000 @property def compression(self): """ - A :py:class:`~uproot4.compression.Compression` object describing the + A :py:class:`~uproot.compression.Compression` object describing the compression setting for the ROOT file. Note that different objects (even different ``TBranches`` within a @@ -278,12 +270,12 @@ def compression(self): be compressed. For some versions of ROOT ``TStreamerInfo`` is always compressed with - :py:class:`~uproot4.compression.ZLIB`, even if the compression is set to a + :py:class:`~uproot.compression.ZLIB`, even if the compression is set to a different algorithm. - See :py:attr:`~uproot4.reading.CommonFileMethods.fCompress`. + See :py:attr:`~uproot.reading.CommonFileMethods.fCompress`. """ - return uproot4.compression.Compression.from_code(self._fCompress) + return uproot.compression.Compression.from_code(self._fCompress) @property def hex_uuid(self): @@ -291,10 +283,10 @@ def hex_uuid(self): The unique identifier (UUID) of the ROOT file expressed as a hexadecimal string. - See :py:attr:`~uproot4.reading.CommonFileMethods.uuid` and - :py:attr:`~uproot4.reading.CommonFileMethods.fUUID`. + See :py:attr:`~uproot.reading.CommonFileMethods.uuid` and + :py:attr:`~uproot.reading.CommonFileMethods.fUUID`. """ - if uproot4._util.py2: + if uproot._util.py2: out = "".join("{0:02x}".format(ord(x)) for x in self._fUUID) else: out = "".join("{0:02x}".format(x) for x in self._fUUID) @@ -306,8 +298,8 @@ def uuid(self): The unique identifier (UUID) of the ROOT file expressed as a Python ``uuid.UUID`` object. - See :py:attr:`~uproot4.reading.CommonFileMethods.hex_uuid` and - :py:attr:`~uproot4.reading.CommonFileMethods.fUUID`. + See :py:attr:`~uproot.reading.CommonFileMethods.hex_uuid` and + :py:attr:`~uproot.reading.CommonFileMethods.fUUID`. """ return uuid.UUID(self.hex_uuid.replace("-", "")) @@ -315,9 +307,9 @@ def uuid(self): def fVersion(self): """ Raw version information for the ROOT file; this number is used to derive - :py:attr:`~uproot4.reading.CommonFileMethods.root_version`, - :py:attr:`~uproot4.reading.CommonFileMethods.root_version_tuple`, and - :py:attr:`~uproot4.reading.CommonFileMethods.is_64bit`. + :py:attr:`~uproot.reading.CommonFileMethods.root_version`, + :py:attr:`~uproot.reading.CommonFileMethods.root_version_tuple`, and + :py:attr:`~uproot.reading.CommonFileMethods.is_64bit`. """ return self._fVersion @@ -389,10 +381,10 @@ def fCompress(self): be compressed. For some versions of ROOT ``TStreamerInfo`` is always compressed with - :py:class:`~uproot4.compression.ZLIB`, even if the compression is set to a + :py:class:`~uproot.compression.ZLIB`, even if the compression is set to a different algorithm. - See :py:attr:`~uproot4.reading.CommonFileMethods.compression`. + See :py:attr:`~uproot.reading.CommonFileMethods.compression`. """ return self._fCompress @@ -400,7 +392,7 @@ def fCompress(self): def fSeekInfo(self): """ The seek point (int) to the ``TStreamerInfo`` data, where - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` are located. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` are located. """ return self._fSeekInfo @@ -408,7 +400,7 @@ def fSeekInfo(self): def fNbytesInfo(self): """ The number of bytes in the ``TStreamerInfo`` data, where - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` are located. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` are located. """ return self._fNbytesInfo @@ -418,8 +410,8 @@ def fUUID(self): The unique identifier (UUID) of the ROOT file as a raw bytestring (Python ``bytes``). - See :py:attr:`~uproot4.reading.CommonFileMethods.hex_uuid` and - :py:attr:`~uproot4.reading.CommonFileMethods.uuid`. + See :py:attr:`~uproot.reading.CommonFileMethods.hex_uuid` and + :py:attr:`~uproot.reading.CommonFileMethods.uuid`. """ return self._fUUID @@ -427,21 +419,21 @@ def fUUID(self): class DetachedFile(CommonFileMethods): """ Args: - file (:py:class:`~uproot4.reading.ReadOnlyFile`): The active file object to + file (:py:class:`~uproot.reading.ReadOnlyFile`): The active file object to convert into a detached file. - A placeholder for a :py:class:`~uproot4.reading.ReadOnlyFile` with useful - information, such as the :py:attr:`~uproot4.reading.CommonFileMethods.file_path` + A placeholder for a :py:class:`~uproot.reading.ReadOnlyFile` with useful + information, such as the :py:attr:`~uproot.reading.CommonFileMethods.file_path` used in many error messages, without holding a reference to the active - :py:class:`~uproot4.source.chunk.Source`. + :py:class:`~uproot.source.chunk.Source`. This allows the file to be closed and deleted while objects that were read from it still exist. Also, only objects that hold detached file references, rather than active ones, can be pickled. The (unpickleable) objects that must hold a reference to an active - :py:class:`~uproot4.reading.ReadOnlyFile` are listed by C++ (decoded) classname - in ``uproot4.must_be_attached``. + :py:class:`~uproot.reading.ReadOnlyFile` are listed by C++ (decoded) classname + in ``uproot.must_be_attached``. """ def __init__(self, file): @@ -470,7 +462,7 @@ class ReadOnlyFile(CommonFileMethods): """ Args: file_path (str or ``pathlib.Path``): The filesystem path or remote URL - of the file to open. Unlike :py:func:`~uproot4.reading.open`, it cannot + of the file to open. Unlike :py:func:`~uproot.reading.open`, it cannot be followed by a colon (``:``) and an object path within the ROOT file. object_cache (None, MutableMapping, or int): Cache of objects drawn @@ -481,42 +473,42 @@ class ReadOnlyFile(CommonFileMethods): drawn from ``TTrees``; if None, do not use a cache; if a memory size, create a new cache of this size. custom_classes (None or MutableMapping): If None, classes come from - uproot4.classes; otherwise, a container of class definitions that + uproot.classes; otherwise, a container of class definitions that is both used to fill with new classes and search for dependencies. decompression_executor (None or Executor with a ``submit`` method): The executor that is used to decompress ``TBaskets``; if None, a - :py:class:`~uproot4.source.futures.TrivialExecutor` is created. + :py:class:`~uproot.source.futures.TrivialExecutor` is created. Executors attached to a file are ``shutdown`` when the file is closed. interpretation_executor (None or Executor with a ``submit`` method): The executor that is used to interpret uncompressed ``TBasket`` data as - arrays; if None, a :py:class:`~uproot4.source.futures.TrivialExecutor` + arrays; if None, a :py:class:`~uproot.source.futures.TrivialExecutor` is created. Executors attached to a file are ``shutdown`` when the file is closed. options: See below. Handle to an open ROOT file, the way to access data in ``TDirectories`` - (:py:class:`~uproot4.reading.ReadOnlyDirectory`) and create new classes from - ``TStreamerInfo`` (:py:attr:`~uproot4.reading.ReadOnlyFile.streamers`). + (:py:class:`~uproot.reading.ReadOnlyDirectory`) and create new classes from + ``TStreamerInfo`` (:py:attr:`~uproot.reading.ReadOnlyFile.streamers`). All objects derived from ROOT files have a pointer back to the file, - though this is a :py:class:`~uproot4.reading.DetachedFile` (no active connection, - cannot read more data) if the object's :py:attr:`~uproot4.model.Model.classname` - is not in ``uproot4.reading.must_be_attached``: objects that can read + though this is a :py:class:`~uproot.reading.DetachedFile` (no active connection, + cannot read more data) if the object's :py:attr:`~uproot.model.Model.classname` + is not in ``uproot.reading.must_be_attached``: objects that can read more data and need to have an active connection (like ``TTree``, ``TBranch``, and ``TDirectory``). - Note that a :py:class:`~uproot4.reading.ReadOnlyFile` can't be directly used to - extract objects. To read data, use the :py:class:`~uproot4.reading.ReadOnlyDirectory` - returned by :py:attr:`~uproot4.reading.ReadOnlyFile.root_directory`. This is why - :py:func:`~uproot4.reading.open` returns a :py:class:`~uproot4.reading.ReadOnlyDirectory` - and not a :py:class:`~uproot4.reading.ReadOnlyFile`. + Note that a :py:class:`~uproot.reading.ReadOnlyFile` can't be directly used to + extract objects. To read data, use the :py:class:`~uproot.reading.ReadOnlyDirectory` + returned by :py:attr:`~uproot.reading.ReadOnlyFile.root_directory`. This is why + :py:func:`~uproot.reading.open` returns a :py:class:`~uproot.reading.ReadOnlyDirectory` + and not a :py:class:`~uproot.reading.ReadOnlyFile`. Options (type; default): - * file_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.file.MemmapSource`) - * xrootd_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.xrootd.XRootDSource`) - * http_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.http.HTTPSource`) - * object_handler (:py:class:`~uproot4.source.chunk.Source` class; :py:class:`~uproot4.source.object.ObjectSource`) + * file_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.file.MemmapSource`) + * xrootd_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.xrootd.XRootDSource`) + * http_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.http.HTTPSource`) + * object_handler (:py:class:`~uproot.source.chunk.Source` class; :py:class:`~uproot.source.object.ObjectSource`) * timeout (float for HTTP, int for XRootD; 30) * max_num_elements (None or int; None) * num_workers (int; 1) @@ -548,14 +540,14 @@ def __init__( self._options = dict(open.defaults) self._options.update(options) for option in ["begin_chunk_size"]: - self._options[option] = uproot4._util.memory_size(self._options[option]) + self._options[option] = uproot._util.memory_size(self._options[option]) self._streamers = None self._streamer_rules = None self.hook_before_create_source() - Source, file_path = uproot4._util.file_path_to_source_class( + Source, file_path = uproot._util.file_path_to_source_class( file_path, self._options ) self._source = Source( @@ -590,7 +582,7 @@ def __init__( self._fNbytesInfo, self._fUUID_version, self._fUUID, - ) = uproot4.source.cursor.Cursor(0).fields( + ) = uproot.source.cursor.Cursor(0).fields( self._begin_chunk, _file_header_fields_small, {} ) @@ -610,7 +602,7 @@ def __init__( self._fNbytesInfo, self._fUUID_version, self._fUUID, - ) = uproot4.source.cursor.Cursor(0).fields( + ) = uproot.source.cursor.Cursor(0).fields( self._begin_chunk, _file_header_fields_big, {} ) @@ -632,7 +624,7 @@ def __repr__(self): @property def detached(self): """ - A :py:class:`~uproot4.reading.DetachedFile` version of this file. + A :py:class:`~uproot.reading.DetachedFile` version of this file. """ return DetachedFile(self) @@ -644,9 +636,9 @@ def close(self): managers.) After closing, new objects and classes cannot be extracted from the file, - but objects with :py:class:`~uproot4.reading.DetachedFile` references instead - of :py:class:`~uproot4.reading.ReadOnlyFile` that are still in the - :py:attr:`~uproot4.reading.ReadOnlyFile.object_cache` would still be + but objects with :py:class:`~uproot.reading.DetachedFile` references instead + of :py:class:`~uproot.reading.ReadOnlyFile` that are still in the + :py:attr:`~uproot.reading.ReadOnlyFile.object_cache` would still be accessible. """ self._source.close() @@ -661,13 +653,13 @@ def closed(self): True if the file has been closed; False otherwise. The file may have been closed explicitly with - :py:meth:`~uproot4.reading.ReadOnlyFile.close` or implicitly in the Python + :py:meth:`~uproot.reading.ReadOnlyFile.close` or implicitly in the Python ``with`` statement, as a context manager. After closing, new objects and classes cannot be extracted from the file, - but objects with :py:class:`~uproot4.reading.DetachedFile` references instead - of :py:class:`~uproot4.reading.ReadOnlyFile` that are still in the - :py:attr:`~uproot4.reading.ReadOnlyFile.object_cache` would still be + but objects with :py:class:`~uproot.reading.DetachedFile` references instead + of :py:class:`~uproot.reading.ReadOnlyFile` that are still in the + :py:attr:`~uproot.reading.ReadOnlyFile.object_cache` would still be accessible. """ return self._source.closed @@ -686,7 +678,7 @@ def __exit__(self, exception_type, exception_value, traceback): @property def source(self): """ - The :py:class:`~uproot4.source.chunk.Source` associated with this file, which + The :py:class:`~uproot.source.chunk.Source` associated with this file, which is the "physical layer" that knows how to communicate with local file systems or through remote protocols like HTTP(S) or XRootD, but does not know what the bytes mean. @@ -708,7 +700,7 @@ def object_cache(self): Any Python ``MutableMapping`` can be used as a cache (i.e. a Python dict would be a cache that never evicts old objects), though - :py:class:`~uproot4.cache.LRUCache` is a good choice because it is thread-safe + :py:class:`~uproot.cache.LRUCache` is a good choice because it is thread-safe and evicts least-recently used objects when a maximum number of objects is reached. """ @@ -718,8 +710,8 @@ def object_cache(self): def object_cache(self, value): if value is None or isinstance(value, MutableMapping): self._object_cache = value - elif uproot4._util.isint(value): - self._object_cache = uproot4.cache.LRUCache(value) + elif uproot._util.isint(value): + self._object_cache = uproot.cache.LRUCache(value) else: raise TypeError("object_cache must be None, a MutableMapping, or an int") @@ -738,7 +730,7 @@ def array_cache(self): Any Python ``MutableMapping`` can be used as a cache (i.e. a Python dict would be a cache that never evicts old objects), though - :py:class:`~uproot4.cache.LRUArrayCache` is a good choice because it is + :py:class:`~uproot.cache.LRUArrayCache` is a good choice because it is thread-safe and evicts least-recently used objects when a size limit is reached. """ @@ -748,8 +740,8 @@ def array_cache(self): def array_cache(self, value): if value is None or isinstance(value, MutableMapping): self._array_cache = value - elif uproot4._util.isint(value) or uproot4._util.isstr(value): - self._array_cache = uproot4.cache.LRUArrayCache(value) + elif uproot._util.isint(value) or uproot._util.isstr(value): + self._array_cache = uproot.cache.LRUArrayCache(value) else: raise TypeError( "array_cache must be None, a MutableMapping, or a memory size" @@ -759,11 +751,11 @@ def array_cache(self, value): def root_directory(self): """ The root ``TDirectory`` of the file - (:py:class:`~uproot4.reading.ReadOnlyDirectory`). + (:py:class:`~uproot.reading.ReadOnlyDirectory`). """ return ReadOnlyDirectory( (), - uproot4.source.cursor.Cursor(self._fBEGIN + self._fNbytesName), + uproot.source.cursor.Cursor(self._fBEGIN + self._fNbytesName), {}, self, self, @@ -800,7 +792,7 @@ def show_streamers(self, classname=None, version="max", stream=sys.stdout): fP: TVector3 (TStreamerObject) fE: double (TStreamerBasicType) """ - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) if classname is None: names = [] for name, streamer_versions in self.streamers.items(): @@ -820,28 +812,28 @@ def show_streamers(self, classname=None, version="max", stream=sys.stdout): @property def streamers(self): """ - A list of :py:class:`~uproot4.streamers.Model_TStreamerInfo` objects + A list of :py:class:`~uproot.streamers.Model_TStreamerInfo` objects representing the ``TStreamerInfos`` in the ROOT file. A file's ``TStreamerInfos`` are only read the first time they are needed. - Uproot has a suite of predefined models in ``uproot4.models`` to reduce + Uproot has a suite of predefined models in ``uproot.models`` to reduce the probability that ``TStreamerInfos`` will need to be read (depending on the choice of classes or versions of the classes that are accessed). - See also :py:attr:`~uproot4.reading.ReadOnlyFile.streamer_rules`, which are + See also :py:attr:`~uproot.reading.ReadOnlyFile.streamer_rules`, which are read in the same pass with ``TStreamerInfos``. """ - import uproot4.streamers - import uproot4.models.TList - import uproot4.models.TObjArray - import uproot4.models.TObjString + import uproot.streamers + import uproot.models.TList + import uproot.models.TObjArray + import uproot.models.TObjString if self._streamers is None: if self._fSeekInfo == 0: self._streamers = {} else: - key_cursor = uproot4.source.cursor.Cursor(self._fSeekInfo) + key_cursor = uproot.source.cursor.Cursor(self._fSeekInfo) key_start = self._fSeekInfo key_stop = min(self._fSeekInfo + _key_format_big.size, self._fEND) key_chunk = self.chunk(key_start, key_stop) @@ -871,7 +863,7 @@ def streamers(self): streamer_chunk=streamer_chunk, ) - classes = uproot4.model.maybe_custom_classes(self._custom_classes) + classes = uproot.model.maybe_custom_classes(self._custom_classes) tlist = classes["TList"].read( streamer_chunk, streamer_cursor, {}, self, self.detached, None ) @@ -880,13 +872,13 @@ def streamers(self): self._streamer_rules = [] for x in tlist: - if isinstance(x, uproot4.streamers.Model_TStreamerInfo): + if isinstance(x, uproot.streamers.Model_TStreamerInfo): if x.name not in self._streamers: self._streamers[x.name] = {} self._streamers[x.name][x.class_version] = x - elif isinstance(x, uproot4.models.TList.Model_TList) and all( - isinstance(y, uproot4.models.TObjString.Model_TObjString) + elif isinstance(x, uproot.models.TList.Model_TList) and all( + isinstance(y, uproot.models.TObjString.Model_TObjString) for y in x ): self._streamer_rules.extend([str(y) for y in x]) @@ -920,7 +912,7 @@ def streamer_rules(self): Uproot does not have access to a C++ compiler. These rules are read in the same pass that produces - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. """ if self._streamer_rules is None: self.streamers @@ -928,7 +920,7 @@ def streamer_rules(self): def streamers_named(self, classname): """ - Returns a list of :py:class:`~uproot4.streamers.Model_TStreamerInfo` objects + Returns a list of :py:class:`~uproot.streamers.Model_TStreamerInfo` objects that match C++ (decoded) ``classname``. More that one streamer matching a given name is unlikely, but possible @@ -936,9 +928,9 @@ def streamers_named(self, classname): files can be created by merging data from different ROOT versions with hadd?) - See also :py:attr:`~uproot4.reading.ReadOnlyFile.streamer_named` (singular). + See also :py:attr:`~uproot.reading.ReadOnlyFile.streamer_named` (singular). """ - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) streamer_versions = self.streamers.get(classname) if streamer_versions is None: return [] @@ -947,16 +939,16 @@ def streamers_named(self, classname): def streamer_named(self, classname, version="max"): """ - Returns a single :py:class:`~uproot4.streamers.Model_TStreamerInfo` object + Returns a single :py:class:`~uproot.streamers.Model_TStreamerInfo` object that matches C++ (decoded) ``classname`` and ``version``. The ``version`` can be an integer or ``"min"`` or ``"max"`` for the minimum and maximum version numbers available in the file. The default is ``"max"`` because there's usually only one. - See also :py:attr:`~uproot4.reading.ReadOnlyFile.streamers_named` (plural). + See also :py:attr:`~uproot.reading.ReadOnlyFile.streamers_named` (plural). """ - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) streamer_versions = self.streamers.get(classname) if streamer_versions is None or len(streamer_versions) == 0: return None @@ -969,14 +961,14 @@ def streamer_named(self, classname, version="max"): def streamer_dependencies(self, classname, version="max"): """ - Returns a list of :py:class:`~uproot4.streamers.Model_TStreamerInfo` objects + Returns a list of :py:class:`~uproot.streamers.Model_TStreamerInfo` objects that depend on the one that matches C++ (decoded) ``classname`` and ``version``. The ``classname`` and ``version`` are interpreted the same way as - :py:attr:`~uproot4.reading.ReadOnlyFile.streamer_named`. + :py:attr:`~uproot.reading.ReadOnlyFile.streamer_named`. """ - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) streamer = self.streamer_named(classname, version=version) out = [] if streamer is not None: @@ -987,7 +979,7 @@ def streamer_dependencies(self, classname, version="max"): def custom_classes(self): """ Either a dict of class objects specific to this file or None if it uses - the common ``uproot4.classes`` pool. + the common ``uproot.classes`` pool. """ return self._custom_classes @@ -1014,7 +1006,7 @@ def decompression_executor(self): @decompression_executor.setter def decompression_executor(self, value): if value is None: - value = uproot4.source.futures.TrivialExecutor() + value = uproot.source.futures.TrivialExecutor() if not hasattr(value, "submit"): raise TypeError("decompression_executor must have a 'submit' method") self._decompression_executor = value @@ -1035,7 +1027,7 @@ def interpretation_executor(self): @interpretation_executor.setter def interpretation_executor(self, value): if value is None: - value = uproot4.source.futures.TrivialExecutor() + value = uproot.source.futures.TrivialExecutor() if not hasattr(value, "submit"): raise TypeError("interpretation_executor must have a 'submit' method") self._interpretation_executor = value @@ -1043,21 +1035,21 @@ def interpretation_executor(self, value): def remove_class_definition(self, classname): """ Removes all versions of a class, specified by C++ (decoded) - ``classname``, from the :py:attr:`~uproot4.reading.ReadOnlyFile.custom_classes`. + ``classname``, from the :py:attr:`~uproot.reading.ReadOnlyFile.custom_classes`. If the file doesn't have a - :py:attr:`~uproot4.reading.ReadOnlyFile.custom_classes`, this function adds + :py:attr:`~uproot.reading.ReadOnlyFile.custom_classes`, this function adds one, so it does not remove the class from the common pool. If you want to remove a class from the common pool, you can do so with .. code-block:: python - del uproot4.classes[classname] + del uproot.classes[classname] """ - classname = uproot4.model.classname_regularize(classname) + classname = uproot.model.classname_regularize(classname) if self._custom_classes is None: - self._custom_classes = dict(uproot4.classes) + self._custom_classes = dict(uproot.classes) if classname in self._custom_classes: del self._custom_classes[classname] @@ -1067,45 +1059,45 @@ def class_named(self, classname, version=None): and possible ``version``. * If the ``version`` is None, this function may return a - :py:class:`~uproot4.model.DispatchByVersion`. + :py:class:`~uproot.model.DispatchByVersion`. * If the ``version`` is an integer, ``"min"`` or ``"max"``, then it - returns a :py:class:`~uproot4.model.VersionedModel`. Using ``"min"`` or + returns a :py:class:`~uproot.model.VersionedModel`. Using ``"min"`` or ``"max"`` specifies the minium or maximum version ``TStreamerInfo`` defined by the file; most files define only one so ``"max"`` is usually safe. - If this file has :py:attr:`~uproot4.reading.ReadOnlyFile.custom_classes`, + If this file has :py:attr:`~uproot.reading.ReadOnlyFile.custom_classes`, the new class is added to that dict; otherwise, it is added to the - global ``uproot4.classes``. + global ``uproot.classes``. """ - classname = uproot4.model.classname_regularize(classname) - classes = uproot4.model.maybe_custom_classes(self._custom_classes) + classname = uproot.model.classname_regularize(classname) + classes = uproot.model.maybe_custom_classes(self._custom_classes) cls = classes.get(classname) if cls is None: streamers = self.streamers_named(classname) if len(streamers) == 0: - unknown_cls = uproot4.unknown_classes.get(classname) + unknown_cls = uproot.unknown_classes.get(classname) if unknown_cls is None: - unknown_cls = uproot4._util.new_class( - uproot4.model.classname_encode(classname, unknown=True), - (uproot4.model.UnknownClass,), + unknown_cls = uproot._util.new_class( + uproot.model.classname_encode(classname, unknown=True), + (uproot.model.UnknownClass,), {}, ) - uproot4.unknown_classes[classname] = unknown_cls + uproot.unknown_classes[classname] = unknown_cls return unknown_cls else: - cls = uproot4._util.new_class( - uproot4._util.ensure_str(uproot4.model.classname_encode(classname)), - (uproot4.model.DispatchByVersion,), + cls = uproot._util.new_class( + uproot._util.ensure_str(uproot.model.classname_encode(classname)), + (uproot.model.DispatchByVersion,), {"known_versions": {}}, ) classes[classname] = cls - if version is not None and issubclass(cls, uproot4.model.DispatchByVersion): - if not uproot4._util.isint(version): + if version is not None and issubclass(cls, uproot.model.DispatchByVersion): + if not uproot._util.isint(version): streamer = self.streamer_named(classname, version) if streamer is not None: version = streamer.class_version @@ -1114,16 +1106,16 @@ def class_named(self, classname, version=None): elif version == "min" and len(cls.known_versions) != 0: version = min(cls.known_versions) else: - unknown_cls = uproot4.unknown_classes.get(classname) + unknown_cls = uproot.unknown_classes.get(classname) if unknown_cls is None: - unknown_cls = uproot4._util.new_class( - uproot4.model.classname_encode( + unknown_cls = uproot._util.new_class( + uproot.model.classname_encode( classname, version, unknown=True ), - (uproot4.model.UnknownClassVersion,), + (uproot.model.UnknownClassVersion,), {}, ) - uproot4.unknown_classes[classname] = unknown_cls + uproot.unknown_classes[classname] = unknown_cls return unknown_cls versioned_cls = cls.class_of_version(version) @@ -1136,12 +1128,12 @@ def class_named(self, classname, version=None): def chunk(self, start, stop): """ - Returns a :py:class:`~uproot4.source.chunk.Chunk` from the - :py:class:`~uproot4.source.chunk.Source` that is guaranteed to include bytes + Returns a :py:class:`~uproot.source.chunk.Chunk` from the + :py:class:`~uproot.source.chunk.Source` that is guaranteed to include bytes from ``start`` up to ``stop`` seek points in the file. If the desired range is satisfied by a previously saved chunk, such as - :py:attr:`~uproot4.reading.ReadOnlyFile.begin_chunk`, then that is returned. + :py:attr:`~uproot.reading.ReadOnlyFile.begin_chunk`, then that is returned. Hence, the returned chunk may include more data than the range from ``start`` up to ``stop``. """ @@ -1155,7 +1147,7 @@ def chunk(self, start, stop): @property def begin_chunk(self): """ - A special :py:class:`~uproot4.source.chunk.Chunk` corresponding to the + A special :py:class:`~uproot.source.chunk.Chunk` corresponding to the beginning of the file, from seek point ``0`` up to ``options["begin_chunk_size"]``. """ @@ -1163,55 +1155,55 @@ def begin_chunk(self): def hook_before_create_source(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyFile` constructor before the - :py:class:`~uproot4.source.chunk.Source` is created. + Called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor before the + :py:class:`~uproot.source.chunk.Source` is created. - This is the first hook called in the :py:class:`~uproot4.reading.ReadOnlyFile` + This is the first hook called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor. """ pass def hook_before_get_chunks(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyFile` constructor after the - :py:class:`~uproot4.source.chunk.Source` is created but before attempting to - get any :py:class:`~uproot4.source.chunk.Chunk`, specifically the - :py:attr:`~uproot4.reading.ReadOnlyFile.begin_chunk`. + Called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor after the + :py:class:`~uproot.source.chunk.Source` is created but before attempting to + get any :py:class:`~uproot.source.chunk.Chunk`, specifically the + :py:attr:`~uproot.reading.ReadOnlyFile.begin_chunk`. """ pass def hook_before_interpret(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyFile` constructor after - loading the :py:attr:`~uproot4.reading.ReadOnlyFile.begin_chunk` and before + Called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor after + loading the :py:attr:`~uproot.reading.ReadOnlyFile.begin_chunk` and before interpreting its ``TFile`` header. """ pass def hook_after_interpret(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyFile` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor after interpreting the ``TFile`` header and before raising an error if the first four bytes are not ``b"root"``. - This is the last hook called in the :py:class:`~uproot4.reading.ReadOnlyFile` + This is the last hook called in the :py:class:`~uproot.reading.ReadOnlyFile` constructor. """ pass def hook_before_read_streamer_key(self, **kwargs): """ - Called in :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` before reading + Called in :py:attr:`~uproot.reading.ReadOnlyFile.streamers` before reading the ``TKey`` associated with the ``TStreamerInfo``. This is the first hook called in - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. """ pass def hook_before_read_decompress_streamers(self, **kwargs): """ - Called in :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` after reading + Called in :py:attr:`~uproot.reading.ReadOnlyFile.streamers` after reading the ``TKey`` associated with the ``TStreamerInfo`` and before reading and decompressing the ``TStreamerInfo`` data. """ @@ -1219,7 +1211,7 @@ def hook_before_read_decompress_streamers(self, **kwargs): def hook_before_interpret_streamers(self, **kwargs): """ - Called in :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` after reading + Called in :py:attr:`~uproot.reading.ReadOnlyFile.streamers` after reading and decompressing the ``TStreamerInfo`` data, but before interpreting it. """ @@ -1227,11 +1219,11 @@ def hook_before_interpret_streamers(self, **kwargs): def hook_after_interpret_streamers(self, **kwargs): """ - Called in :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` after + Called in :py:attr:`~uproot.reading.ReadOnlyFile.streamers` after interpreting the ``TStreamerInfo`` data. This is the last hook called in - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. """ pass @@ -1246,22 +1238,22 @@ class ReadOnlyDirectory(Mapping): Args: path (tuple of str): Object path of the ``TDirectory`` as a tuple of nested ``TDirectory`` names. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in - the :py:class:`~uproot4.reading.ReadOnlyFile`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in + the :py:class:`~uproot.reading.ReadOnlyFile`. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): The open file object. + file (:py:class:`~uproot.reading.ReadOnlyFile`): The open file object. parent (None or calling object): The previous ``read`` in the recursive descent. Represents a ``TDirectory`` from a ROOT file, most notably, the root - directory (:py:attr:`~uproot4.reading.ReadOnlyFile.root_directory`). + directory (:py:attr:`~uproot.reading.ReadOnlyFile.root_directory`). - Be careful not to confuse :py:class:`~uproot4.reading.ReadOnlyFile` and - :py:class:`~uproot4.reading.ReadOnlyDirectory`: files are for accessing global - information such as :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and + Be careful not to confuse :py:class:`~uproot.reading.ReadOnlyFile` and + :py:class:`~uproot.reading.ReadOnlyDirectory`: files are for accessing global + information such as :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and directories are for data in local hierarchies. - A :py:class:`~uproot4.reading.ReadOnlyDirectory` is a Python ``Mapping``, which + A :py:class:`~uproot.reading.ReadOnlyDirectory` is a Python ``Mapping``, which uses square bracket syntax to extract objects: .. code-block:: python @@ -1291,20 +1283,20 @@ class ReadOnlyDirectory(Mapping): my_directory["/directory/another_tree/branch_in_tree"] # absolute my_directory["/directory////another_tree/branch_in_tree"] # extra /// - As a Python ``Mapping``, :py:class:`~uproot4.reading.ReadOnlyDirectory` also has + As a Python ``Mapping``, :py:class:`~uproot.reading.ReadOnlyDirectory` also has - * :py:meth:`~uproot4.reading.ReadOnlyDirectory.keys`: names of objects in the + * :py:meth:`~uproot.reading.ReadOnlyDirectory.keys`: names of objects in the ``TDirectory`` - * :py:meth:`~uproot4.reading.ReadOnlyDirectory.values`: objects in the + * :py:meth:`~uproot.reading.ReadOnlyDirectory.values`: objects in the ``TDirectory`` - * :py:meth:`~uproot4.reading.ReadOnlyDirectory.items`: 2-tuple (name, object) + * :py:meth:`~uproot.reading.ReadOnlyDirectory.items`: 2-tuple (name, object) pairs. - However, the :py:class:`~uproot4.reading.ReadOnlyDirectory` versions of these + However, the :py:class:`~uproot.reading.ReadOnlyDirectory` versions of these methods have extra parameters for navigating a complex ROOT file. In addition, there is a - * :py:attr:`~uproot4.reading.ReadOnlyDirectory.classnames`: returns a dict of + * :py:attr:`~uproot.reading.ReadOnlyDirectory.classnames`: returns a dict of (name, classname) pairs. with the same parameters. @@ -1360,7 +1352,7 @@ def __init__(self, path, cursor, context, file, parent): else: keys_start = self._fSeekKeys keys_stop = min(keys_start + self._fNbytesKeys + 8, file.fEND) - keys_cursor = uproot4.source.cursor.Cursor(self._fSeekKeys) + keys_cursor = uproot.source.cursor.Cursor(self._fSeekKeys) self.hook_before_read_keys( chunk=chunk, cursor=cursor, keys_cursor=keys_cursor @@ -1394,7 +1386,7 @@ def __init__(self, path, cursor, context, file, parent): ) self._keys = [] - for i in uproot4._util.range(num_keys): + for i in uproot._util.range(num_keys): key = ReadOnlyKey( keys_chunk, keys_cursor, {}, file, self, read_strings=True ) @@ -1419,7 +1411,7 @@ def path(self): Object path of the ``TDirectory`` as a tuple of nested ``TDirectory`` names. The root directory is an empty tuple, ``()``. - See :py:attr:`~uproot4.reading.ReadOnlyDirectory.object_path` for the path + See :py:attr:`~uproot.reading.ReadOnlyDirectory.object_path` for the path as a string. """ return self._path @@ -1430,7 +1422,7 @@ def object_path(self): Object path of the ``TDirectory`` as a single string, beginning and ending with ``/``. The root directory is a single slash, ``"/"``. - See :py:attr:`~uproot4.reading.ReadOnlyDirectory.path` for the path as a + See :py:attr:`~uproot.reading.ReadOnlyDirectory.path` for the path as a tuple of strings. """ return "/".join(("",) + self._path + ("",)).replace("//", "/") @@ -1438,21 +1430,21 @@ def object_path(self): @property def file(self): """ - The :py:class:`~uproot4.reading.ReadOnlyFile` in which this ``TDirectory`` + The :py:class:`~uproot.reading.ReadOnlyFile` in which this ``TDirectory`` resides. This property is useful for getting global information, in idioms like .. code-block:: python - with uproot4.open("/path/to/file.root") as handle: + with uproot.open("/path/to/file.root") as handle: handle.file.show_streamers() """ return self._file def close(self): """ - Close the :py:class:`~uproot4.reading.ReadOnlyFile` in which this ``TDirectory`` + Close the :py:class:`~uproot.reading.ReadOnlyFile` in which this ``TDirectory`` resides. """ self._file.close() @@ -1460,7 +1452,7 @@ def close(self): @property def closed(self): """ - True if the :py:attr:`~uproot4.reading.ReadOnlyDirectory.file` is closed; + True if the :py:attr:`~uproot.reading.ReadOnlyDirectory.file` is closed; False otherwise. """ return self._file.closed @@ -1475,7 +1467,7 @@ def __exit__(self, exception_type, exception_value, traceback): @property def cursor(self): """ - A :py:class:`~uproot4.source.cursor.Cursor` pointing to the seek point in the + A :py:class:`~uproot.source.cursor.Cursor` pointing to the seek point in the file where this ``TDirectory`` is defined (at the start of the ``TDirectory`` header). """ @@ -1495,11 +1487,11 @@ def is_64bit(self): True if the ``TDirectory`` is 64-bit ready; False otherwise. This refers to seek points like - :py:attr:`~uproot4.reading.ReadOnlyDirectory.fSeekDir` being 64-bit integers, + :py:attr:`~uproot.reading.ReadOnlyDirectory.fSeekDir` being 64-bit integers, rather than 32-bit. Note that a file being 64-bit is distinct from a ``TDirectory`` being - 64-bit; see :py:attr:`~uproot4.reading.ReadOnlyFile.is_64bit`. + 64-bit; see :py:attr:`~uproot.reading.ReadOnlyFile.is_64bit`. """ return self._fVersion > 1000 @@ -1557,7 +1549,7 @@ def values( filter to select keys by C++ (decoded) classname. Returns objects in this ``TDirectory`` as a list of - :py:class:`~uproot4.model.Model`. + :py:class:`~uproot.model.Model`. Note that this reads all objects that are selected by ``filter_name`` and ``filter_classname``. @@ -1589,7 +1581,7 @@ def items( filter to select keys by C++ (decoded) classname. Returns (name, object) pairs for objects in this ``TDirectory`` as a - list of 2-tuples of (str, :py:class:`~uproot4.model.Model`). + list of 2-tuples of (str, :py:class:`~uproot.model.Model`). Note that this reads all objects that are selected by ``filter_name`` and ``filter_classname``. @@ -1658,8 +1650,8 @@ def iterkeys( Note that this does not read any data from the file. """ - filter_name = uproot4._util.regularize_filter(filter_name) - filter_classname = uproot4._util.regularize_filter(filter_classname) + filter_name = uproot._util.regularize_filter(filter_name) + filter_classname = uproot._util.regularize_filter(filter_classname) for key in self._keys: if (filter_name is no_filter or filter_name(key.fName)) and ( filter_classname is no_filter or filter_classname(key.fClassName) @@ -1692,7 +1684,7 @@ def itervalues( filter to select keys by C++ (decoded) classname. Returns objects in this ``TDirectory`` as an iterator over - :py:class:`~uproot4.model.Model`. + :py:class:`~uproot.model.Model`. Note that this reads all objects that are selected by ``filter_name`` and ``filter_classname``. @@ -1724,13 +1716,13 @@ def iteritems( filter to select keys by C++ (decoded) classname. Returns (name, object) pairs for objects in this ``TDirectory`` as an - iterator over 2-tuples of (str, :py:class:`~uproot4.model.Model`). + iterator over 2-tuples of (str, :py:class:`~uproot.model.Model`). Note that this reads all objects that are selected by ``filter_name`` and ``filter_classname``. """ - filter_name = uproot4._util.regularize_filter(filter_name) - filter_classname = uproot4._util.regularize_filter(filter_classname) + filter_name = uproot._util.regularize_filter(filter_name) + filter_classname = uproot._util.regularize_filter(filter_classname) for key in self._keys: if (filter_name is no_filter or filter_name(key.fName)) and ( filter_classname is no_filter or filter_classname(key.fClassName) @@ -1772,8 +1764,8 @@ def iterclassnames( Note that this does not read any data from the file. """ - filter_name = uproot4._util.regularize_filter(filter_name) - filter_classname = uproot4._util.regularize_filter(filter_classname) + filter_name = uproot._util.regularize_filter(filter_name) + filter_classname = uproot._util.regularize_filter(filter_classname) for key in self._keys: if (filter_name is no_filter or filter_name(key.fName)) and ( filter_classname is no_filter or filter_classname(key.fClassName) @@ -1837,9 +1829,9 @@ def classname_of(self, where, encoded=False, version=None): def class_of(self, where, version=None): """ Returns a class object for the ROOT object selected by ``where``. If - ``version`` is specified, get a :py:class:`~uproot4.model.VersionedModel`; - otherwise, get a :py:class:`~uproot4.model.DispatchByVersion` or a versionless - :py:class:`~uproot4.model.Model`. + ``version`` is specified, get a :py:class:`~uproot.model.VersionedModel`; + otherwise, get a :py:class:`~uproot.model.DispatchByVersion` or a versionless + :py:class:`~uproot.model.Model`. The syntax for ``where`` is the same as in square brakets, namely that cycle numbers can be specified after semicolons (``;``) and nested @@ -1855,7 +1847,7 @@ def class_of(self, where, version=None): def streamer_of(self, where, version): """ - Returns a ``TStreamerInfo`` (:py:class:`~uproot4.streamers.Model_TStreamerInfo`) + Returns a ``TStreamerInfo`` (:py:class:`~uproot.streamers.Model_TStreamerInfo`) for the object selected by ``where`` and ``version``. The syntax for ``where`` is the same as in square brakets, namely that @@ -1872,7 +1864,7 @@ def streamer_of(self, where, version): def key(self, where): """ - Returns a ``TKey`` (:py:class:`~uproot4.reading.ReadOnlyKey`) for the object + Returns a ``TKey`` (:py:class:`~uproot.reading.ReadOnlyKey`) for the object selected by ``where``. The syntax for ``where`` is the same as in square brakets, namely that @@ -1884,7 +1876,7 @@ def key(self, where): Note that this does not read any data from the file. """ - where = uproot4._util.ensure_str(where) + where = uproot._util.ensure_str(where) if "/" in where: items = where.split("/") @@ -1895,7 +1887,7 @@ def key(self, where): last = step step = step[item] else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( where, because=repr(item) + " is not a TDirectory", keys=[key.fName for key in last._keys], @@ -1926,11 +1918,11 @@ def key(self, where): if last is not None: return last elif cycle is None: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( item, cycle="any", keys=self.keys(), file_path=self._file.file_path ) else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( item, cycle=cycle, keys=self.keys(), file_path=self._file.file_path ) @@ -1947,10 +1939,10 @@ def __getitem__(self, where): head, tail = item[:index], item[index + 1 :] last = step step = step[head] - if isinstance(step, uproot4.behaviors.TBranch.HasBranches): + if isinstance(step, uproot.behaviors.TBranch.HasBranches): return step["/".join([tail] + items[i + 1 :])] else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( where, because=repr(head) + " is not a TDirectory, TTree, or TBranch", @@ -1961,11 +1953,11 @@ def __getitem__(self, where): last = step step = step[item] - elif isinstance(step, uproot4.behaviors.TBranch.HasBranches): + elif isinstance(step, uproot.behaviors.TBranch.HasBranches): return step["/".join(items[i:])] else: - raise uproot4.KeyInFileError( + raise uproot.KeyInFileError( where, because=repr(item) + " is not a TDirectory, TTree, or TBranch", @@ -2042,24 +2034,24 @@ def fSeekKeys(self): def hook_before_read(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor before + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor before reading the ``TDirectory`` header fields. This is the first hook called in the - :py:class:`~uproot4.reading.ReadOnlyDirecotry` constructor. + :py:class:`~uproot.reading.ReadOnlyDirecotry` constructor. """ pass def hook_before_interpret(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor after reading the ``TDirectory`` header fields and before interpreting them. """ pass def hook_before_read_keys(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor after interpreting the ``TDirectory`` header fields and before reading the chunk of ``TKeys``. """ @@ -2067,14 +2059,14 @@ def hook_before_read_keys(self, **kwargs): def hook_before_header_key(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor after reading the chunk of ``TKeys`` and before interpreting the header ``TKey``. """ pass def hook_before_keys(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor after interpreting the header ``TKey`` and number of keys, and before interpeting the object ``TKeys``. """ @@ -2082,11 +2074,11 @@ def hook_before_keys(self, **kwargs): def hook_after_keys(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyDirectory` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyDirectory` constructor after interpeting the object ``TKeys``. This is the last hook called in the - :py:class:`~uproot4.reading.ReadOnlyDirecotry` constructor. + :py:class:`~uproot.reading.ReadOnlyDirecotry` constructor. """ pass @@ -2098,12 +2090,12 @@ def hook_after_keys(self, **kwargs): class ReadOnlyKey(object): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): Current position in - the :py:class:`~uproot4.reading.ReadOnlyFile`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. + cursor (:py:class:`~uproot.source.cursor.Cursor`): Current position in + the :py:class:`~uproot.reading.ReadOnlyFile`. context (dict): Auxiliary data used in deserialization. - file (:py:class:`~uproot4.reading.ReadOnlyFile`): The open file object. + file (:py:class:`~uproot.reading.ReadOnlyFile`): The open file object. parent (None or calling object): The previous ``read`` in the recursive descent. read_strings (bool): If True, interpret the `fClassName`, `fName`, and @@ -2195,7 +2187,7 @@ def __repr__(self): @property def cursor(self): """ - A :py:class:`~uproot4.source.cursor.Cursor` pointing to the seek point in the + A :py:class:`~uproot.source.cursor.Cursor` pointing to the seek point in the file where this ``TKey`` starts (before its header fields). """ return self._cursor @@ -2203,16 +2195,16 @@ def cursor(self): @property def data_cursor(self): """ - A :py:class:`~uproot4.source.cursor.Cursor` pointing to the seek point in the + A :py:class:`~uproot.source.cursor.Cursor` pointing to the seek point in the file where the data begins (the object to be read, after its copy of the ``TKey`` and before the object's number of bytes/version header). """ - return uproot4.source.cursor.Cursor(self._fSeekKey + self._fKeylen) + return uproot.source.cursor.Cursor(self._fSeekKey + self._fKeylen) @property def file(self): """ - The :py:class:`~uproot4.reading.ReadOnlyFile` in which this ``TKey`` resides. + The :py:class:`~uproot.reading.ReadOnlyFile` in which this ``TKey`` resides. """ return self._file @@ -2244,7 +2236,7 @@ def classname(self, encoded=False, version=None): If ``encoded`` is False, the classname is a C++ (decoded) classname. """ if encoded: - return uproot4.model.classname_encode(self.fClassName, version=version) + return uproot.model.classname_encode(self.fClassName, version=version) else: return self.fClassName @@ -2277,7 +2269,7 @@ def is_64bit(self): True if the ``TKey`` is 64-bit ready; False otherwise. This refers to seek points like - :py:attr:`~uproot4.reading.ReadOnlyKey.fSeekKey` being 64-bit integers, + :py:attr:`~uproot.reading.ReadOnlyKey.fSeekKey` being 64-bit integers, rather than 32-bit. """ return self._fVersion > 1000 @@ -2297,7 +2289,7 @@ def data_uncompressed_bytes(self): """ Number of bytes in the uncompressed object (excluding any keys) - This is equal to :py:attr:`~uproot4.reading.ReadOnlyKey.fObjlen``. + This is equal to :py:attr:`~uproot.reading.ReadOnlyKey.fObjlen``. """ return self._fObjlen @@ -2306,8 +2298,8 @@ def data_compressed_bytes(self): """ Number of bytes in the compressed object (excluding any keys) - This is equal to :py:attr:`~uproot4.reading.ReadOnlyKey.fNbytes`` - minus :py:attr:`~uproot4.reading.ReadOnlyKey.fKeylen``. + This is equal to :py:attr:`~uproot.reading.ReadOnlyKey.fNbytes`` + minus :py:attr:`~uproot.reading.ReadOnlyKey.fKeylen``. """ return self._fNbytes - self._fKeylen @@ -2317,11 +2309,11 @@ def get(self): necessary. If the first attempt to deserialize the object fails with - :py:exc:`~uproot4.deserialization.DeserializationError` and any of the + :py:exc:`~uproot.deserialization.DeserializationError` and any of the models used in that attempt were predefined (not from - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`), this method will + :py:attr:`~uproot.reading.ReadOnlyFile.streamers`), this method will try again with the file's own - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers`. + :py:attr:`~uproot.reading.ReadOnlyFile.streamers`. (Some ROOT files do have classes that don't match the standard ``TStreamerInfo``; they may have been produced from private builds of @@ -2363,12 +2355,12 @@ def get(self): try: out = cls.read(chunk, cursor, context, self._file, selffile, parent) - except uproot4.deserialization.DeserializationError: + except uproot.deserialization.DeserializationError: breadcrumbs = context.get("breadcrumbs") if breadcrumbs is None or all( - breadcrumb_cls.classname in uproot4.model.bootstrap_classnames - or isinstance(breadcrumb_cls, uproot4.containers.AsContainer) + breadcrumb_cls.classname in uproot.model.bootstrap_classnames + or isinstance(breadcrumb_cls, uproot.containers.AsContainer) or getattr(breadcrumb_cls.class_streamer, "file_uuid", None) == self._file.uuid for breadcrumb_cls in breadcrumbs @@ -2379,7 +2371,7 @@ def get(self): for breadcrumb_cls in breadcrumbs: if ( breadcrumb_cls.classname - not in uproot4.model.bootstrap_classnames + not in uproot.model.bootstrap_classnames ): self._file.remove_class_definition(breadcrumb_cls.classname) @@ -2399,18 +2391,18 @@ def get(self): def get_uncompressed_chunk_cursor(self): """ - Returns an uncompressed :py:class:`~uproot4.source.chunk.Chunk` and - :py:class:`~uproot4.source.cursor.Cursor` for the object pointed to by this + Returns an uncompressed :py:class:`~uproot.source.chunk.Chunk` and + :py:class:`~uproot.source.cursor.Cursor` for the object pointed to by this ``TKey`` as a 2-tuple. """ - cursor = uproot4.source.cursor.Cursor(0, origin=-self._fKeylen) + cursor = uproot.source.cursor.Cursor(0, origin=-self._fKeylen) data_start = self.data_cursor.index data_stop = data_start + self.data_compressed_bytes chunk = self._file.chunk(data_start, data_stop) if self.is_compressed: - uncompressed_chunk = uproot4.compression.decompress( + uncompressed_chunk = uproot.compression.decompress( chunk, self.data_cursor, {}, @@ -2418,7 +2410,7 @@ def get_uncompressed_chunk_cursor(self): self.data_uncompressed_bytes, ) else: - uncompressed_chunk = uproot4.source.chunk.Chunk.wrap( + uncompressed_chunk = uproot.source.chunk.Chunk.wrap( chunk.source, chunk.get( data_start, @@ -2496,7 +2488,7 @@ def fSeekPdir(self): def fClassName(self): """ The C++ (decoded) classname of the object or None if the - :py:class:`~uproot4.reading.ReadOnlyKey` was constructed with + :py:class:`~uproot.reading.ReadOnlyKey` was constructed with ``read_strings=False``. """ return self._fClassName @@ -2504,7 +2496,7 @@ def fClassName(self): @property def fName(self): """ - The name of the object or None if the :py:class:`~uproot4.reading.ReadOnlyKey` + The name of the object or None if the :py:class:`~uproot.reading.ReadOnlyKey` was constructed with ``read_strings=False``. """ return self._fName @@ -2512,28 +2504,28 @@ def fName(self): @property def fTitle(self): """ - The title of the object or None if the :py:class:`~uproot4.reading.ReadOnlyKey` + The title of the object or None if the :py:class:`~uproot.reading.ReadOnlyKey` was constructed with ``read_strings=False``. """ return self._fTitle def hook_before_interpret(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyKey` constructor before + Called in the :py:class:`~uproot.reading.ReadOnlyKey` constructor before interpeting anything. This is the first hook called in the - :py:class:`~uproot4.reading.ReadOnlyKey` constructor. + :py:class:`~uproot.reading.ReadOnlyKey` constructor. """ pass def hook_before_strings(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyKey` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyKey` constructor after interpeting the header and before interpreting - :py:attr:`~uproot4.reading.ReadOnlyKey.fClassName`, - :py:attr:`~uproot4.reading.ReadOnlyKey.fName`, and - :py:attr:`~uproot4.reading.ReadOnlyKey.fTitle`. + :py:attr:`~uproot.reading.ReadOnlyKey.fClassName`, + :py:attr:`~uproot.reading.ReadOnlyKey.fName`, and + :py:attr:`~uproot.reading.ReadOnlyKey.fTitle`. Only called if ``read_strings=True`` is passed to the constructor. """ @@ -2541,10 +2533,10 @@ def hook_before_strings(self, **kwargs): def hook_after_interpret(self, **kwargs): """ - Called in the :py:class:`~uproot4.reading.ReadOnlyKey` constructor after + Called in the :py:class:`~uproot.reading.ReadOnlyKey` constructor after interpeting everything. This is the last hook called in the - :py:class:`~uproot4.reading.ReadOnlyKey` constructor. + :py:class:`~uproot.reading.ReadOnlyKey` constructor. """ pass diff --git a/uproot4/source/__init__.py b/uproot/source/__init__.py similarity index 75% rename from uproot4/source/__init__.py rename to uproot/source/__init__.py index e9c1049e7..0420564a0 100644 --- a/uproot4/source/__init__.py +++ b/uproot/source/__init__.py @@ -6,14 +6,14 @@ is distinguished from "interpretation" in that the meaning of the bytes that have been read are not relevant in this layer. The "interpretation layer" interacts with the "physical layer" by requesting a -:py:class:`~uproot4.source.chunk.Chunk` from a :py:class:`~uproot4.source.chunk.Source` and -inspecting it with a :py:class:`~uproot4.source.cursor.Cursor`. +:py:class:`~uproot.source.chunk.Chunk` from a :py:class:`~uproot.source.chunk.Source` and +inspecting it with a :py:class:`~uproot.source.cursor.Cursor`. Any threads used for parallel reading are launched and shut down with the file handle or handles themselves. Context management (Python's ``with`` statement) controls both I/O resources and threads. -This module includes a :py:mod:`uproot4.source.futures` implementation that +This module includes a :py:mod:`uproot.source.futures` implementation that connects file handles with threads. """ diff --git a/uproot4/source/chunk.py b/uproot/source/chunk.py similarity index 74% rename from uproot4/source/chunk.py rename to uproot/source/chunk.py index a40d779f5..5c9020ab1 100644 --- a/uproot4/source/chunk.py +++ b/uproot/source/chunk.py @@ -1,22 +1,20 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines a :py:class:`~uproot4.source.chunk.Chunk`, which is a range of bytes +Defines a :py:class:`~uproot.source.chunk.Chunk`, which is a range of bytes requested from a file. All interaction between the "physical layer" and the -"interpretation layer" is through a :py:class:`~uproot4.source.cursor.Cursor`'s -interpretation of a :py:class:`~uproot4.source.chunk.Chunk`. +"interpretation layer" is through a :py:class:`~uproot.source.cursor.Cursor`'s +interpretation of a :py:class:`~uproot.source.chunk.Chunk`. -Also defines abstract classes for :py:class:`~uproot4.source.chunk.Resource` and -:py:class:`~uproot4.source.chunk.Source`, the primary types of the "physical layer." +Also defines abstract classes for :py:class:`~uproot.source.chunk.Resource` and +:py:class:`~uproot.source.chunk.Source`, the primary types of the "physical layer." """ from __future__ import absolute_import import numpy -import uproot4.deserialization -import uproot4.source.futures -import uproot4.source.cursor +import uproot class Resource(object): @@ -24,9 +22,9 @@ class Resource(object): Abstract class for a file handle whose lifetime may be linked to threads in a thread pool executor. - A :py:class:`~uproot4.source.chunk.Resource` instance is always the first + A :py:class:`~uproot.source.chunk.Resource` instance is always the first argument of functions evaluated by a - :py:class:`~uproot4.source.future.ResourceFuture`. + :py:class:`~uproot.source.future.ResourceFuture`. """ def file_path(self): @@ -41,8 +39,8 @@ class Source(object): Abstract class for physically reading and writing data from a file, which might be remote. - In addition to the file handle, a :py:class:`~uproot4.source.chunk.Source` might - manage a :py:class:`~uproot4.source.future.ResourceThreadPoolExecutor` to read + In addition to the file handle, a :py:class:`~uproot.source.chunk.Source` might + manage a :py:class:`~uproot.source.future.ResourceThreadPoolExecutor` to read the file in parallel. Stopping these threads is part of the act of closing the file. """ @@ -55,7 +53,7 @@ def chunk(self, start, stop): (one greater than the last byte to include). Request a byte range of data from the file as a - :py:class:`~uproot4.source.chunk.Chunk`. + :py:class:`~uproot.source.chunk.Chunk`. """ pass @@ -74,10 +72,10 @@ def chunks(self, ranges, notifications): This method has two outputs: * The method returns a list of unfilled - :py:class:`~uproot4.source.chunk.Chunk` objects, which get filled + :py:class:`~uproot.source.chunk.Chunk` objects, which get filled in a background thread. If you try to read data from an unfilled chunk, it will wait until it is filled. - * The method also puts the same :py:class:`~uproot4.source.chunk.Chunk` + * The method also puts the same :py:class:`~uproot.source.chunk.Chunk` objects onto the ``notifications`` queue as soon as they are filled. @@ -113,7 +111,7 @@ def num_requests(self): @property def num_requested_chunks(self): """ - The number of :py:class:`~uproot4.source.chunk.Chunk` objects that have been + The number of :py:class:`~uproot.source.chunk.Chunk` objects that have been requested (performance counter). """ return self._num_requested_chunks @@ -142,8 +140,8 @@ def closed(self): class MultithreadedSource(Source): """ - Abstract class for a :py:class:`~uproot4.source.chunk.Source` that maintains a - :py:class:`~uproot4.source.future.ResourceThreadPoolExecutor`. + Abstract class for a :py:class:`~uproot.source.chunk.Source` that maintains a + :py:class:`~uproot.source.future.ResourceThreadPoolExecutor`. """ def __repr__(self): @@ -181,22 +179,22 @@ def chunks(self, ranges, notifications): @property def executor(self): """ - The :py:class:`~uproot4.source.future.ResourceThreadPoolExecutor` + The :py:class:`~uproot.source.future.ResourceThreadPoolExecutor` """ return self._executor @property def num_workers(self): """ - The number of :py:class:`~uproot4.source.future.ResourceWorker` threads in - the :py:class:`~uproot4.source.future.ResourceThreadPoolExecutor`. + The number of :py:class:`~uproot.source.future.ResourceWorker` threads in + the :py:class:`~uproot.source.future.ResourceThreadPoolExecutor`. """ return self._executor.num_workers @property def closed(self): """ - True if the :py:class:`~uproot4.source.future.ResourceThreadPoolExecutor` has + True if the :py:class:`~uproot.source.future.ResourceThreadPoolExecutor` has been shut down and the file handles have been closed. """ return self._executor.closed @@ -219,29 +217,29 @@ def notify(): class Chunk(object): """ Args: - source (:py:class:`~uproot4.source.chunk.Source`): Source from which the + source (:py:class:`~uproot.source.chunk.Source`): Source from which the data were derived. start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - future (:py:class:`~uproot4.source.futures.TrivialFuture` or :py:class:`~uproot4.source.futures.Future`): Handle + future (:py:class:`~uproot.source.futures.TrivialFuture` or :py:class:`~uproot.source.futures.Future`): Handle to the synchronous or asynchronous data. A chunk is "filled" when the ``future`` completes. - A range of bytes from a :py:class:`~uproot4.source.chunk.Source`, which may be + A range of bytes from a :py:class:`~uproot.source.chunk.Source`, which may be synchronously or asynchronously filled. The following methods must wait for the - :py:attr:`~uproot4.source.chunk.Chunk.future` to complete (to be filled): + :py:attr:`~uproot.source.chunk.Chunk.future` to complete (to be filled): - * :py:meth:`~uproot4.source.chunk.Chunk.wait`: Waits and nothing else. - * :py:attr:`~uproot4.source.chunk.Chunk.raw_data`: The data as a + * :py:meth:`~uproot.source.chunk.Chunk.wait`: Waits and nothing else. + * :py:attr:`~uproot.source.chunk.Chunk.raw_data`: The data as a ``numpy.ndarray`` of ``numpy.uint8``. - * :py:meth:`~uproot4.source.chunk.Chunk.get`: A subinterval of the data as + * :py:meth:`~uproot.source.chunk.Chunk.get`: A subinterval of the data as a ``numpy.ndarray`` of ``numpy.uint8``. - * :py:meth:`~uproot4.source.chunk.Chunk.remainder`: A subinterval from the - :py:class:`~uproot4.source.cursor.Cursor` to the end of the - :py:class:`~uproot4.source.chunk.Chunk`. + * :py:meth:`~uproot.source.chunk.Chunk.remainder`: A subinterval from the + :py:class:`~uproot.source.cursor.Cursor` to the end of the + :py:class:`~uproot.source.chunk.Chunk`. """ _dtype = numpy.dtype(numpy.uint8) @@ -250,13 +248,13 @@ class Chunk(object): def wrap(cls, source, data): """ Args: - source (:py:class:`~uproot4.source.chunk.Source`): Source to attach to + source (:py:class:`~uproot.source.chunk.Source`): Source to attach to the new chunk. data (``numpy.ndarray`` of ``numpy.uint8``): Data for the new chunk. - Manually creates a synchronous :py:class:`~uproot4.source.chunk.Chunk`. + Manually creates a synchronous :py:class:`~uproot.source.chunk.Chunk`. """ - future = uproot4.source.futures.TrivialFuture(data) + future = uproot.source.futures.TrivialFuture(data) return Chunk(source, 0, len(data), future) def __init__(self, source, start, stop, future): @@ -301,16 +299,16 @@ def future(self): def __contains__(self, range): start, stop = range - if isinstance(start, uproot4.source.cursor.Cursor): + if isinstance(start, uproot.source.cursor.Cursor): start = start.index - if isinstance(stop, uproot4.source.cursor.Cursor): + if isinstance(stop, uproot.source.cursor.Cursor): stop = stop.index return self._start <= start and stop <= self._stop def wait(self): """ Explicitly wait until the chunk is filled (the - :py:attr:`~uproot4.source.chunk.Chunk.future` completes). + :py:attr:`~uproot.source.chunk.Chunk.future` completes). """ if self._raw_data is None: self._raw_data = numpy.frombuffer(self._future.result(), dtype=self._dtype) @@ -331,7 +329,7 @@ def raw_data(self): Data from the Source as a ``numpy.ndarray`` of ``numpy.uint8``. This method will wait until the chunk is filled (the - :py:attr:`~uproot4.source.chunk.Chunk.future` completes), if it isn't + :py:attr:`~uproot.source.chunk.Chunk.future` completes), if it isn't already. """ self.wait() @@ -343,20 +341,20 @@ def get(self, start, stop, cursor, context): start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - cursor (:py:class:`~uproot4.source.cursor.Cursor`): A pointer to the + cursor (:py:class:`~uproot.source.cursor.Cursor`): A pointer to the current position in this chunk. context (dict): Auxiliary data used in deserialization. - Returns a subinterval of the :py:attr:`~uproot4.source.chunk.Chunk.raw_data` + Returns a subinterval of the :py:attr:`~uproot.source.chunk.Chunk.raw_data` as a ``numpy.ndarray`` of ``numpy.uint8``. Note that this ``start`` and ``stop`` are in the same coordinate - system as the :py:attr:`~uproot4.source.chunk.Chunk.start` and - :py:attr:`~uproot4.source.chunk.Chunk.stop`. That is, to get the whole + system as the :py:attr:`~uproot.source.chunk.Chunk.start` and + :py:attr:`~uproot.source.chunk.Chunk.stop`. That is, to get the whole chunk, use ``start=chunk.start`` and ``stop=chunk.stop``. This method will wait until the chunk is filled (the - :py:attr:`~uproot4.source.chunk.Chunk.future` completes), if it isn't + :py:attr:`~uproot.source.chunk.Chunk.future` completes), if it isn't already. """ self.wait() @@ -367,7 +365,7 @@ def get(self, start, stop, cursor, context): return self._raw_data[local_start:local_stop] else: - raise uproot4.deserialization.DeserializationError( + raise uproot.deserialization.DeserializationError( """attempting to get bytes {0}:{1} outside expected range {2}:{3} for this Chunk""".format( start, stop, self._start, self._stop @@ -382,20 +380,20 @@ def remainder(self, start, cursor, context): """ Args: start (int): Seek position of the first byte to include. - cursor (:py:class:`~uproot4.source.cursor.Cursor`): A pointer to the + cursor (:py:class:`~uproot.source.cursor.Cursor`): A pointer to the current position in this chunk. context (dict): Auxiliary data used in deserialization. - Returns a subinterval of the :py:attr:`~uproot4.source.chunk.Chunk.raw_data` + Returns a subinterval of the :py:attr:`~uproot.source.chunk.Chunk.raw_data` as a ``numpy.ndarray`` of ``numpy.uint8`` from ``start`` to the end of the chunk. Note that this ``start`` is in the same coordinate system as the - :py:attr:`~uproot4.source.chunk.Chunk.start`. That is, to get the whole + :py:attr:`~uproot.source.chunk.Chunk.start`. That is, to get the whole chunk, use ``start=chunk.start``. This method will wait until the chunk is filled (the - :py:attr:`~uproot4.source.chunk.Chunk.future` completes), if it isn't + :py:attr:`~uproot.source.chunk.Chunk.future` completes), if it isn't already. """ self.wait() @@ -405,7 +403,7 @@ def remainder(self, start, cursor, context): return self._raw_data[local_start:] else: - raise uproot4.deserialization.DeserializationError( + raise uproot.deserialization.DeserializationError( """attempting to get bytes after {0} outside expected range {1}:{2} for this Chunk""".format( start, self._start, self._stop diff --git a/uproot4/source/cursor.py b/uproot/source/cursor.py similarity index 76% rename from uproot4/source/cursor.py rename to uproot/source/cursor.py index 85ec0b4b2..7e547dab8 100644 --- a/uproot4/source/cursor.py +++ b/uproot/source/cursor.py @@ -1,7 +1,7 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE """ -Defines the :py:class:`~uproot4.source.cursor.Cursor`, which maintains a thread-local +Defines the :py:class:`~uproot.source.cursor.Cursor`, which maintains a thread-local pointer into a :py:class:`~uproot.source.chunk.Chunk` and performs the lowest level of interpretation (numbers, strings, raw arrays, etc.). """ @@ -13,8 +13,7 @@ import numpy -import uproot4 -import uproot4.deserialization +import uproot _printable_characters = ( @@ -29,17 +28,17 @@ class Cursor(object): """ Args: index (int): Global seek position in the ROOT file or local position - in an uncompressed :py:class:`~uproot4.source.chunk.Chunk`. + in an uncompressed :py:class:`~uproot.source.chunk.Chunk`. origin (int): Zero-point for numerical keys in ``refs``. refs (None or dict): References to data already read in - :py:func:`~uproot4.deserialization.read_object_any`. + :py:func:`~uproot.deserialization.read_object_any`. Represents a seek point in a ROOT file, which may be held for later reference or advanced while interpreting data from a - :py:class:`~uproot4.source.chunk.Chunk`. + :py:class:`~uproot.source.chunk.Chunk`. A cursor also holds references to previously read data that might be - requested by :py:func:`~uproot4.deserialization.read_object_any`. + requested by :py:func:`~uproot.deserialization.read_object_any`. """ def __init__(self, index, origin=0, refs=None): @@ -70,7 +69,7 @@ def __repr__(self): def index(self): """ Global seek position in the ROOT file or local position in an - uncompressed :py:class:`~uproot4.source.chunk.Chunk`. + uncompressed :py:class:`~uproot.source.chunk.Chunk`. """ return self._index @@ -78,7 +77,7 @@ def index(self): def origin(self): """ Zero-point for numerical keys in - :py:attr:`~uproot4.source.cursor.Cursor.refs`. + :py:attr:`~uproot.source.cursor.Cursor.refs`. """ return self._origin @@ -86,7 +85,7 @@ def origin(self): def refs(self): """ References to data already read in - :py:func:`~uproot4.deserialization.read_object_any`. + :py:func:`~uproot.deserialization.read_object_any`. """ if self._refs is None: self._refs = {} @@ -94,9 +93,9 @@ def refs(self): def displacement(self, other=None): """ - The number of bytes between this :py:class:`~uproot4.source.cursor.Cursor` - and its :py:attr:`~uproot4.source.cursor.Cursor.origin` (if None) - or the ``other`` :py:class:`~uproot4.source.cursor.Cursor` (if provided). + The number of bytes between this :py:class:`~uproot.source.cursor.Cursor` + and its :py:attr:`~uproot.source.cursor.Cursor.origin` (if None) + or the ``other`` :py:class:`~uproot.source.cursor.Cursor` (if provided). If the displacement is positive, ``self`` is later in the file than the ``origin`` or ``other``; if negative, it is earlier. @@ -108,8 +107,8 @@ def displacement(self, other=None): def copy(self, link_refs=True): """ - Returns a copy of this :py:class:`~uproot4.source.cursor.Cursor`. If - ``link_refs`` is True, any :py:attr:`~uproot4.source.cursor.Cursor.refs` + Returns a copy of this :py:class:`~uproot.source.cursor.Cursor`. If + ``link_refs`` is True, any :py:attr:`~uproot.source.cursor.Cursor.refs` will be *referenced*, rather than *copied*. """ if link_refs or self._refs is None: @@ -119,21 +118,21 @@ def copy(self, link_refs=True): def move_to(self, index): """ - Move the :py:attr:`~uproot4.source.cursor.Cursor.index` to a specified seek + Move the :py:attr:`~uproot.source.cursor.Cursor.index` to a specified seek position. """ self._index = index def skip(self, num_bytes): """ - Move the :py:attr:`~uproot4.source.cursor.Cursor.index` forward + Move the :py:attr:`~uproot.source.cursor.Cursor.index` forward ``num_bytes``. """ self._index += num_bytes def skip_after(self, obj): """ - Move the :py:attr:`~uproot4.source.cursor.Cursor.index` just after an object + Move the :py:attr:`~uproot.source.cursor.Cursor.index` just after an object that has a starting ``obj.cursor`` and an expected ``obj.num_bytes``. """ start_cursor = getattr(obj, "cursor", None) @@ -152,18 +151,18 @@ def skip_after(self, obj): def skip_over(self, chunk, context): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. - Move the :py:attr:`~uproot4.source.cursor.Cursor.index` to a seek position + Move the :py:attr:`~uproot.source.cursor.Cursor.index` to a seek position beyond the serialized data for an object that can be interpreted with - :py:func:`~uproot4.deserialization.numbytes_version`. + :py:func:`~uproot.deserialization.numbytes_version`. Returns True if successful (cursor has moved), False otherwise (cursor has NOT moved). """ - num_bytes, version, is_memberwise = uproot4.deserialization.numbytes_version( + num_bytes, version, is_memberwise = uproot.deserialization.numbytes_version( chunk, self, context, move=False ) if num_bytes is None: @@ -175,16 +174,16 @@ def skip_over(self, chunk, context): def fields(self, chunk, format, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. format (``struct.Struct``): Specification to interpret the bytes of data. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` with a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` with a specified format. Returns a tuple of data whose types and length are determined by the ``format``. """ @@ -197,16 +196,16 @@ def fields(self, chunk, format, context, move=True): def field(self, chunk, format, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. format (``struct.Struct``): Specification to interpret the bytes of data. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` with a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` with a format that only specifies one field, returning a single item instead of a tuple. """ @@ -219,14 +218,14 @@ def field(self, chunk, format, context, move=True): def double32(self, chunk, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as ROOT's ``Double32_t`` type, returning the Python ``float``. """ # https://github.com/root-project/root/blob/e87a6311278f859ca749b491af4e9a2caed39161/io/io/src/TBufferFile.cxx#L448-L464 @@ -239,15 +238,15 @@ def double32(self, chunk, context, move=True): def float16(self, chunk, num_bits, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. num_bits (int): Number of bits in the mantissa. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as ROOT's ``Float16_t`` type, returning the Python ``float``. """ # https://github.com/root-project/root/blob/e87a6311278f859ca749b491af4e9a2caed39161/io/io/src/TBufferFile.cxx#L432-L442 @@ -272,15 +271,15 @@ def float16(self, chunk, num_bits, context, move=True): def bytes(self, chunk, length, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. length (int): Number of bytes to retrieve. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as raw + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as raw bytes with a given ``length``. """ start = self._index @@ -292,16 +291,16 @@ def bytes(self, chunk, length, context, move=True): def array(self, chunk, length, dtype, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. length (int): Number of bytes to retrieve. dtype (``numpy.dtype``): Data type for the array. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a one-dimensional array with a given ``length`` and ``dtype``. """ start = self._index @@ -316,14 +315,14 @@ def array(self, chunk, length, dtype, context, move=True): def bytestring(self, chunk, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a bytestring. The first byte is taken to be the length of the subsequent string unless @@ -351,14 +350,14 @@ def bytestring(self, chunk, context, move=True): def string(self, chunk, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a UTF-8 encoded string. The first byte is taken to be the length of the subsequent string unless @@ -366,7 +365,7 @@ def string(self, chunk, context, move=True): ``numpy.int32`` length. """ out = self.bytestring(chunk, context, move=move) - if uproot4._util.py2: + if uproot._util.py2: return out else: return out.decode(errors="surrogateescape") @@ -374,15 +373,15 @@ def string(self, chunk, context, move=True): def bytestring_with_length(self, chunk, context, length, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. length (int): Number of bytes in the bytestring. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a bytestring. """ start = self._index @@ -398,19 +397,19 @@ def bytestring_with_length(self, chunk, context, length, move=True): def string_with_length(self, chunk, context, length, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. length (int): Number of bytes in the string. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a UTF-8 encoded string. """ out = self.bytestring_with_length(chunk, context, length, move=move) - if uproot4._util.py2: + if uproot._util.py2: return out else: return out.decode(errors="surrogateescape") @@ -418,14 +417,14 @@ def string_with_length(self, chunk, context, length, move=True): def classname(self, chunk, context, move=True): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Buffer of contiguous data - from the file :py:class:`~uproot4.source.chunk.Source`. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Buffer of contiguous data + from the file :py:class:`~uproot.source.chunk.Source`. context (dict): Auxiliary data used in deserialization. move (bool): If True, move the - :py:attr:`~uproot4.source.cursor.Cursor.index` past the fields; + :py:attr:`~uproot.source.cursor.Cursor.index` past the fields; otherwise, leave it where it is. - Interpret data at this :py:attr:`~uproot4.source.cursor.Cursor.index` as a + Interpret data at this :py:attr:`~uproot.source.cursor.Cursor.index` as a null-terminated, UTF-8 encoded string. """ remainder = chunk.remainder(self._index, self, context) @@ -451,7 +450,7 @@ def classname(self, chunk, context, move=True): else: out = out.tostring() - if uproot4._util.py2: + if uproot._util.py2: return out else: return out.decode(errors="surrogateescape") @@ -467,12 +466,12 @@ def debug( ): """ Args: - chunk (:py:class:`~uproot4.source.chunk.Chunk`): Data to examine. + chunk (:py:class:`~uproot.source.chunk.Chunk`): Data to examine. context (dict): Auxiliary data used in deserialization. limit_bytes (None or int): Number of bytes to limit the output to. A line of debugging output (without any ``offset``) is 20 bytes, so multiples of 20 show full lines. If None, everything is - shown to the end of the :py:class:`~uproot4.source.chunk.Chunk`, + shown to the end of the :py:class:`~uproot.source.chunk.Chunk`, which might be large. dtype (None, ``numpy.dtype``, or its constructor argument): If None, present only the bytes as decimal values (0-255). Otherwise, @@ -526,7 +525,7 @@ def debug( formatter = u"{{0:>{0}.{0}s}}".format(dtype.itemsize * 4 - 1) - for line_start in uproot4._util.range( + for line_start in uproot._util.range( 0, int(numpy.ceil(len(data) / 20.0)) * 20, 20 ): line_data = data[line_start : line_start + 20] diff --git a/uproot4/source/file.py b/uproot/source/file.py similarity index 74% rename from uproot4/source/file.py rename to uproot/source/file.py index d96f6eedb..3406bc17e 100644 --- a/uproot4/source/file.py +++ b/uproot/source/file.py @@ -3,13 +3,13 @@ """ Physical layer for local files. -Defines a :py:class:`~uproot4.source.file.FileResource` (wrapped Python file handle) -and two sources: :py:class:`~uproot4.source.file.MultithreadedFileSource` and -:py:class:`~uproot4.source.file.MemmapSource`, which provide thread-safe local +Defines a :py:class:`~uproot.source.file.FileResource` (wrapped Python file handle) +and two sources: :py:class:`~uproot.source.file.MultithreadedFileSource` and +:py:class:`~uproot.source.file.MemmapSource`, which provide thread-safe local file readers using many file handles or a memory-mapped file, respectively. If the filesystem or operating system does not support memory-mapped files, the -:py:class:`~uproot4.source.file.MultithreadedFileSource` is an automatic fallback. +:py:class:`~uproot.source.file.MultithreadedFileSource` is an automatic fallback. """ from __future__ import absolute_import @@ -18,25 +18,25 @@ import numpy -import uproot4.source.futures -import uproot4.source.chunk -import uproot4._util +import uproot +import uproot.source.futures +import uproot.source.chunk -class FileResource(uproot4.source.chunk.Resource): +class FileResource(uproot.source.chunk.Resource): """ Args: file_path (str): The filesystem path of the file to open. - A :py:class:`~uproot4.source.chunk.Resource` for a simple file handle. + A :py:class:`~uproot.source.chunk.Resource` for a simple file handle. """ def __init__(self, file_path): self._file_path = file_path try: self._file = open(self._file_path, "rb") - except uproot4._util._FileNotFoundError: - raise uproot4._util._file_not_found(file_path) + except uproot._util._FileNotFoundError: + raise uproot._util._file_not_found(file_path) @property def file(self): @@ -71,32 +71,32 @@ def get(self, start, stop): def future(source, start, stop): """ Args: - source (:py:class:`~uproot4.source.chunk.MultithreadedFileSource`): The + source (:py:class:`~uproot.source.chunk.MultithreadedFileSource`): The data source. start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` that calls - :py:meth:`~uproot4.source.file.FileResource.get` with ``start`` and ``stop``. + Returns a :py:class:`~uproot.source.futures.ResourceFuture` that calls + :py:meth:`~uproot.source.file.FileResource.get` with ``start`` and ``stop``. """ def task(resource): return resource.get(start, stop) - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) -class MemmapSource(uproot4.source.chunk.Source): +class MemmapSource(uproot.source.chunk.Source): """ Args: file_path (str): The filesystem path of the file to open. options: Must include ``"num_fallback_workers"``. - A :py:class:`~uproot4.source.chunk.Source` that manages one memory-mapped file. + A :py:class:`~uproot.source.chunk.Source` that manages one memory-mapped file. """ - _dtype = uproot4.source.chunk.Chunk._dtype + _dtype = uproot.source.chunk.Chunk._dtype def __init__(self, file_path, **options): num_fallback_workers = options["num_fallback_workers"] @@ -113,7 +113,7 @@ def __init__(self, file_path, **options): self._file = None opts = dict(options) opts["num_workers"] = num_fallback_workers - self._fallback = uproot4.source.file.MultithreadedFileSource( + self._fallback = uproot.source.file.MultithreadedFileSource( file_path, **opts # NOTE: a comma after **opts breaks Python 2 ) @@ -138,8 +138,8 @@ def chunk(self, start, stop): self._num_requested_bytes += stop - start data = numpy.array(self._file[start:stop], copy=True) - future = uproot4.source.futures.TrivialFuture(data) - return uproot4.source.chunk.Chunk(self, start, stop, future) + future = uproot.source.futures.TrivialFuture(data) + return uproot.source.chunk.Chunk(self, start, stop, future) else: return self._fallback.chunk(start, stop) @@ -156,8 +156,8 @@ def chunks(self, ranges, notifications): chunks = [] for start, stop in ranges: data = numpy.array(self._file[start:stop], copy=True) - future = uproot4.source.futures.TrivialFuture(data) - chunk = uproot4.source.chunk.Chunk(self, start, stop, future) + future = uproot.source.futures.TrivialFuture(data) + chunk = uproot.source.chunk.Chunk(self, start, stop, future) notifications.put(chunk) chunks.append(chunk) return chunks @@ -175,10 +175,10 @@ def file(self): @property def fallback(self): """ - If None, the :py:attr:`~uproot4.source.file.MemmapSource.file` opened + If None, the :py:attr:`~uproot.source.file.MemmapSource.file` opened successfully and no fallback is needed. - Otherwise, this is a :py:class:`~uproot4.source.file.MultithreadedFileSource` + Otherwise, this is a :py:class:`~uproot.source.file.MultithreadedFileSource` to which all requests are forwarded. """ return self._fallback @@ -186,7 +186,7 @@ def fallback(self): @property def closed(self): if self._fallback is None: - if uproot4._util.py2: + if uproot._util.py2: try: self._file._mmap.tell() except ValueError: @@ -223,14 +223,14 @@ def num_bytes(self): return self._fallback.num_bytes -class MultithreadedFileSource(uproot4.source.chunk.MultithreadedSource): +class MultithreadedFileSource(uproot.source.chunk.MultithreadedSource): """ Args: file_path (str): The filesystem path of the file to open. options: Must include ``"num_workers"``. - A :py:class:`~uproot4.source.chunk.MultithreadedSource` that manages many - :py:class:`~uproot4.source.file.FileResource` objects. + A :py:class:`~uproot.source.chunk.MultithreadedSource` that manages many + :py:class:`~uproot.source.file.FileResource` objects. """ ResourceClass = FileResource @@ -242,7 +242,7 @@ def __init__(self, file_path, **options): self._num_requested_bytes = 0 self._file_path = file_path - self._executor = uproot4.source.futures.ResourceThreadPoolExecutor( - [FileResource(file_path) for x in uproot4._util.range(num_workers)] + self._executor = uproot.source.futures.ResourceThreadPoolExecutor( + [FileResource(file_path) for x in uproot._util.range(num_workers)] ) self._num_bytes = os.path.getsize(self._file_path) diff --git a/uproot4/source/futures.py b/uproot/source/futures.py similarity index 71% rename from uproot4/source/futures.py rename to uproot/source/futures.py index e7f3ffacc..aae2082be 100644 --- a/uproot4/source/futures.py +++ b/uproot/source/futures.py @@ -3,18 +3,18 @@ """ Defines a Python-like Future and Executor for Uproot in three levels: -1. :py:class:`~uproot4.source.futures.TrivialFuture` and - :py:class:`~uproot4.source.futures.TrivialExecutor`: interface only, all activity +1. :py:class:`~uproot.source.futures.TrivialFuture` and + :py:class:`~uproot.source.futures.TrivialExecutor`: interface only, all activity is synchronous. -2. :py:class:`~uproot4.source.futures.Future`, :py:class:`~uproot4.source.futures.Worker`, - and :py:class:`~uproot4.source.futures.ThreadPoolExecutor`: similar to Python's +2. :py:class:`~uproot.source.futures.Future`, :py:class:`~uproot.source.futures.Worker`, + and :py:class:`~uproot.source.futures.ThreadPoolExecutor`: similar to Python's own Future, Thread, and ThreadPoolExecutor, though only a minimal implementation is provided. These exist to unify behavior between Python 2 and 3 and provide a base class for the following. -3. :py:class:`~uproot4.source.futures.ResourceFuture`, - :py:class:`~uproot4.source.futures.ResourceWorker`, - and :py:class:`~uproot4.source.futures.ResourceThreadPoolExecutor`: like the above - except that a :py:class:`~uproot4.source.chunk.Resource` is associated with every +3. :py:class:`~uproot.source.futures.ResourceFuture`, + :py:class:`~uproot.source.futures.ResourceWorker`, + and :py:class:`~uproot.source.futures.ResourceThreadPoolExecutor`: like the above + except that a :py:class:`~uproot.source.chunk.Resource` is associated with every worker. When the threads are shut down, the resources (i.e. file handles) are released. @@ -28,7 +28,7 @@ import threading import time -import uproot4 +import uproot try: import queue @@ -40,7 +40,7 @@ def delayed_raise(exception_class, exception_value, traceback): """ Raise an exception from a background thread on the main thread. """ - if uproot4._util.py2: + if uproot._util.py2: exec("raise exception_class, exception_value, traceback") else: raise exception_value.with_traceback(traceback) @@ -51,7 +51,7 @@ def delayed_raise(exception_class, exception_value, traceback): class TrivialFuture(object): """ - Formally satisfies the interface for a :py:class:`~uproot4.source.futures.Future` + Formally satisfies the interface for a :py:class:`~uproot.source.futures.Future` object, but it is already complete at the time when it is constructed. """ @@ -68,8 +68,8 @@ def result(self, timeout=None): class TrivialExecutor(object): """ Formally satisfies the interface for a - :py:class:`~uproot4.source.futures.ThreadPoolExecutor`, but the - :py:meth:`~uproot4.source.futures.TrivialExecutor.submit` method computes its + :py:class:`~uproot.source.futures.ThreadPoolExecutor`, but the + :py:meth:`~uproot.source.futures.TrivialExecutor.submit` method computes its ``task`` synchronously. """ @@ -101,7 +101,7 @@ class Future(object): Like Python 3 ``concurrent.futures.Future`` except that it has only the subset of the interface Uproot needs and is available in Python 2. - The :py:class:`~uproot4.source.futures.ResourceFuture` extends this class. + The :py:class:`~uproot.source.futures.ResourceFuture` extends this class. """ def __init__(self, task, args): @@ -137,12 +137,12 @@ class Worker(threading.Thread): """ Args: work_queue (``queue.Queue``): The worker calls ``get`` on this queue - for tasks in the form of :py:class:`~uproot4.source.futures.Future` + for tasks in the form of :py:class:`~uproot.source.futures.Future` objects and runs them. If it ever gets a None value, the thread is stopped. A ``threading.Thread`` for the - :py:class:`~uproot4.source.futures.ThreadPoolExecutor`. + :py:class:`~uproot.source.futures.ThreadPoolExecutor`. """ def __init__(self, work_queue): @@ -154,15 +154,15 @@ def __init__(self, work_queue): def work_queue(self): """ The worker calls ``get`` on this queue for tasks in the form of - :py:class:`~uproot4.source.futures.Future` objects and runs them. If it ever + :py:class:`~uproot.source.futures.Future` objects and runs them. If it ever gets a None value, the thread is stopped. """ return self._work_queue def run(self): """ - Listens to the :py:attr:`~uproot4.source.futures.Worker.work_queue` and - executes each :py:class:`~uproot4.source.futures.Future` it receives until it + Listens to the :py:attr:`~uproot.source.futures.Worker.work_queue` and + executes each :py:class:`~uproot.source.futures.Future` it receives until it receives None. """ future = None @@ -184,7 +184,7 @@ class ThreadPoolExecutor(object): Like Python 3 ``concurrent.futures.ThreadPoolExecutor`` except that it has only the subset of the interface Uproot needs and is available in Python 2. - The :py:class:`~uproot4.source.futures.ResourceThreadPoolExecutor` extends this + The :py:class:`~uproot.source.futures.ResourceThreadPoolExecutor` extends this class. """ @@ -199,7 +199,7 @@ def __init__(self, num_workers=None): self._work_queue = queue.Queue() self._workers = [] - for x in uproot4._util.range(num_workers): + for x in uproot._util.range(num_workers): self._workers.append(Worker(self._work_queue)) for worker in self._workers: worker.start() @@ -219,15 +219,15 @@ def num_workers(self): @property def workers(self): """ - A list of workers (:py:class:`~uproot4.source.futures.Worker`). + A list of workers (:py:class:`~uproot.source.futures.Worker`). """ return self._workers def submit(self, task, *args): """ Pass the ``task`` and ``args`` onto the workers' - :py:attr:`~uproot4.source.futures.Worker.work_queue` as a - :py:class:`~uproot4.source.futures.Future` so that it will be executed when + :py:attr:`~uproot.source.futures.Worker.work_queue` as a + :py:class:`~uproot.source.futures.Future` so that it will be executed when one is available. """ future = Future(task, args) @@ -236,8 +236,8 @@ def submit(self, task, *args): def shutdown(self, wait=True): """ - Stop every :py:class:`~uproot4.source.futures.Worker` by putting None - on the :py:attr:`~uproot4.source.futures.Worker.work_queue` until none of + Stop every :py:class:`~uproot.source.futures.Worker` by putting None + on the :py:attr:`~uproot.source.futures.Worker.work_queue` until none of them satisfy ``worker.is_alive()``. """ while True: @@ -257,11 +257,11 @@ class ResourceFuture(Future): """ Args: task (function): The function to evaluate with a - :py:class:`~uproot4.source.chunk.Resource` as its first argument. + :py:class:`~uproot.source.chunk.Resource` as its first argument. - A :py:class:`~uproot4.source.futures.Future` that uses the - :py:class:`~uproot4.source.chunk.Resource` associated with the - :py:class:`~uproot4.source.futures.ResourceWorker` that runs it. + A :py:class:`~uproot.source.futures.Future` that uses the + :py:class:`~uproot.source.chunk.Resource` associated with the + :py:class:`~uproot.source.futures.ResourceWorker` that runs it. """ def __init__(self, task): @@ -292,14 +292,14 @@ class ResourceWorker(Worker): """ Args: work_queue (``queue.Queue``): The worker calls ``get`` on this queue - for tasks in the form of :py:class:`~uproot4.source.futures.Future` + for tasks in the form of :py:class:`~uproot.source.futures.Future` objects and runs them. If it ever gets a None value, the thread is stopped. - A :py:class:`~uproot4.source.futures.Worker` that is bound to a - :py:class:`~uproot4.source.chunk.Resource`. This - :py:attr:`~uproot4.source.futures.ResourceWorker.resource` is the first argument - passed to each :py:class:`~uproot4.source.futures.ResourceFuture` that it + A :py:class:`~uproot.source.futures.Worker` that is bound to a + :py:class:`~uproot.source.chunk.Resource`. This + :py:attr:`~uproot.source.futures.ResourceWorker.resource` is the first argument + passed to each :py:class:`~uproot.source.futures.ResourceFuture` that it executes. """ @@ -310,15 +310,15 @@ def __init__(self, work_queue, resource): @property def resource(self): """ - The :py:class:`~uproot4.source.chunk.Resource` that is bound to this worker. + The :py:class:`~uproot.source.chunk.Resource` that is bound to this worker. """ return self._resource def run(self): """ - Listens to the :py:attr:`~uproot4.source.futures.ResourceWorker.work_queue` - and executes each :py:class:`~uproot4.source.futures.ResourceFuture` it - receives (with :py:attr:`~uproot4.source.futures.ResourceWorker.resource` as + Listens to the :py:attr:`~uproot.source.futures.ResourceWorker.work_queue` + and executes each :py:class:`~uproot.source.futures.ResourceFuture` it + receives (with :py:attr:`~uproot.source.futures.ResourceWorker.resource` as its first argument) until it receives None. """ future = None @@ -334,10 +334,10 @@ def run(self): class ResourceThreadPoolExecutor(ThreadPoolExecutor): """ Args: - resources (list of :py:class:`~uproot4.source.chunk.Resource`): Resources to - wrap as :py:class:`~uproot4.source.futures.ResourceFuture` objects. + resources (list of :py:class:`~uproot.source.chunk.Resource`): Resources to + wrap as :py:class:`~uproot.source.futures.ResourceFuture` objects. - A :py:class:`~uproot4.source.futures.ThreadPoolExecutor` whose workers are bound + A :py:class:`~uproot.source.futures.ThreadPoolExecutor` whose workers are bound to resources, such as file handles. """ @@ -362,9 +362,9 @@ def __repr__(self): def submit(self, future): """ Pass the ``task`` onto the workers' - :py:attr:`~uproot4.source.futures.ResourceWorker.work_queue` as a - :py:class:`~uproot4.source.futures.ResourceFuture` so that it will be - executed with its :py:attr:`~uproot4.source.futures.ResourceFuture.resource` + :py:attr:`~uproot.source.futures.ResourceWorker.work_queue` as a + :py:class:`~uproot.source.futures.ResourceFuture` so that it will be + executed with its :py:attr:`~uproot.source.futures.ResourceFuture.resource` when that worker is available. """ assert isinstance(future, ResourceFuture) @@ -379,17 +379,17 @@ def submit(self, future): def close(self): """ - Stops all :py:class:`~uproot4.source.futures.ResourceWorker` threads and frees - their :py:attr:`~uproot4.source.futures.ResourceWorker.resource`. + Stops all :py:class:`~uproot.source.futures.ResourceWorker` threads and frees + their :py:attr:`~uproot.source.futures.ResourceWorker.resource`. """ self.__exit__(None, None, None) @property def closed(self): """ - True if the :py:class:`~uproot4.source.futures.ResourceWorker` threads have + True if the :py:class:`~uproot.source.futures.ResourceWorker` threads have been stopped and their - :py:attr:`~uproot4.source.futures.ResourceWorker.resource` freed. + :py:attr:`~uproot.source.futures.ResourceWorker.resource` freed. """ return self._closed diff --git a/uproot4/source/http.py b/uproot/source/http.py similarity index 83% rename from uproot4/source/http.py rename to uproot/source/http.py index 448c4ad1c..abb9c3e35 100644 --- a/uproot4/source/http.py +++ b/uproot/source/http.py @@ -3,13 +3,13 @@ """ Physical layer for remote files, accessed via HTTP(S). -Defines a :py:class:`~uproot4.source.http.HTTPResource` (stateless) and two sources: -:py:class:`~uproot4.source.http.MultithreadedHTTPSource` and -:py:class:`~uproot4.source.http.HTTPSource`. The multi-threaded source only requires +Defines a :py:class:`~uproot.source.http.HTTPResource` (stateless) and two sources: +:py:class:`~uproot.source.http.MultithreadedHTTPSource` and +:py:class:`~uproot.source.http.HTTPSource`. The multi-threaded source only requires the server to support byte range requests (code 206), but the general source requires the server to support multi-part byte range requests. If the server -does not support multi-part GET, :py:class:`~uproot4.source.http.HTTPSource` -automatically falls back to :py:class:`~uproot4.source.http.MultithreadedHTTPSource`. +does not support multi-part GET, :py:class:`~uproot.source.http.HTTPSource` +automatically falls back to :py:class:`~uproot.source.http.MultithreadedHTTPSource`. Despite the name, both sources support secure HTTPS (selected by URL scheme). """ @@ -32,9 +32,9 @@ except ImportError: import Queue as queue -import uproot4.source.futures -import uproot4.source.chunk -import uproot4._util +import uproot +import uproot.source.futures +import uproot.source.chunk def make_connection(parsed_url, timeout): @@ -48,7 +48,7 @@ def make_connection(parsed_url, timeout): depending on the URL scheme. """ if parsed_url.scheme == "https": - if uproot4._util.py2: + if uproot._util.py2: return HTTPSConnection( parsed_url.hostname, parsed_url.port, None, None, False, timeout ) @@ -58,7 +58,7 @@ def make_connection(parsed_url, timeout): ) elif parsed_url.scheme == "http": - if uproot4._util.py2: + if uproot._util.py2: return HTTPConnection(parsed_url.hostname, parsed_url.port, False, timeout) else: return HTTPConnection(parsed_url.hostname, parsed_url.port, timeout) @@ -114,7 +114,7 @@ def get_num_bytes(file_path, parsed_url, timeout): if response.status == 404: connection.close() - raise uproot4._util._file_not_found(file_path, "HTTP(S) returned 404") + raise uproot._util._file_not_found(file_path, "HTTP(S) returned 404") if response.status != 200: connection.close() @@ -139,13 +139,13 @@ def get_num_bytes(file_path, parsed_url, timeout): ) -class HTTPResource(uproot4.source.chunk.Resource): +class HTTPResource(uproot.source.chunk.Resource): """ Args: file_path (str): A URL of the file to open. timeout (None or float): An optional timeout in seconds. - A :py:class:`~uproot4.source.chunk.Resource` for HTTP(S) connections. + A :py:class:`~uproot.source.chunk.Resource` for HTTP(S) connections. For simplicity, this resource does not manage a live ``http.client.HTTPConnection`` or ``http.client.HTTPSConnection``, though @@ -190,7 +190,7 @@ def get(self, connection, start, stop): if response.status == 404: connection.close() - raise uproot4._util._file_not_found(self.file_path, "HTTP(S) returned 404") + raise uproot._util._file_not_found(self.file_path, "HTTP(S) returned 404") if 300 <= response.status < 400: for k, x in response.getheaders(): @@ -228,14 +228,14 @@ def get(self, connection, start, stop): def future(source, start, stop): """ Args: - source (:py:class:`~uproot4.source.chunk.HTTPSource` or :py:class:`~uproot4.source.chunk.MultithreadedHTTPSource`): The + source (:py:class:`~uproot.source.chunk.HTTPSource` or :py:class:`~uproot.source.chunk.MultithreadedHTTPSource`): The data source. start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` that calls - :py:meth:`~uproot4.source.file.HTTPResource.get` with ``start`` and ``stop``. + Returns a :py:class:`~uproot.source.futures.ResourceFuture` that calls + :py:meth:`~uproot.source.file.HTTPResource.get` with ``start`` and ``stop``. """ connection = make_connection(source.parsed_url, source.timeout) connection.request( @@ -247,31 +247,31 @@ def future(source, start, stop): def task(resource): return resource.get(connection, start, stop) - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) @staticmethod def multifuture(source, ranges, futures, results): u""" Args: - source (:py:class:`~uproot4.source.chunk.HTTPSource`): The data source. + source (:py:class:`~uproot.source.chunk.HTTPSource`): The data source. ranges (list of (int, int) 2-tuples): Intervals to fetch as (start, stop) pairs in a single request, if possible. - futures (dict of (int, int) \u2192 :py:class:`~uproot4.source.futures.ResourceFuture`): Mapping + futures (dict of (int, int) \u2192 :py:class:`~uproot.source.futures.ResourceFuture`): Mapping from (start, stop) to a future that is awaiting its result. results (dict of (int, int) \u2192 None or ``numpy.ndarray`` of ``numpy.uint8``): Mapping from (start, stop) to None or results. - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` that attempts + Returns a :py:class:`~uproot.source.futures.ResourceFuture` that attempts to perform an HTTP(S) multipart GET, filling ``results`` to satisfy - the individual :py:class:`~uproot4.source.chunk.Chunk`'s ``futures`` with + the individual :py:class:`~uproot.source.chunk.Chunk`'s ``futures`` with its multipart response. If the server does not support multipart GET, that same future - sets :py:attr:`~uproot4.source.chunk.HTTPSource.fallback` and retries the + sets :py:attr:`~uproot.source.chunk.HTTPSource.fallback` and retries the request without multipart, using a - :py:class:`~uproot4.source.http.MultithreadedHTTPSource` to fill the same + :py:class:`~uproot.source.http.MultithreadedHTTPSource` to fill the same ``results`` and ``futures``. Subsequent attempts would immediately - use the :py:attr:`~uproot4.source.chunk.HTTPSource.fallback`. + use the :py:attr:`~uproot.source.chunk.HTTPSource.fallback`. """ connection = [make_connection(source.parsed_url, source.timeout)] @@ -328,7 +328,7 @@ def task(resource): finally: connection[0].close() - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) _content_range_size = re.compile( b"Content-Range: bytes ([0-9]+-[0-9]+)/([0-9]+)", re.I @@ -337,7 +337,7 @@ def task(resource): def is_multipart_supported(self, ranges, response): """ - Helper function for :py:meth:`~uproot4.source.http.HTTPResource.multifuture` + Helper function for :py:meth:`~uproot.source.http.HTTPResource.multifuture` to check for multipart GET support. """ if response.status != 206: @@ -354,7 +354,7 @@ def is_multipart_supported(self, ranges, response): def handle_no_multipart(self, source, ranges, futures, results): """ - Helper function for :py:meth:`~uproot4.source.http.HTTPResource.multifuture` + Helper function for :py:meth:`~uproot.source.http.HTTPResource.multifuture` to handle a lack of multipart GET support. """ source._set_fallback() @@ -362,14 +362,14 @@ def handle_no_multipart(self, source, ranges, futures, results): notifications = queue.Queue() source.fallback.chunks(ranges, notifications) - for x in uproot4._util.range(len(ranges)): + for x in uproot._util.range(len(ranges)): chunk = notifications.get() results[chunk.start, chunk.stop] = chunk.raw_data futures[chunk.start, chunk.stop]._run(self) def handle_multipart(self, source, futures, results, response): """ - Helper function for :py:meth:`~uproot4.source.http.HTTPResource.multifuture` + Helper function for :py:meth:`~uproot.source.http.HTTPResource.multifuture` to handle the multipart GET response. """ if hasattr(response, "readline"): @@ -377,7 +377,7 @@ def handle_multipart(self, source, futures, results, response): else: response_buffer = _ResponseBuffer(response) - for i in uproot4._util.range(len(futures)): + for i in uproot._util.range(len(futures)): range_string, size = self.next_header(response_buffer) if range_string is None: raise OSError( @@ -420,7 +420,7 @@ def handle_multipart(self, source, futures, results, response): def next_header(self, response_buffer): """ - Helper function for :py:meth:`~uproot4.source.http.HTTPResource.multifuture` + Helper function for :py:meth:`~uproot.source.http.HTTPResource.multifuture` to return the next header from the ``response_buffer``. """ line = response_buffer.readline() @@ -443,18 +443,18 @@ def next_header(self, response_buffer): @staticmethod def partfuture(results, start, stop): """ - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` to simply select + Returns a :py:class:`~uproot.source.futures.ResourceFuture` to simply select the ``(start, stop)`` item from the ``results`` dict. - In :py:meth:`~uproot4.source.http.HTTPSource.chunks`, each chunk has a - :py:meth:`~uproot4.source.http.HTTPResource.partfuture` that are collectively - filled by a single :py:meth:`~uproot4.source.http.HTTPResource.multifuture`. + In :py:meth:`~uproot.source.http.HTTPSource.chunks`, each chunk has a + :py:meth:`~uproot.source.http.HTTPResource.partfuture` that are collectively + filled by a single :py:meth:`~uproot.source.http.HTTPResource.multifuture`. """ def task(resource): return results[start, stop] - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) class _ResponseBuffer(object): @@ -490,21 +490,21 @@ def readline(self): return out -class HTTPSource(uproot4.source.chunk.Source): +class HTTPSource(uproot.source.chunk.Source): """ Args: file_path (str): A URL of the file to open. options: Must include ``"num_fallback_workers"`` and ``"timeout"``. - A :py:class:`~uproot4.source.chunk.Source` that first attempts an HTTP(S) + A :py:class:`~uproot.source.chunk.Source` that first attempts an HTTP(S) multipart GET, but if the server doesn't support it, it falls back to many HTTP(S) connections in threads - (:py:class:`~uproot4.source.http.MultithreadedHTTPSource`). + (:py:class:`~uproot.source.http.MultithreadedHTTPSource`). Since the multipart GET is a single request and response, it needs only one thread, but it is a background thread (a single - :py:class:`~uproot4.source.futures.ResourceWorker` in a - :py:class:`~uproot4.source.futures.ResourceThreadPoolExecutor`). + :py:class:`~uproot.source.futures.ResourceWorker` in a + :py:class:`~uproot.source.futures.ResourceThreadPoolExecutor`). """ ResourceClass = HTTPResource @@ -520,7 +520,7 @@ def __init__(self, file_path, **options): self._timeout = timeout self._num_bytes = None - self._executor = uproot4.source.futures.ResourceThreadPoolExecutor( + self._executor = uproot.source.futures.ResourceThreadPoolExecutor( [HTTPResource(file_path, timeout)] ) self._fallback = None @@ -544,7 +544,7 @@ def chunk(self, start, stop): self._num_requested_bytes += stop - start future = self.ResourceClass.future(self, start, stop) - chunk = uproot4.source.chunk.Chunk(self, start, stop, future) + chunk = uproot.source.chunk.Chunk(self, start, stop, future) self._executor.submit(future) return chunk @@ -561,9 +561,9 @@ def chunks(self, ranges, notifications): partfuture = self.ResourceClass.partfuture(results, start, stop) futures[start, stop] = partfuture results[start, stop] = None - chunk = uproot4.source.chunk.Chunk(self, start, stop, partfuture) + chunk = uproot.source.chunk.Chunk(self, start, stop, partfuture) partfuture._set_notify( - uproot4.source.chunk.notifier(chunk, notifications) + uproot.source.chunk.notifier(chunk, notifications) ) chunks.append(chunk) @@ -578,7 +578,7 @@ def chunks(self, ranges, notifications): @property def executor(self): """ - The :py:class:`~uproot4.source.futures.ResourceThreadPoolExecutor` that + The :py:class:`~uproot.source.futures.ResourceThreadPoolExecutor` that manages this source's single background thread. """ return self._executor @@ -621,7 +621,7 @@ def fallback(self): If None, the source has not encountered an unsuccessful multipart GET and no fallback is needed yet. - Otherwise, this is a :py:class:`~uproot4.source.http.MultithreadedHTTPSource` + Otherwise, this is a :py:class:`~uproot.source.http.MultithreadedHTTPSource` to which all requests are forwarded. """ return self._fallback @@ -633,14 +633,14 @@ def _set_fallback(self): ) -class MultithreadedHTTPSource(uproot4.source.chunk.MultithreadedSource): +class MultithreadedHTTPSource(uproot.source.chunk.MultithreadedSource): """ Args: file_path (str): A URL of the file to open. options: Must include ``"num_workers"`` and ``"timeout"``. - A :py:class:`~uproot4.source.chunk.MultithreadedSource` that manages many - :py:class:`~uproot4.source.http.HTTPResource` objects. + A :py:class:`~uproot.source.chunk.MultithreadedSource` that manages many + :py:class:`~uproot.source.http.HTTPResource` objects. """ ResourceClass = HTTPResource @@ -656,8 +656,8 @@ def __init__(self, file_path, **options): self._num_bytes = None self._timeout = timeout - self._executor = uproot4.source.futures.ResourceThreadPoolExecutor( - [HTTPResource(file_path, timeout) for x in uproot4._util.range(num_workers)] + self._executor = uproot.source.futures.ResourceThreadPoolExecutor( + [HTTPResource(file_path, timeout) for x in uproot._util.range(num_workers)] ) @property diff --git a/uproot4/source/object.py b/uproot/source/object.py similarity index 74% rename from uproot4/source/object.py rename to uproot/source/object.py index efabd9cda..da07a5d0a 100644 --- a/uproot4/source/object.py +++ b/uproot/source/object.py @@ -3,24 +3,24 @@ """ Physical layer for file-like objects. -Defines a :py:class:`~uproot4.source.object.ObjectResource` (wrapped Python file-like -object) and one source :py:class:`~uproot4.source.object.ObjectSource` which always +Defines a :py:class:`~uproot.source.object.ObjectResource` (wrapped Python file-like +object) and one source :py:class:`~uproot.source.object.ObjectSource` which always has exactly one worker (we can't assume that the object is thread-safe). """ from __future__ import absolute_import -import uproot4.source.futures -import uproot4.source.chunk -import uproot4._util +import uproot +import uproot.source.futures +import uproot.source.chunk -class ObjectResource(uproot4.source.chunk.Resource): +class ObjectResource(uproot.source.chunk.Resource): """ Args: obj: The file-like object to use. - A :py:class:`~uproot4.source.chunk.Resource` for a file-like object. + A :py:class:`~uproot.source.chunk.Resource` for a file-like object. This object must have the following methods: @@ -69,29 +69,29 @@ def get(self, start, stop): def future(source, start, stop): """ Args: - source (:py:class:`~uproot4.source.chunk.ObjectSource`): The data source. + source (:py:class:`~uproot.source.chunk.ObjectSource`): The data source. start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` that calls - :py:meth:`~uproot4.source.object.ObjectResource.get` with ``start`` and + Returns a :py:class:`~uproot.source.futures.ResourceFuture` that calls + :py:meth:`~uproot.source.object.ObjectResource.get` with ``start`` and ``stop``. """ def task(resource): return resource.get(start, stop) - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) -class ObjectSource(uproot4.source.chunk.MultithreadedSource): +class ObjectSource(uproot.source.chunk.MultithreadedSource): """ Args: obj: The file-like object to use. - A :py:class:`~uproot4.source.chunk.Source` for a file-like object. (Although this - is a :py:class:`~uproot4.source.chunk.MultithreadedSource`, it never has more or + A :py:class:`~uproot.source.chunk.Source` for a file-like object. (Although this + is a :py:class:`~uproot.source.chunk.MultithreadedSource`, it never has more or less than one thread.) This object must have the following methods: @@ -113,7 +113,7 @@ def __init__(self, obj, **options): self._num_requested_bytes = 0 self._file_path = repr(obj) - self._executor = uproot4.source.futures.ResourceThreadPoolExecutor( + self._executor = uproot.source.futures.ResourceThreadPoolExecutor( [ObjectResource(obj)] ) self._num_bytes = None diff --git a/uproot4/source/xrootd.py b/uproot/source/xrootd.py similarity index 81% rename from uproot4/source/xrootd.py rename to uproot/source/xrootd.py index 61d389509..675aa74b6 100644 --- a/uproot4/source/xrootd.py +++ b/uproot/source/xrootd.py @@ -3,18 +3,18 @@ """ Physical layer for remote files, accessed via the XRootD protocol. -Defines a :py:class:`~uproot4.source.http.XRootDResource` (``XRootD.File``) and two -sources: :py:class:`~uproot4.source.http.MultithreadedXRootDSource` and -:py:class:`~uproot4.source.http.XRootDSource`. The latter requires the server to +Defines a :py:class:`~uproot.source.http.XRootDResource` (``XRootD.File``) and two +sources: :py:class:`~uproot.source.http.MultithreadedXRootDSource` and +:py:class:`~uproot.source.http.XRootDSource`. The latter requires the server to support vector-read requests; if not, it automatically falls back to -:py:class:`~uproot4.source.http.MultithreadedXRootDSource`. +:py:class:`~uproot.source.http.MultithreadedXRootDSource`. """ from __future__ import absolute_import -import uproot4.source.chunk -import uproot4.source.futures -import uproot4.extras +import uproot +import uproot.source.chunk +import uproot.source.futures def get_server_config(file): @@ -35,7 +35,7 @@ def get_server_config(file): readv_iov_max = 1024 readv_ior_max = 2097136 - XRootD_client = uproot4.extras.XRootD_client() + XRootD_client = uproot.extras.XRootD_client() # Check if the file is stored locally on this machine last_url = file.get_property("LastURL") @@ -67,17 +67,17 @@ def get_server_config(file): return readv_iov_max, readv_ior_max -class XRootDResource(uproot4.source.chunk.Resource): +class XRootDResource(uproot.source.chunk.Resource): """ Args: file_path (str): A URL of the file to open. timeout (None or float): An optional timeout in seconds. - A :py:class:`~uproot4.source.chunk.Resource` for XRootD connections. + A :py:class:`~uproot.source.chunk.Resource` for XRootD connections. """ def __init__(self, file_path, timeout): - XRootD_client = uproot4.extras.XRootD_client() + XRootD_client = uproot.extras.XRootD_client() self._file_path = file_path self._timeout = timeout @@ -99,7 +99,7 @@ def _xrd_error(self, status): # https://github.com/xrootd/xrootd/blob/8e91462e76ab969720b40fc324714b84e0b4bd42/src/XrdCl/XrdClStatus.hh#L47-L103 # https://github.com/xrootd/xrootd/blob/250eced4d3787c2ac5be2c8c922134153bbf7f08/src/XrdCl/XrdClStatus.cc#L34-L74 if status.code == 101 or status.code == 304 or status.code == 400: - raise uproot4._util._file_not_found(self._file_path, status.message) + raise uproot._util._file_not_found(self._file_path, status.message) else: raise OSError( @@ -158,37 +158,37 @@ def get(self, start, stop): def future(source, start, stop): """ Args: - source (:py:class:`~uproot4.source.chunk.MultithreadedXRootDSource`): The + source (:py:class:`~uproot.source.chunk.MultithreadedXRootDSource`): The data source. start (int): Seek position of the first byte to include. stop (int): Seek position of the first byte to exclude (one greater than the last byte to include). - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` that calls - :py:meth:`~uproot4.source.xrootd.XRootDResource.get` with ``start`` and + Returns a :py:class:`~uproot.source.futures.ResourceFuture` that calls + :py:meth:`~uproot.source.xrootd.XRootDResource.get` with ``start`` and ``stop``. """ def task(resource): return resource.get(start, stop) - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) @staticmethod def partfuture(results, start, stop): """ - Returns a :py:class:`~uproot4.source.futures.ResourceFuture` to simply select + Returns a :py:class:`~uproot.source.futures.ResourceFuture` to simply select the ``(start, stop)`` item from the ``results`` dict. - In :py:meth:`~uproot4.source.xrootd.XRootDSource.chunks`, each chunk has a - :py:meth:`~uproot4.source.xrootd.XRootDResource.partfuture` that are collectively - filled by callbacks from :py:meth:`~uproot4.source.xrootd.XRootDResource.callbacker`. + In :py:meth:`~uproot.source.xrootd.XRootDSource.chunks`, each chunk has a + :py:meth:`~uproot.source.xrootd.XRootDResource.partfuture` that are collectively + filled by callbacks from :py:meth:`~uproot.source.xrootd.XRootDResource.callbacker`. """ def task(resource): return results[start, stop] - return uproot4.source.futures.ResourceFuture(task) + return uproot.source.futures.ResourceFuture(task) @staticmethod def callbacker(futures, results): @@ -206,13 +206,13 @@ def callback(status, response, hosts): return callback -class XRootDSource(uproot4.source.chunk.Source): +class XRootDSource(uproot.source.chunk.Source): """ Args: file_path (str): A URL of the file to open. options: Must include ``"timeout"`` and ``"max_num_elements"``. - A :py:class:`~uproot4.source.chunk.Source` that uses XRootD's vector-read + A :py:class:`~uproot.source.chunk.Source` that uses XRootD's vector-read to get many chunks in one request. """ @@ -249,8 +249,8 @@ def chunk(self, start, stop): self._num_requested_bytes += stop - start data = self._resource.get(start, stop) - future = uproot4.source.futures.TrivialFuture(data) - return uproot4.source.chunk.Chunk(self, start, stop, future) + future = uproot.source.futures.TrivialFuture(data) + return uproot.source.chunk.Chunk(self, start, stop, future) def chunks(self, ranges, notifications): self._num_requests += 1 @@ -275,9 +275,9 @@ def chunks(self, ranges, notifications): stop = start + size partfuture = self.ResourceClass.partfuture(results, start, stop) futures[start, stop] = partfuture - chunk = uproot4.source.chunk.Chunk(self, start, stop, partfuture) + chunk = uproot.source.chunk.Chunk(self, start, stop, partfuture) partfuture._set_notify( - uproot4.source.chunk.notifier(chunk, notifications) + uproot.source.chunk.notifier(chunk, notifications) ) chunks.append(chunk) @@ -294,7 +294,7 @@ def chunks(self, ranges, notifications): @property def resource(self): """ - The :py:class:`~uproot4.source.xrootd.XRootDResource` object. + The :py:class:`~uproot.source.xrootd.XRootDResource` object. """ return self._resource @@ -329,14 +329,14 @@ def num_bytes(self): return self._num_bytes -class MultithreadedXRootDSource(uproot4.source.chunk.MultithreadedSource): +class MultithreadedXRootDSource(uproot.source.chunk.MultithreadedSource): """ Args: file_path (str): A URL of the file to open. options: Must include ``"num_workers"`` and ``"timeout"``. - A :py:class:`~uproot4.source.chunk.MultithreadedSource` that manages many - :py:class:`~uproot4.source.xrootd.XRootDResource` objects. + A :py:class:`~uproot.source.chunk.MultithreadedSource` that manages many + :py:class:`~uproot.source.xrootd.XRootDResource` objects. """ ResourceClass = XRootDResource @@ -352,10 +352,10 @@ def __init__(self, file_path, **options): self._num_bytes = None self._timeout = timeout - self._executor = uproot4.source.futures.ResourceThreadPoolExecutor( + self._executor = uproot.source.futures.ResourceThreadPoolExecutor( [ XRootDResource(file_path, timeout) - for x in uproot4._util.range(num_workers) + for x in uproot._util.range(num_workers) ] ) diff --git a/uproot4/streamers.py b/uproot/streamers.py similarity index 83% rename from uproot4/streamers.py rename to uproot/streamers.py index 3c88b518a..cc74c774b 100644 --- a/uproot4/streamers.py +++ b/uproot/streamers.py @@ -13,12 +13,7 @@ import numpy -import uproot4._util -import uproot4.model -import uproot4.const -import uproot4.deserialization -import uproot4.models.TNamed -import uproot4.interpretation.identify +import uproot _canonical_typename_patterns = [ @@ -69,62 +64,62 @@ def _canonical_typename(name): def _ftype_to_dtype(fType): - if fType == uproot4.const.kBool: + if fType == uproot.const.kBool: return "numpy.dtype(numpy.bool_)" - elif fType == uproot4.const.kChar: + elif fType == uproot.const.kChar: return "numpy.dtype('i1')" - elif fType in (uproot4.const.kUChar, uproot4.const.kCharStar): + elif fType in (uproot.const.kUChar, uproot.const.kCharStar): return "numpy.dtype('u1')" - elif fType == uproot4.const.kShort: + elif fType == uproot.const.kShort: return "numpy.dtype('>i2')" - elif fType == uproot4.const.kUShort: + elif fType == uproot.const.kUShort: return "numpy.dtype('>u2')" - elif fType == uproot4.const.kInt: + elif fType == uproot.const.kInt: return "numpy.dtype('>i4')" - elif fType in (uproot4.const.kBits, uproot4.const.kUInt, uproot4.const.kCounter): + elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter): return "numpy.dtype('>u4')" - elif fType == uproot4.const.kLong: + elif fType == uproot.const.kLong: return "numpy.dtype('>i8')" - elif fType == uproot4.const.kULong: + elif fType == uproot.const.kULong: return "numpy.dtype('>u8')" - elif fType == uproot4.const.kLong64: + elif fType == uproot.const.kLong64: return "numpy.dtype('>i8')" - elif fType == uproot4.const.kULong64: + elif fType == uproot.const.kULong64: return "numpy.dtype('>u8')" - elif fType in (uproot4.const.kFloat, uproot4.const.kFloat16): + elif fType in (uproot.const.kFloat, uproot.const.kFloat16): return "numpy.dtype('>f4')" - elif fType in (uproot4.const.kDouble, uproot4.const.kDouble32): + elif fType in (uproot.const.kDouble, uproot.const.kDouble32): return "numpy.dtype('>f8')" else: return None def _ftype_to_struct(fType): - if fType == uproot4.const.kBool: + if fType == uproot.const.kBool: return "?" - elif fType == uproot4.const.kChar: + elif fType == uproot.const.kChar: return "b" - elif fType in (uproot4.const.kUChar, uproot4.const.kCharStar): + elif fType in (uproot.const.kUChar, uproot.const.kCharStar): return "B" - elif fType == uproot4.const.kShort: + elif fType == uproot.const.kShort: return "h" - elif fType == uproot4.const.kUShort: + elif fType == uproot.const.kUShort: return "H" - elif fType == uproot4.const.kInt: + elif fType == uproot.const.kInt: return "i" - elif fType in (uproot4.const.kBits, uproot4.const.kUInt, uproot4.const.kCounter): + elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter): return "I" - elif fType == uproot4.const.kLong: + elif fType == uproot.const.kLong: return "q" - elif fType == uproot4.const.kULong: + elif fType == uproot.const.kULong: return "Q" - elif fType == uproot4.const.kLong64: + elif fType == uproot.const.kLong64: return "q" - elif fType == uproot4.const.kULong64: + elif fType == uproot.const.kULong64: return "Q" - elif fType in (uproot4.const.kFloat, uproot4.const.kFloat16): + elif fType in (uproot.const.kFloat, uproot.const.kFloat16): return "f" - elif fType in (uproot4.const.kDouble, uproot4.const.kDouble32): + elif fType in (uproot.const.kDouble, uproot.const.kDouble32): return "d" else: raise NotImplementedError(fType) @@ -133,9 +128,9 @@ def _ftype_to_struct(fType): _tstreamerinfo_format1 = struct.Struct(">Ii") -class Model_TStreamerInfo(uproot4.model.Model): +class Model_TStreamerInfo(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerInfo``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerInfo``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -179,9 +174,9 @@ def show(self, stream=sys.stdout): def name(self): """ The name (``fName``) of this ``TStreamerInfo``, passed through - :py:func:`~uproot4.model.classname_regularize` + :py:func:`~uproot.model.classname_regularize` """ - return uproot4.model.classname_regularize(self.member("fName")) + return uproot.model.classname_regularize(self.member("fName")) @property def typename(self): @@ -194,7 +189,7 @@ def typename(self): def elements(self): """ This ``TStreamerInfo``'s list of ``TStreamerElements`` - (:py:class:`~uproot4.streamers.TStreamerElement`). + (:py:class:`~uproot.streamers.TStreamerElement`). """ return self._members["fElements"] @@ -208,7 +203,7 @@ def class_version(self): def class_code(self): """ Returns Python code as a string that, when evaluated, would be a suitable - :py:class:`~uproot4.model.VersionedModel` for this class and version. + :py:class:`~uproot.model.VersionedModel` for this class and version. """ read_members = [ " def read_members(self, chunk, cursor, context, file):", @@ -231,15 +226,15 @@ def class_code(self): " @classmethod", " def awkward_form(cls, file, index_format='i64', header=False, " "tobject_header=True):", - " from awkward1.forms import NumpyForm, ListOffsetForm, " + " from awkward.forms import NumpyForm, ListOffsetForm, " "RegularForm, RecordForm", " contents = {}", " if header:", " contents['@num_bytes'] = " - "uproot4._util.awkward_form(numpy.dtype('u4'), file, index_format, " + "uproot._util.awkward_form(numpy.dtype('u4'), file, index_format, " "header, tobject_header)", " contents['@instance_version'] = " - "uproot4._util.awkward_form(numpy.dtype('u2'), file, index_format, " + "uproot._util.awkward_form(numpy.dtype('u2'), file, index_format, " "header, tobject_header)", ] fields = [] @@ -250,7 +245,7 @@ def class_code(self): member_names = [] class_flags = {} - for i in uproot4._util.range(len(self._members["fElements"])): + for i in uproot._util.range(len(self._members["fElements"])): self._members["fElements"][i].class_code( self, i, @@ -272,7 +267,7 @@ def class_code(self): read_members.append("") strided_interpretation.append( - " return uproot4.interpretation.objects.AsStridedObjects" + " return uproot.interpretation.objects.AsStridedObjects" "(cls, members, original=original)" ) strided_interpretation.append("") @@ -316,9 +311,9 @@ def class_code(self): ) ) - class_name = uproot4.model.classname_encode(self.name, self.class_version) + class_name = uproot.model.classname_encode(self.name, self.class_version) return "\n".join( - ["class {0}(uproot4.model.VersionedModel):".format(class_name)] + ["class {0}(uproot.model.VersionedModel):".format(class_name)] + read_members + strided_interpretation + awkward_form @@ -328,25 +323,25 @@ def class_code(self): def new_class(self, file): """ Args: - file (:py:class:`~uproot4.reading.ReadOnlyFile`): File to use to generate - :py:class:`~uproot4.model.Model` classes as needed from its - :py:attr:`~uproot4.reading.ReadOnlyFile.streamers` and ``file_path`` + file (:py:class:`~uproot.reading.ReadOnlyFile`): File to use to generate + :py:class:`~uproot.model.Model` classes as needed from its + :py:attr:`~uproot.reading.ReadOnlyFile.streamers` and ``file_path`` for error messages. - Returns a new subclass of :py:class:`~uproot4.model.VersionedModel` for this + Returns a new subclass of :py:class:`~uproot.model.VersionedModel` for this class and version. """ class_code = self.class_code() - class_name = uproot4.model.classname_encode(self.name, self.class_version) - classes = uproot4.model.maybe_custom_classes(file.custom_classes) - return uproot4.deserialization.compile_class( + class_name = uproot.model.classname_encode(self.name, self.class_version) + classes = uproot.model.maybe_custom_classes(file.custom_classes) + return uproot.deserialization.compile_class( file, classes, class_code, class_name ) @property def file_uuid(self): """ - The unique identifier (:py:class:`~uproot4.reading.ReadOnlyFile`) of the file + The unique identifier (:py:class:`~uproot.reading.ReadOnlyFile`) of the file from which this ``TStreamerInfo`` was extracted. """ return self._file.uuid @@ -354,14 +349,14 @@ def file_uuid(self): def walk_members(self, streamers): """ Args: - streamers (list of :py:class:`~uproot4.streamers.TStreamerInfo`): The + streamers (list of :py:class:`~uproot.streamers.TStreamerInfo`): The complete set of ``TStreamerInfos``, probably including this one. Generator that yields all ``TStreamerElements`` - (:py:class:`~uproot4.streamers.TStreamerElement`) for this class and its + (:py:class:`~uproot.streamers.TStreamerElement`) for this class and its superclasses. - The ``TStreamerBase`` elements (:py:class:`~uproot4.streamers.TStreamerBase`) + The ``TStreamerBase`` elements (:py:class:`~uproot.streamers.TStreamerBase`) are not yielded, but they are extracted from ``streamers`` to include their elements. """ @@ -380,7 +375,7 @@ def walk_members(self, streamers): def read_members(self, chunk, cursor, context, file): self._bases.append( - uproot4.models.TNamed.Model_TNamed.read( + uproot.models.TNamed.Model_TNamed.read( chunk, cursor, context, @@ -398,7 +393,7 @@ def read_members(self, chunk, cursor, context, file): chunk, _tstreamerinfo_format1, context ) - self._members["fElements"] = uproot4.deserialization.read_object_any( + self._members["fElements"] = uproot.deserialization.read_object_any( chunk, cursor, context, file, self._file, self._concrete ) @@ -414,9 +409,9 @@ def _dependencies(self, streamers, out): _tstreamerelement_dtype1 = numpy.dtype(">i4") -class Model_TStreamerElement(uproot4.model.Model): +class Model_TStreamerElement(uproot.model.Model): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerElement``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerElement``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -435,7 +430,7 @@ def show(self, stream=sys.stdout): u" {0}: {1} ({2})\n".format( self.name, self.typename, - uproot4.model.classname_decode(type(self).__name__)[0], + uproot.model.classname_decode(type(self).__name__)[0], ) ) @@ -470,7 +465,7 @@ def array_length(self): @property def file_uuid(self): """ - The unique identifier (:py:class:`~uproot4.reading.ReadOnlyFile`) of the file + The unique identifier (:py:class:`~uproot.reading.ReadOnlyFile`) of the file from which this ``TStreamerElement`` was extracted. """ return self._file.uuid @@ -486,7 +481,7 @@ def read_members(self, chunk, cursor, context, file): # https://github.com/root-project/root/blob/master/core/meta/src/TStreamerElement.cxx#L505 self._bases.append( - uproot4.models.TNamed.Model_TNamed.read( + uproot.models.TNamed.Model_TNamed.read( chunk, cursor, context, @@ -537,7 +532,7 @@ def _dependencies(self, streamers, out): class Model_TStreamerArtificial(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerArtificial``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerArtificial``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -574,7 +569,7 @@ def class_code( class_flags, ): read_members.append( - " raise uproot4.deserialization.DeserializationError(" + " raise uproot.deserialization.DeserializationError(" "'not implemented: class members defined by {0} of type {1} in member " "{2} of class {3}', chunk, cursor, context, file.file_path)".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -582,7 +577,7 @@ def class_code( ) strided_interpretation.append( - " raise uproot4.interpretation.objects.CannotBeStrided(" + " raise uproot.interpretation.objects.CannotBeStrided(" "'not implemented: class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -590,7 +585,7 @@ def class_code( ) awkward_form.append( - " raise uproot4.interpretation.objects.CannotBeAwkward(" + " raise uproot.interpretation.objects.CannotBeAwkward(" "'not implemented: class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -603,7 +598,7 @@ def class_code( class Model_TStreamerBase(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerBase``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerBase``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -614,9 +609,9 @@ class Model_TStreamerBase(Model_TStreamerElement): def name(self): """ The name (``fName``) of this ``TStreamerBase``, passed through - :py:func:`~uproot4.model.classname_regularize`. + :py:func:`~uproot.model.classname_regularize`. """ - return uproot4.model.classname_regularize(self.member("fName")) + return uproot.model.classname_regularize(self.member("fName")) @property def base_version(self): @@ -705,7 +700,7 @@ def _dependencies(self, streamers, out): class Model_TStreamerBasicPointer(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerBasicPointer``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerBasicPointer``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -754,7 +749,7 @@ def class_code( ) strided_interpretation.append( - " raise uproot4.interpretation.objects.CannotBeStrided(" + " raise uproot.interpretation.objects.CannotBeStrided(" "'class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -764,7 +759,7 @@ def class_code( awkward_form.extend( [ " contents[{0}] = ListOffsetForm(index_format, " - "uproot4._util.awkward_form(cls._dtype{1}, file, index_format, header, " + "uproot._util.awkward_form(cls._dtype{1}, file, index_format, header, " "tobject_header),".format(repr(self.name), len(dtypes)), " parameters={'uproot': {'as': 'TStreamerBasicPointer', " "'count_name': " + repr(self.count_name) + "}}", @@ -773,7 +768,7 @@ def class_code( ) member_names.append(self.name) - dtypes.append(_ftype_to_dtype(self.fType - uproot4.const.kOffsetP)) + dtypes.append(_ftype_to_dtype(self.fType - uproot.const.kOffsetP)) def read_members(self, chunk, cursor, context, file): self._bases.append( @@ -796,7 +791,7 @@ def read_members(self, chunk, cursor, context, file): class Model_TStreamerBasicType(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerBasicType``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerBasicType``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -883,7 +878,7 @@ def class_code( ) else: strided_interpretation.append( - " raise uproot4.interpretation.objects.CannotBeStrided(" + " raise uproot.interpretation.objects.CannotBeStrided(" "'class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -907,7 +902,7 @@ def class_code( else: awkward_form.append( - " contents[{0}] = uproot4._util.awkward_form({1}, " + " contents[{0}] = uproot._util.awkward_form({1}, " "file, index_format, header, tobject_header)".format( repr(self.name), _ftype_to_dtype(self.fType) ) @@ -915,7 +910,7 @@ def class_code( else: awkward_form.append( - " contents[{0}] = RegularForm(uproot4._util.awkward_form({1}, " + " contents[{0}] = RegularForm(uproot._util.awkward_form({1}, " "file, index_format, header, tobject_header), {2})".format( repr(self.name), _ftype_to_dtype(self.fType), self.array_length ) @@ -936,60 +931,60 @@ def read_members(self, chunk, cursor, context, file): ) ) if ( - uproot4.const.kOffsetL + uproot.const.kOffsetL < self._bases[0]._members["fType"] - < uproot4.const.kOffsetP + < uproot.const.kOffsetP ): - self._bases[0]._members["fType"] -= uproot4.const.kOffsetL + self._bases[0]._members["fType"] -= uproot.const.kOffsetL basic = True if self._bases[0]._members["fType"] in ( - uproot4.const.kBool, - uproot4.const.kUChar, - uproot4.const.kChar, + uproot.const.kBool, + uproot.const.kUChar, + uproot.const.kChar, ): self._bases[0]._members["fSize"] = 1 elif self._bases[0]._members["fType"] in ( - uproot4.const.kUShort, - uproot4.const.kShort, + uproot.const.kUShort, + uproot.const.kShort, ): self._bases[0]._members["fSize"] = 2 elif self._bases[0]._members["fType"] in ( - uproot4.const.kBits, - uproot4.const.kUInt, - uproot4.const.kInt, - uproot4.const.kCounter, + uproot.const.kBits, + uproot.const.kUInt, + uproot.const.kInt, + uproot.const.kCounter, ): self._bases[0]._members["fSize"] = 4 elif self._bases[0]._members["fType"] in ( - uproot4.const.kULong, - uproot4.const.kLong, + uproot.const.kULong, + uproot.const.kLong, ): self._bases[0]._members["fSize"] = numpy.dtype(numpy.long).itemsize elif self._bases[0]._members["fType"] in ( - uproot4.const.kULong64, - uproot4.const.kLong64, + uproot.const.kULong64, + uproot.const.kLong64, ): self._bases[0]._members["fSize"] = 8 elif self._bases[0]._members["fType"] in ( - uproot4.const.kFloat, - uproot4.const.kFloat16, + uproot.const.kFloat, + uproot.const.kFloat16, ): self._bases[0]._members["fSize"] = 4 elif self._bases[0]._members["fType"] in ( - uproot4.const.kDouble, - uproot4.const.kDouble32, + uproot.const.kDouble, + uproot.const.kDouble32, ): self._bases[0]._members["fSize"] = 8 - elif self._bases[0]._members["fType"] == uproot4.const.kCharStar: + elif self._bases[0]._members["fType"] == uproot.const.kCharStar: self._bases[0]._members["fSize"] = numpy.dtype(numpy.intp).itemsize else: @@ -1004,7 +999,7 @@ def read_members(self, chunk, cursor, context, file): class Model_TStreamerLoop(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerLoop``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerLoop``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1037,7 +1032,7 @@ def class_code( read_members.extend( [ " cursor.skip(6)", - " for tmp in uproot4._util.range(self.member({0})):".format( + " for tmp in uproot._util.range(self.member({0})):".format( repr(self.count_name) ), " self._members[{0}] = c({1}).read(chunk, cursor, " @@ -1048,7 +1043,7 @@ def class_code( ) strided_interpretation.append( - " raise uproot4.interpretation.objects.CannotBeStrided(" + " raise uproot.interpretation.objects.CannotBeStrided(" "'class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -1103,7 +1098,7 @@ def _dependencies(self, streamers, out): class Model_TStreamerSTL(Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerSTL``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerSTL``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1140,7 +1135,7 @@ def class_code( member_names, class_flags, ): - stl_container = uproot4.interpretation.identify.parse_typename( + stl_container = uproot.interpretation.identify.parse_typename( self.typename, quote=True, outer_header=True, @@ -1187,23 +1182,23 @@ def read_members(self, chunk, cursor, context, file): ) if self._members["fSTLtype"] in ( - uproot4.const.kSTLmultimap, - uproot4.const.kSTLset, + uproot.const.kSTLmultimap, + uproot.const.kSTLset, ): if self._bases[0]._members["fTypeName"].startswith( "std::set" ) or self._bases[0]._members["fTypeName"].startswith("set"): - self._members["fSTLtype"] = uproot4.const.kSTLset + self._members["fSTLtype"] = uproot.const.kSTLset elif self._bases[0]._members["fTypeName"].startswith( "std::multimap" ) or self._bases[0]._members["fTypeName"].startswith("multimap"): - self._members["fSTLtype"] = uproot4.const.kSTLmultimap + self._members["fSTLtype"] = uproot.const.kSTLmultimap class Model_TStreamerSTLstring(Model_TStreamerSTL): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerSTLString``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerSTLString``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1227,8 +1222,8 @@ def read_members(self, chunk, cursor, context, file): class TStreamerPointerTypes(object): """ A class to share code between - :py:class:`~uproot4.streamers.Model_TStreamerObjectAnyPointer` and - :py:class:`~uproot4.streamers.Model_TStreamerObjectPointer`. + :py:class:`~uproot.streamers.Model_TStreamerObjectAnyPointer` and + :py:class:`~uproot.streamers.Model_TStreamerObjectPointer`. """ def class_code( @@ -1247,7 +1242,7 @@ def class_code( member_names, class_flags, ): - if self.fType == uproot4.const.kObjectp or self.fType == uproot4.const.kAnyp: + if self.fType == uproot.const.kObjectp or self.fType == uproot.const.kAnyp: read_members.append( " self._members[{0}] = c({1}).read(chunk, cursor, context, " "file, self._file, self._concrete)".format( @@ -1267,13 +1262,13 @@ def class_code( ) ) - elif self.fType == uproot4.const.kObjectP or self.fType == uproot4.const.kAnyP: + elif self.fType == uproot.const.kObjectP or self.fType == uproot.const.kAnyP: read_members.append( " self._members[{0}] = read_object_any(chunk, cursor, " "context, file, self._file, self)".format(repr(self.name)) ) strided_interpretation.append( - " raise uproot4.interpretation.objects.CannotBeStrided(" + " raise uproot.interpretation.objects.CannotBeStrided(" "'class members defined by {0} of type {1} in member " "{2} of class {3}')".format( type(self).__name__, self.typename, self.name, streamerinfo.name @@ -1283,7 +1278,7 @@ def class_code( else: read_members.append( - " raise uproot4.deserialization.DeserializationError(" + " raise uproot.deserialization.DeserializationError(" "'not implemented: class members defined by {0} with fType {1}', " "chunk, cursor, context, file.file_path)".format( type(self).__name__, self.fType, @@ -1302,7 +1297,7 @@ def _dependencies(self, streamers, out): class Model_TStreamerObjectAnyPointer(TStreamerPointerTypes, Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerObjectAnyPointer``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerObjectAnyPointer``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1325,7 +1320,7 @@ def read_members(self, chunk, cursor, context, file): class Model_TStreamerObjectPointer(TStreamerPointerTypes, Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerObjectPointer``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerObjectPointer``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1349,9 +1344,9 @@ def read_members(self, chunk, cursor, context, file): class TStreamerObjectTypes(object): """ A class to share code between - :py:class:`~uproot4.streamers.Model_TStreamerObject`, - :py:class:`~uproot4.streamers.Model_TStreamerObjectAny`, and - :py:class:`~uproot4.streamers.Model_TStreamerString`. + :py:class:`~uproot.streamers.Model_TStreamerObject`, + :py:class:`~uproot.streamers.Model_TStreamerObjectAny`, and + :py:class:`~uproot.streamers.Model_TStreamerString`. """ def class_code( @@ -1402,7 +1397,7 @@ def _dependencies(self, streamers, out): class Model_TStreamerObject(TStreamerObjectTypes, Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerObject``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerObject``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1425,7 +1420,7 @@ def read_members(self, chunk, cursor, context, file): class Model_TStreamerObjectAny(TStreamerObjectTypes, Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerObjectAny``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerObjectAny``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1448,7 +1443,7 @@ def read_members(self, chunk, cursor, context, file): class Model_TStreamerString(TStreamerObjectTypes, Model_TStreamerElement): """ - A versionless :py:class:`~uproot4.model.Model` for ``TStreamerString``. + A versionless :py:class:`~uproot.model.Model` for ``TStreamerString``. Since this model is versionless and most of its functionality is internal (not to be directly accessed by most users), it is defined on the model @@ -1469,17 +1464,17 @@ def read_members(self, chunk, cursor, context, file): ) -uproot4.classes["TStreamerInfo"] = Model_TStreamerInfo -uproot4.classes["TStreamerElement"] = Model_TStreamerElement -uproot4.classes["TStreamerArtificial"] = Model_TStreamerArtificial -uproot4.classes["TStreamerBase"] = Model_TStreamerBase -uproot4.classes["TStreamerBasicPointer"] = Model_TStreamerBasicPointer -uproot4.classes["TStreamerBasicType"] = Model_TStreamerBasicType -uproot4.classes["TStreamerLoop"] = Model_TStreamerLoop -uproot4.classes["TStreamerObject"] = Model_TStreamerObject -uproot4.classes["TStreamerObjectAny"] = Model_TStreamerObjectAny -uproot4.classes["TStreamerObjectAnyPointer"] = Model_TStreamerObjectAnyPointer -uproot4.classes["TStreamerObjectPointer"] = Model_TStreamerObjectPointer -uproot4.classes["TStreamerSTL"] = Model_TStreamerSTL -uproot4.classes["TStreamerSTLstring"] = Model_TStreamerSTLstring -uproot4.classes["TStreamerString"] = Model_TStreamerString +uproot.classes["TStreamerInfo"] = Model_TStreamerInfo +uproot.classes["TStreamerElement"] = Model_TStreamerElement +uproot.classes["TStreamerArtificial"] = Model_TStreamerArtificial +uproot.classes["TStreamerBase"] = Model_TStreamerBase +uproot.classes["TStreamerBasicPointer"] = Model_TStreamerBasicPointer +uproot.classes["TStreamerBasicType"] = Model_TStreamerBasicType +uproot.classes["TStreamerLoop"] = Model_TStreamerLoop +uproot.classes["TStreamerObject"] = Model_TStreamerObject +uproot.classes["TStreamerObjectAny"] = Model_TStreamerObjectAny +uproot.classes["TStreamerObjectAnyPointer"] = Model_TStreamerObjectAnyPointer +uproot.classes["TStreamerObjectPointer"] = Model_TStreamerObjectPointer +uproot.classes["TStreamerSTL"] = Model_TStreamerSTL +uproot.classes["TStreamerSTLstring"] = Model_TStreamerSTLstring +uproot.classes["TStreamerString"] = Model_TStreamerString diff --git a/uproot4/version.py b/uproot/version.py similarity index 95% rename from uproot4/version.py rename to uproot/version.py index ffff9b0d0..0bff8ca04 100644 --- a/uproot4/version.py +++ b/uproot/version.py @@ -13,7 +13,7 @@ import re -__version__ = "0.1.2" +__version__ = "1.0.0rc1" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__)) diff --git a/uproot4/__init__.py b/uproot4/__init__.py deleted file mode 100644 index f1d377fa3..000000000 --- a/uproot4/__init__.py +++ /dev/null @@ -1,210 +0,0 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE - -""" -Uproot: ROOT I/O in pure Python and NumPy. - -Nearly all of the functions needed for general use are imported here, but the -documentation gives fully qualified names. For example, the most frequently -used function in Uproot is - -.. code-block:: python - - uproot4.open("path/to/filename.root") - -but we refer to it in the documentation as :py:func:`~uproot4.reading.open`. - -Typical entry points for file-reading are - -* :py:func:`~uproot4.reading.open` -* :py:func:`~uproot4.behaviors.TBranch.iterate` -* :py:func:`~uproot4.behaviors.TBranch.concatenate` -* :py:func:`~uproot4.behaviors.TBranch.lazy` - -though they would usually be accessed as ``uproot4.iterate``, -``uproot4.concatenate``, and ``uproot4.lazy``. - -The most useful classes are - -* :py:class:`~uproot4.behaviors.TBranch.HasBranches` (``TTree`` or ``TBranch``) -* :py:class:`~uproot4.behaviors.TBranch.TBranch` -* :py:class:`~uproot4.behaviors.TH1` -* :py:class:`~uproot4.behaviors.TH2` -* :py:class:`~uproot4.behaviors.TProfile` - -though they would usually be accessed through instances that have been read -from files. - -The submodules of Uproot are: - -* :py:mod:`uproot4.reading`: entry-point for reading files, as well as classes - for the three basic types that can't be modeled: ``TFile``, ``TDirectory``, - and ``TKey``. -* :py:mod:`uproot4.behaviors`: methods and properties to mix into instantiated - models, for a high-level user interface. -* :py:mod:`uproot4.model`: utilities for modeling C++ objects as Python objects. -* :py:mod:`uproot4.streamers`: models for ``TStreamerInfo`` and its elements - to generate code for new models for classes in ROOT files. -* :py:mod:`uproot4.cache`: defines caches with least-recently used eviction - policies. -* :py:mod:`uproot4.compression`: functions for compressing and decompressing data. -* :py:mod:`uproot4.deserialization`: utility functions for deserialization, - including the generation of new classes. -* :py:mod:`uproot4.source`: the "physical layer," which reads bytes without - interpreting them from various backends, like files, HTTP(S), and XRootD. -* :py:mod:`uproot4.interpretation`: prescriptions for converting ROOT types - into Pythonic arrays. -* :py:mod:`uproot4.containers`: interpretations and models for standard - containers, such as ``std::vector`` and arrays. -* :py:mod:`uproot4.language`: computational backends for expressions in - :py:mod:`uproot4.behavior.TBranch.HasBranches.arrays`. -* :py:mod:`uproot4.models`: predefined models for classes that are too basic - to rely on ``TStreamerInfo`` or too common to justify reading it. -* :py:mod:`uproot4.const`: integer constants used in ROOT serialization and - deserialization. -* :py:mod:`uproot4.extras`: import functions for the libraries that Uproot can - use, but does not require as dependencies. If a library can't be imported, - these functions provide instructions for installing them. -* :py:mod:`uproot4.version`: for access to the version number. -* :py:mod:`uproot4.dynamic`: initially empty module, in which dynamically - generated classes are defined. -* :py:mod:`uproot4._util`: non-public utilities used by the above. -""" - -from __future__ import absolute_import - -from uproot4.version import __version__ - -import uproot4.dynamic - -classes = {} -unknown_classes = {} - -from uproot4.cache import LRUCache -from uproot4.cache import LRUArrayCache - -from uproot4.source.file import MemmapSource -from uproot4.source.file import MultithreadedFileSource -from uproot4.source.http import HTTPSource -from uproot4.source.http import MultithreadedHTTPSource -from uproot4.source.xrootd import XRootDSource -from uproot4.source.xrootd import MultithreadedXRootDSource -from uproot4.source.object import ObjectSource -from uproot4.source.cursor import Cursor -from uproot4.source.futures import TrivialExecutor -from uproot4.source.futures import ThreadPoolExecutor -from uproot4.deserialization import DeserializationError - -from uproot4.reading import open -from uproot4.reading import ReadOnlyFile -from uproot4.reading import ReadOnlyDirectory - -from uproot4.exceptions import KeyInFileError - -from uproot4.model import Model -from uproot4.model import classname_decode -from uproot4.model import classname_encode -from uproot4.model import has_class_named -from uproot4.model import class_named -from uproot4.model import reset_classes - -import uproot4.models.TObject -import uproot4.models.TString -import uproot4.models.TArray -import uproot4.models.TNamed -import uproot4.models.TList -import uproot4.models.THashList -import uproot4.models.TObjArray -import uproot4.models.TObjString -import uproot4.models.TAtt -import uproot4.models.TRef - -import uproot4.models.TTree -import uproot4.models.TBranch -import uproot4.models.TLeaf -import uproot4.models.TBasket -import uproot4.models.RNTuple - -from uproot4.containers import STLVector -from uproot4.containers import STLSet -from uproot4.containers import STLMap - -import uproot4.interpretation -import uproot4.interpretation.library -from uproot4.interpretation.numerical import AsDtype -from uproot4.interpretation.numerical import AsDtypeInPlace -from uproot4.interpretation.numerical import AsDouble32 -from uproot4.interpretation.numerical import AsFloat16 -from uproot4.interpretation.numerical import AsSTLBits -from uproot4.interpretation.jagged import AsJagged -from uproot4.interpretation.strings import AsStrings -from uproot4.interpretation.objects import AsObjects -from uproot4.interpretation.objects import AsStridedObjects -from uproot4.interpretation.grouped import AsGrouped -from uproot4.containers import AsString -from uproot4.containers import AsPointer -from uproot4.containers import AsArray -from uproot4.containers import AsDynamic -from uproot4.containers import AsVector -from uproot4.containers import AsSet -from uproot4.containers import AsMap - -default_library = "ak" - -from uproot4.behaviors.TTree import TTree -from uproot4.behaviors.TBranch import TBranch -from uproot4.behaviors.TBranch import iterate -from uproot4.behaviors.TBranch import concatenate -from uproot4.behaviors.TBranch import lazy - -import pkgutil -import uproot4.behaviors - - -def behavior_of(classname): - """ - Finds and loads the behavior class for C++ (decoded) classname or returns - None if there isn't one. - - Behaviors do not have a required base class, and they may be used with - Awkward Array's ``ak.behavior``. - - The search strategy for finding behavior classes is: - - 1. Translate the ROOT class name from C++ to Python with - :py:func:`~uproot4.model.classname_encode`. For example, - ``"ROOT::RThing"`` becomes ``"Model_ROOT_3a3a_RThing"``. - 2. Look for a submodule of ``uproot4.behaviors`` without - the ``"Model_"`` prefix. For example, ``"ROOT_3a3a_RThing"``. - 3. Look for a class in that submodule with the fully encoded - name. For example, ``"Model_ROOT_3a3a_RThing"``. - - See :py:mod:`uproot4.behaviors` for details. - """ - name = classname_encode(classname) - assert name.startswith("Model_") - name = name[6:] - - if name not in globals(): - if name in behavior_of._module_names: - exec( - compile( - "import uproot4.behaviors.{0}".format(name), "", "exec" - ), - globals(), - ) - module = eval("uproot4.behaviors.{0}".format(name)) - behavior_cls = getattr(module, name, None) - if behavior_cls is not None: - globals()[name] = behavior_cls - - return globals().get(name) - - -behavior_of._module_names = [ - module_name - for loader, module_name, is_pkg in pkgutil.walk_packages(uproot4.behaviors.__path__) -] - -del pkgutil - -from uproot4._util import no_filter diff --git a/uproot4/language/__init__.py b/uproot4/language/__init__.py deleted file mode 100644 index 67e3e38c1..000000000 --- a/uproot4/language/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# BSD 3-Clause License; see https://github.com/scikit-hep/uproot4/blob/master/LICENSE - -""" -Defines languages for expressions passed to -:py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` (and similar). - -The default is :py:class:`~uproot4.language.python.PythonLanguage`. - -All languages must be subclasses of :py:class:`~uproot4.language.Language`. -""" - -from __future__ import absolute_import - - -class Language(object): - """ - Abstract class for all languages, which are used to compute the expressions - that are passed to :py:meth:`~uproot4.behavior.TBranch.HasBranches.arrays` (and - similar). - - The default is :py:class:`~uproot4.language.python.PythonLanguage`. - """ - - pass