From 922cd1c75b4d388420965ac2a3e61a3aa7186c45 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Wed, 27 Mar 2019 10:15:55 -0500 Subject: [PATCH] add uproot.pandas.iterate in a way that isn't overly clever --- uproot/__init__.py | 18 ++---------------- uproot/pandas.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 uproot/pandas.py diff --git a/uproot/__init__.py b/uproot/__init__.py index c6a3cdef..e099a7d3 100644 --- a/uproot/__init__.py +++ b/uproot/__init__.py @@ -164,22 +164,7 @@ from uproot.interp.objects import STLString asdebug = asjagged(asdtype("u1")) -from uproot.source.memmap import MemmapSource -from uproot.source.xrootd import XRootDSource -from uproot.source.http import HTTPSource -def iterate(path, treepath, branches=None, entrysteps=None, namedecode="utf-8", reportpath=False, reportfile=False, flatten=True, flatname=None, awkwardlib=None, cache=None, basketcache=None, keycache=None, executor=None, blocking=True, localsource=MemmapSource.defaults, xrootdsource=XRootDSource.defaults, httpsource=HTTPSource.defaults, **options): - import pandas - import uproot.tree - return uproot.tree.iterate(path, treepath, branches=branches, entrysteps=entrysteps, outputtype=pandas.DataFrame, namedecode=namedecode, reportpath=reportpath, reportfile=reportfile, reportentries=False, flatten=flatten, flatname=flatname, awkwardlib=awkwardlib, cache=cache, basketcache=basketcache, keycache=keycache, executor=executor, blocking=blocking, localsource=localsource, xrootdsource=xrootdsource, httpsource=httpsource, **options) - -from types import ModuleType -pandas = ModuleType("uproot.pandas") -pandas.iterate = iterate -del ModuleType -del iterate -del MemmapSource -del XRootDSource -del HTTPSource +from uproot import pandas # put help strings on everything (they're long, too disruptive to intersperse # in the code, and are built programmatically to avoid duplication; Python's @@ -189,6 +174,7 @@ def iterate(path, treepath, branches=None, entrysteps=None, namedecode="utf-8", # convenient access to the version number from uproot.version import __version__ +# don't expose uproot.uproot; it's ugly del uproot __all__ = ["open", "xrootd", "http", "iterate", "numentries", "lazyarray", "lazyarrays", "daskarray", "daskarrays", "daskframe", "create", "recreate", "update", "MemmapSource", "FileSource", "XRootDSource", "HTTPSource", "interpret", "asdtype", "asarray", "asdouble32", "asstlbitset", "asjagged", "astable", "asobj", "asgenobj", "asstring", "asdebug", "SimpleArray", "STLVector", "STLMap", "STLString", "pandas", "__version__"] diff --git a/uproot/pandas.py b/uproot/pandas.py new file mode 100644 index 00000000..9e7cd0ad --- /dev/null +++ b/uproot/pandas.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +# Copyright (c) 2019, IRIS-HEP +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Top-level functions for Pandas.""" + +import uproot.tree +from uproot.source.memmap import MemmapSource +from uproot.source.xrootd import XRootDSource +from uproot.source.http import HTTPSource + +def iterate(path, treepath, branches=None, entrysteps=None, namedecode="utf-8", reportpath=False, reportfile=False, flatten=True, flatname=None, awkwardlib=None, cache=None, basketcache=None, keycache=None, executor=None, blocking=True, localsource=MemmapSource.defaults, xrootdsource=XRootDSource.defaults, httpsource=HTTPSource.defaults, **options): + import pandas + return uproot.tree.iterate(path, treepath, branches=branches, entrysteps=entrysteps, outputtype=pandas.DataFrame, namedecode=namedecode, reportpath=reportpath, reportfile=reportfile, reportentries=False, flatten=flatten, flatname=flatname, awkwardlib=awkwardlib, cache=cache, basketcache=basketcache, keycache=keycache, executor=executor, blocking=blocking, localsource=localsource, xrootdsource=xrootdsource, httpsource=httpsource, **options)