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 #6 from scikit-hep/finish-implementation
Browse files Browse the repository at this point in the history
First 0.1.x release: jagged, table, object, indexed, and chunked are done
  • Loading branch information
jpivarski authored Oct 4, 2018
2 parents 9232d92 + 4a1a98a commit cbde2d2
Show file tree
Hide file tree
Showing 19 changed files with 2,268 additions and 969 deletions.
7 changes: 4 additions & 3 deletions awkward/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from awkward.array.chunked import ChunkedArray, PartitionedArray, AppendableArray
from awkward.array.indexed import IndexedArray, ByteIndexedArray, IndexedMaskedArray, UnionArray
from awkward.array.chunked import ChunkedArray, AppendableArray
from awkward.array.indexed import IndexedArray, ByteIndexedArray, IndexedMaskedArray
from awkward.array.jagged import JaggedArray, ByteJaggedArray
from awkward.array.masked import MaskedArray, BitMaskedArray
from awkward.array.objects import Methods, ObjectArray
from awkward.array.sparse import SparseArray
from awkward.array.table import Table
from awkward.array.union import UnionArray
from awkward.array.virtual import VirtualArray

from awkward.generate import fromiter

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

__all__ = ["ChunkedArray", "PartitionedArray", "AppendableArray", "IndexedArray", "ByteIndexedArray", "IndexedMaskedArray", "UnionArray", "JaggedArray", "ByteJaggedArray", "MaskedArray", "BitMaskedArray", "ObjectArray", "SparseArray", "Table", "VirtualArray", "fromiter", "__version__"]
__all__ = ["ChunkedArray", "AppendableArray", "IndexedArray", "ByteIndexedArray", "IndexedMaskedArray", "JaggedArray", "ByteJaggedArray", "MaskedArray", "BitMaskedArray", "Methods", "ObjectArray", "SparseArray", "Table", "UnionArray", "VirtualArray", "fromiter", "__version__"]
21 changes: 13 additions & 8 deletions awkward/array/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import numpy

import awkward.util

class AwkwardArray(awkward.util.NDArrayOperatorsMixin):
Expand All @@ -42,11 +40,9 @@ def __iter__(self):

def __str__(self):
if len(self) <= 6:
return "[{0}]".format(" ".join(str(x) if isinstance(x, (numpy.ndarray, AwkwardArray)) else repr(x) for x in self))
return "[{0}]".format(" ".join(awkward.util.array_str(x) for x in self))
else:
return "[{0} ... {1}]".format(
" ".join(str(x) if isinstance(x, (numpy.ndarray, AwkwardArray)) else repr(x) for x in self[:3]),
", ".join(str(x) if isinstance(x, (numpy.ndarray, AwkwardArray)) else repr(x) for x in self[-3:]))
return "[{0} ... {1}]".format(" ".join(awkward.util.array_str(x) for x in self[:3]), " ".join(awkward.util.array_str(x) for x in self[-3:]))

def __repr__(self):
return "<{0} {1} at {2:012x}>".format(self.__class__.__name__, str(self), id(self))
Expand All @@ -62,14 +58,23 @@ def __getattr__(self, where):
return self[where[1:]]
else:
raise AttributeError("'{0}' object has no attribute '{1}'".format(self.__class__.__name__, where))


def __bool__(self):
raise ValueError("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()")

__nonzero__ = __bool__

@property
def jshape(self):
return self.type.jshape

def tolist(self):
import awkward.array.table
out = []
for x in self:
if isinstance(x, awkward.array.table.Table.Row):
out.append(dict((n, self._try_tolist(x[n])) for n in x._table._content))
elif isinstance(x, numpy.ma.core.MaskedConstant):
elif isinstance(x, awkward.util.numpy.ma.core.MaskedConstant):
out.append(None)
else:
out.append(self._try_tolist(x))
Expand Down
Loading

0 comments on commit cbde2d2

Please sign in to comment.