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

Commit

Permalink
Showing 11 changed files with 546 additions and 107 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -36,16 +36,19 @@ addons:
- python-setuptools

script:
python setup.py pytest
pytest -v tests

install:
- pip install --upgrade setuptools_scm
- pip install $NUMPY
- if [[ $TRAVIS_PYTHON_VERSION = pypy* ]] ; then pip install "numpy<1.16.0" ; fi # FIXME: pypy bug in numpy
- python -c 'import numpy; print(numpy.__version__)'
- pip install pytest pytest-runner
- if [[ $TRAVIS_PYTHON_VERSION != pypy* ]] ; then pip install h5py ; fi
- if [[ $TRAVIS_PYTHON_VERSION != pypy* ]] ; then pip install h5py pyarrow ; fi
- if [[ $TRAVIS_PYTHON_VERSION != pypy* ]] ; then pip install numba ; ln -s ../awkward-numba/awkward/numba awkward/numba ; fi
- pip install uproot-methods
- python -c 'import uproot_methods; print(uproot_methods.__version__)'
- python -c 'import awkward; print(awkward.__version__)'
- export AWKWARD_DEPLOYMENT=base
- pip install --upgrade pyOpenSSL # for deployment

6 changes: 4 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -45,5 +45,7 @@ install:

build_script:
- "pip install %NUMPY%"
- "pip install pytest pytest-runner h5py"
- "python setup.py pytest"
- "pip install pytest pytest-runner h5py uproot-methods"
- "python -c \"import uproot_methods; print(uproot_methods.__version__)\""
- "python -c \"import awkward; print(awkward.__version__)\""
- "pytest -v tests"
4 changes: 3 additions & 1 deletion awkward/__init__.py
Original file line number Diff line number Diff line change
@@ -47,9 +47,11 @@

from awkward.persist import serialize, deserialize, save, load, hdf5

from awkward.arrow import toarrow, fromarrow, toparquet, fromparquet

# convenient access to the version number
from awkward.version import __version__

__all__ = ["numpy", "ChunkedArray", "AppendableArray", "IndexedArray", "SparseArray", "JaggedArray", "MaskedArray", "BitMaskedArray", "IndexedMaskedArray", "Methods", "ObjectArray", "Table", "UnionArray", "VirtualArray", "StringArray", "fromiter", "fromiterchunks", "serialize", "deserialize", "save", "load", "hdf5", "__version__"]
__all__ = ["numpy", "ChunkedArray", "AppendableArray", "IndexedArray", "SparseArray", "JaggedArray", "MaskedArray", "BitMaskedArray", "IndexedMaskedArray", "Methods", "ObjectArray", "Table", "UnionArray", "VirtualArray", "StringArray", "fromiter", "fromiterchunks", "serialize", "deserialize", "save", "load", "hdf5", "toarrow", "fromarrow", "toparquet", "fromparquet", "__version__"]

__path__ = __import__("pkgutil").extend_path(__path__, __name__)
27 changes: 27 additions & 0 deletions awkward/array/jagged.py
Original file line number Diff line number Diff line change
@@ -1123,6 +1123,33 @@ def _canuseoffset(self):
self._valid()
return self.offsetsaliased(self._starts, self._stops) or (len(self._starts.shape) == 1 and self.numpy.array_equal(self._starts[1:], self._stops[:-1]))

@property
def iscompact(self):
if len(self._starts) == 0:
return True
else:
flatstarts = self._starts.reshape(-1)
flatstops = self.stops.reshape(-1) # no underscore!
if not self.offsetsaliased(self._starts, self._stops) and not self.numpy.array_equal(flatstarts[1:], flatstops[:-1]):
return False
if not self._isvalid and not (flatstops >= flatstarts).all():
raise ValueError("offsets must be monatonically increasing")
return True

def compact(self):
if self.iscompact:
return self
else:
offsets = self.counts2offsets(self.counts.reshape(-1))
if len(self._starts.shape) == 1:
tmp = self
else: # no underscore!
tmp = self.JaggedArray(self._starts.reshape(-1), self.stops.reshape(-1), self._content)
out = tmp._tojagged(offsets[:-1], offsets[1:], copy=False)
out.starts.shape = self._starts.shape
out.stops.shape = self._starts.shape # intentional: self._stops can too long
return out

def flatten(self, axis=0):
if not self._util_isinteger(axis) or axis < 0:
raise TypeError("axis must be a non-negative integer (can't count from the end)")
26 changes: 26 additions & 0 deletions awkward/array/objects.py
Original file line number Diff line number Diff line change
@@ -568,3 +568,29 @@ def __getitem__(self, where):
else:
out = self._content[where]
return self.__class__(out.starts, out.stops, out.content, self.encoding)

@property
def iscompact(self):
return self._content.iscompact

def compact(self):
return self.fromjagged(self._content.compact(), self.encoding)

def flatten(self):
return self.fromjagged(self._content.flatten(), self.encoding)

@awkward.util.bothmethod
def concatenate(isclassmethod, cls_or_self, arrays, axis=0):
if isclassmethod:
cls = cls_or_self
if not all(isinstance(x, StringArray) for x in arrays):
raise TypeError("cannot concatenate non-StringArrays with StringArray.concatenate")
else:
self = cls_or_self
cls = self.__class__
if not isinstance(self, StringArray) or not all(isinstance(x, StringArray) for x in arrays):
raise TypeError("cannot concatenate non-StringArrays with StringArrays.concatenate")
arrays = (self,) + tuple(arrays)

jagged = self.JaggedArray.concatenate([x._content for x in arrays], axis=axis)
return self.fromjagged(jagged, self.encoding)
16 changes: 16 additions & 0 deletions awkward/array/union.py
Original file line number Diff line number Diff line change
@@ -121,7 +121,23 @@ def tags(self):
@tags.setter
def tags(self, value):
value = self._util_toarray(value, self.TAGTYPE, self.numpy.ndarray)
tagsmax = value.max()
if tagsmax <= self.numpy.iinfo(self.TAGTYPE).max:
value = value.astype(self.TAGTYPE)
elif tagsmax <= self.numpy.iinfo(self.numpy.uint8).max:
value = value.astype(self.numpy.uint8)
elif tagsmax <= self.numpy.iinfo(self.numpy.uint16).max:
value = value.astype(self.numpy.uint16)
elif tagsmax <= self.numpy.iinfo(self.numpy.uint32).max:
value = value.astype(self.numpy.uint32)
elif tagsmax <= self.numpy.iinfo(self.numpy.uint64).max:
value = value.astype(self.numpy.uint64)
else:
raise ValueError("maximum tag must be at most {0}".format(self.numpy.iinfo(self.numpy.uint64).max))

if self.check_prop_valid:
if len(value) == 0:
raise ValueError("tags must be non-empty")
if not self._util_isintegertype(value.dtype.type):
raise TypeError("tags must have integer dtype")
if (value < 0).any():
Loading

0 comments on commit 1681251

Please sign in to comment.