From 97e65a40282e8c96628e00d224f109362f2e7c06 Mon Sep 17 00:00:00 2001 From: zineb aly <aly.zineb.az@gmail.com> Date: Tue, 26 May 2020 17:55:52 +0200 Subject: [PATCH] move monkey patch to patches.py --- km3io/__init__.py | 20 +------------------- km3io/patches.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 km3io/patches.py diff --git a/km3io/__init__.py b/km3io/__init__.py index 2cb507f..52ba634 100644 --- a/km3io/__init__.py +++ b/km3io/__init__.py @@ -1,7 +1,3 @@ -import numpy as np -import awkward as ak -import awkward1 as ak1 - from pkg_resources import get_distribution, DistributionNotFound version = get_distribution(__name__).version @@ -9,18 +5,4 @@ version = get_distribution(__name__).version from .offline import OfflineReader from .online import OnlineReader from .gseagen import GSGReader - -# to avoid infinite recursion -old_getitem = ak.ChunkedArray.__getitem__ - - -def new_getitem(self, item): - """Monkey patch the getitem in awkward.ChunkedArray to apply - awkward1.Array masks on awkward.ChunkedArray""" - if isinstance(item, (ak1.Array, ak.ChunkedArray)): - return ak1.Array(self)[item] - else: - return old_getitem(self, item) - - -ak.ChunkedArray.__getitem__ = new_getitem +from . import patches diff --git a/km3io/patches.py b/km3io/patches.py new file mode 100644 index 0000000..3ee5b34 --- /dev/null +++ b/km3io/patches.py @@ -0,0 +1,17 @@ +import awkward as ak +import awkward1 as ak1 + +# to avoid infinite recursion +old_getitem = ak.ChunkedArray.__getitem__ + + +def new_getitem(self, item): + """Monkey patch the getitem in awkward.ChunkedArray to apply + awkward1.Array masks on awkward.ChunkedArray""" + if isinstance(item, (ak1.Array, ak.ChunkedArray)): + return ak1.Array(self)[item] + else: + return old_getitem(self, item) + + +ak.ChunkedArray.__getitem__ = new_getitem \ No newline at end of file -- GitLab