From a7350e964180a2aefa1b8cfc88c4620ba492cca1 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 30 Aug 2018 14:52:53 -0500 Subject: [PATCH] functions of one argument should apply to the whole array, not the first Table field --- awkward/array/jagged.py | 8 ++++++-- awkward/array/objects.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/awkward/array/jagged.py b/awkward/array/jagged.py index 92978626..b24b8042 100644 --- a/awkward/array/jagged.py +++ b/awkward/array/jagged.py @@ -31,6 +31,7 @@ import collections import math import numbers +import types import awkward.array.base import awkward.type @@ -343,7 +344,7 @@ def base(self): return self._content.base def _argfields(self, function): - if isinstance(self._content, awkward.util.numpy.ndarray): + if (isinstance(function, types.FunctionType) and function.__code__.co_argcount == 1) or isinstance(self._content, awkward.util.numpy.ndarray): return awkward.util._argfields(function) else: return self._content._argfields(function) @@ -452,7 +453,10 @@ def __getitem__(self, where): offsets = counts2offsets(intheadsum) return self.copy(starts=offsets[:-1].reshape(intheadsum.shape), stops=offsets[1:].reshape(intheadsum.shape), content=thyself._content[head._content]) - + + elif len(head.shape) == 1: + raise TypeError("jagged index must be boolean (mask) or integer (fancy indexing)") + else: # the other cases are possible, but complicated; the first sets the form raise NotImplementedError("jagged index content type: {0}".format(head._content.dtype)) diff --git a/awkward/array/objects.py b/awkward/array/objects.py index 7e40618e..9e01c55a 100644 --- a/awkward/array/objects.py +++ b/awkward/array/objects.py @@ -29,6 +29,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import numbers +import types import awkward.array.base import awkward.util @@ -174,7 +175,7 @@ def base(self): return self._content.base def _argfields(self, function): - if isinstance(self._content, awkward.util.numpy.ndarray): + if (isinstance(function, types.FunctionType) and function.__code__.co_argcount == 1) or isinstance(self._content, awkward.util.numpy.ndarray): return awkward.util._argfields(function) else: return self._content._argfields(function)