From b261b7a597366dd217c1c1e66d27a8e22019afeb Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 7 Aug 2018 08:19:32 -0500 Subject: [PATCH 1/3] maybe fixes #110: recognize pathlib.Path objects when given to uproot.open, uproot.iterate, uproot.numentries, and uproot.lazyarrays --- uproot/rootio.py | 5 +++++ uproot/tree.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/uproot/rootio.py b/uproot/rootio.py index b912edeb..0bbe0089 100644 --- a/uproot/rootio.py +++ b/uproot/rootio.py @@ -54,6 +54,11 @@ ################################################################ high-level interface def open(path, localsource=MemmapSource.defaults, xrootdsource=XRootDSource.defaults, httpsource=HTTPSource.defaults, **options): + if path.__class__.__module__ == "pathlib": + import pathlib + if isinstance(path, pathlib.Path): + path = str(path) + parsed = urlparse(path) if _bytesid(parsed.scheme) == b"file" or len(parsed.scheme) == 0: path = parsed.netloc + parsed.path diff --git a/uproot/tree.py b/uproot/tree.py index 2ad3b556..d172d290 100644 --- a/uproot/tree.py +++ b/uproot/tree.py @@ -99,6 +99,10 @@ def _delayedraise(excinfo): raise err.with_traceback(trc) def _filename_explode(x): + if x.__class__.__module__ == "pathlib": + import pathlib + if isinstance(x, pathlib.Path): + x = str(x) parsed = urlparse(x) if _bytesid(parsed.scheme) == b"file" or len(parsed.scheme) == 0: pattern = os.path.expanduser(parsed.netloc + parsed.path) From 59a6f79c034d279fbc557a195852cf6720f6270d Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 7 Aug 2018 11:18:26 -0500 Subject: [PATCH 2/3] for #110: what about this? --- uproot/rootio.py | 2 ++ uproot/tree.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/uproot/rootio.py b/uproot/rootio.py index 0bbe0089..11b126c5 100644 --- a/uproot/rootio.py +++ b/uproot/rootio.py @@ -54,6 +54,8 @@ ################################################################ high-level interface def open(path, localsource=MemmapSource.defaults, xrootdsource=XRootDSource.defaults, httpsource=HTTPSource.defaults, **options): + if hasattr(path, "__fspath__"): + path = path.__fspath__() if path.__class__.__module__ == "pathlib": import pathlib if isinstance(path, pathlib.Path): diff --git a/uproot/tree.py b/uproot/tree.py index d172d290..0fb74822 100644 --- a/uproot/tree.py +++ b/uproot/tree.py @@ -99,6 +99,8 @@ def _delayedraise(excinfo): raise err.with_traceback(trc) def _filename_explode(x): + if hasattr(x, "__fspath__"): + x = x.__fspath__() if x.__class__.__module__ == "pathlib": import pathlib if isinstance(x, pathlib.Path): From 5d17e402139c8e48d9510ae050cb97515e8e26a2 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 7 Aug 2018 14:50:32 -0500 Subject: [PATCH 3/3] close #110 to simplify refactoring into uproot 3 --- uproot/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uproot/version.py b/uproot/version.py index 7727b6bc..066eafba 100644 --- a/uproot/version.py +++ b/uproot/version.py @@ -30,7 +30,7 @@ import re -__version__ = "2.9.10" +__version__ = "2.9.11" version = __version__ version_info = tuple(re.split(r"[-\.]", __version__))