Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #101 from scikit-hep/issue-uprootmethods-44
Browse files Browse the repository at this point in the history
fix issues related to scikit-hep/uproot3-methods#44 and #100
  • Loading branch information
jpivarski authored Mar 10, 2019
2 parents c7c75d5 + 574f201 commit eb7ff85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions awkward/array/jagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,13 @@ def starts(self, value):
self._starts = value
self._offsets, self._counts, self._parents = None, None, None
self._isvalid = False

@property
def stops(self):
return self._stops
if len(self._stops) == len(self._starts):
return self._stops
else:
return self._stops[:len(self._starts)]

@stops.setter
def stops(self, value):
Expand Down Expand Up @@ -386,7 +389,7 @@ def offsets(self, value):
def counts(self):
if self._counts is None:
self._valid()
self._counts = self._stops - self._starts
self._counts = self.stops - self._starts
return self._counts

@counts.setter
Expand Down Expand Up @@ -433,7 +436,7 @@ def parents(self, value):
def index(self):
tmp = self.compact()
out = self.numpy.arange(len(tmp._content), dtype=self.INDEXTYPE)
return self.copy(starts=tmp._starts, stops=tmp._stops, content=(out - tmp._starts[tmp.parents]))
return self.JaggedArray(tmp._starts, tmp._stops, (out - tmp._starts[tmp.parents]))

def _getnbytes(self, seen):
if id(self) in seen:
Expand Down Expand Up @@ -483,7 +486,7 @@ def _validstartsstops(cls, starts, stops):
raise ValueError("starts must have the same (or shorter) length than stops")
if starts.shape[1:] != stops.shape[1:]:
raise ValueError("starts and stops must have the same dimensionality (shape[1:])")
if not (stops >= starts).all():
if not (stops[:len(starts)] >= starts).all():
raise ValueError("stops must be greater than or equal to starts")

def __iter__(self, checkiter=True):
Expand Down Expand Up @@ -590,7 +593,7 @@ def __getitem__(self, where):
stack.insert(0, node.counts)
node = node.flatten()

counts = node._stops - node._starts
counts = node.stops - node._starts
if head < 0:
head = counts + head
if not self.numpy.bitwise_and(0 <= head, head < counts).all():
Expand All @@ -605,7 +608,7 @@ def __getitem__(self, where):
if nslices >= 2:
raise NotImplementedError("this implementation cannot slice a JaggedArray in more than two dimensions")

counts = node._stops - node._starts
counts = node.stops - node._starts
step = 1 if head.step is None else head.step

if step == 0:
Expand Down Expand Up @@ -766,12 +769,21 @@ def __setitem__(self, where, what):

def tojagged(self, data):
if isinstance(data, JaggedArray):
if not self.numpy.array_equal(self.counts, data.counts):
selfcounts = self.stops - self._starts
datacounts = data.stops - data._starts
if not self.numpy.array_equal(selfcounts, datacounts):
raise ValueError("cannot broadcast JaggedArray to match JaggedArray with a different counts")
if len(self._starts) == 0:
return self.copy(content=data._content)

tmp = self.compact()
assert self.offsetsaliased(tmp._starts, tmp._stops) # because that's what compact means
tmpparents = self.offsets2parents(tmp._starts.base)

index = self.JaggedArray(tmp._starts, tmp._stops, (self.numpy.arange(tmp._stops[-1], dtype=self.INDEXTYPE) - tmp._starts[tmpparents]))

data = data.compact()
return self.copy(content=data._content[self.IndexedArray.invert((self.index + self._starts)._content)])
return self.copy(content=data._content[self.IndexedArray.invert((index + self._starts)._content)])

elif isinstance(data, awkward.array.base.AwkwardArray):
if len(self._starts) != len(data):
Expand Down Expand Up @@ -842,7 +854,7 @@ def _tojagged(self, starts=None, stops=None, copy=True):
if self.offsetsaliased(starts, stops):
parents = self.offsets2parents(starts.base)
elif len(starts.shape) == 1 and self.numpy.array_equal(starts[1:], stops[:-1]):
if len(self._stops) == 0:
if len(stops) == 0:
offsets = self.numpy.array([0], dtype=self.INDEXTYPE)
else:
offsets = self.numpy.append(starts, stops[-1])
Expand Down
2 changes: 1 addition & 1 deletion awkward/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import re

__version__ = "0.8.9"
__version__ = "0.8.10"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit eb7ff85

Please sign in to comment.