• Stars
    star
    832
  • Rank 54,811 (Top 2 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 5 years ago
  • Updated 22 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Manipulate JSON-like data with NumPy-like idioms.

PyPI version Conda-Forge Python 3.8‒3.12 BSD-3 Clause License Build Test

Scikit-HEP NSF-1836650 DOI Documentation Gitter

Awkward Array is a library for nested, variable-sized data, including arbitrary-length lists, records, mixed types, and missing data, using NumPy-like idioms.

Arrays are dynamically typed, but operations on them are compiled and fast. Their behavior coincides with NumPy when array dimensions are regular and generalizes when they're not.

Motivating example

Given an array of lists of objects with x, y fields (with nested lists in the y field),

import awkward as ak

array = ak.Array([
    [{"x": 1.1, "y": [1]}, {"x": 2.2, "y": [1, 2]}, {"x": 3.3, "y": [1, 2, 3]}],
    [],
    [{"x": 4.4, "y": [1, 2, 3, 4]}, {"x": 5.5, "y": [1, 2, 3, 4, 5]}]
])

the following slices out the y values, drops the first element from each inner list, and runs NumPy's np.square function on everything that is left:

output = np.square(array["y", ..., 1:])

The result is

[
    [[], [4], [4, 9]],
    [],
    [[4, 9, 16], [4, 9, 16, 25]]
]

The equivalent using only Python is

output = []
for sublist in array:
    tmp1 = []
    for record in sublist:
        tmp2 = []
        for number in record["y"][1:]:
            tmp2.append(np.square(number))
        tmp1.append(tmp2)
    output.append(tmp1)

The expression using Awkward Arrays is more concise, using idioms familiar from NumPy, and it also has NumPy-like performance. For a similar problem 10 million times larger than the one above (single-threaded on a 2.2 GHz processor),

  • the Awkward Array one-liner takes 1.5 seconds to run and uses 2.1 GB of memory,
  • the equivalent using Python lists and dicts takes 140 seconds to run and uses 22 GB of memory.

Awkward Array is even faster when used in Numba's JIT-compiled functions.

See the Getting started documentation on awkward-array.org for an introduction, including a no-install demo you can try in your web browser.

Getting help

Installation

Awkward Array can be installed from PyPI using pip:

pip install awkward

The awkward package is pure Python, and it will download the awkward-cpp compiled components as a dependency. If there is no awkward-cpp binary package (wheel) for your platform and Python version, pip will attempt to compile it from source (which has additional dependencies, such as a C++ compiler).

Awkward Array is also available on conda-forge:

conda install -c conda-forge awkward

Because of the two packages (awkward-cpp may be updated in GitHub but not on PyPI), pip install through git (pip install git+https://...) will not work. Instead, use the Installation for developers section below.

Installation for developers

Clone this repository recursively to get the header-only C++ dependencies, then generate sources with nox, compile and install awkward-cpp, and finally install awkward as an editable installation:

git clone --recursive https://github.com/scikit-hep/awkward.git
cd awkward

nox -s prepare
python -m pip install -v ./awkward-cpp
python -m pip install -e .

Tests can be run in parallel with pytest:

python -m pytest -n auto tests

For more details, see CONTRIBUTING.md, or one of the links below.

Documentation, Release notes, Roadmap, Citations

The documentation is on awkward-array.org, including

The Release notes for each version are in the GitHub Releases tab.

The Roadmap, Plans, and Deprecation Schedule are in the GitHub Wiki.

To cite Awkward Array in a paper, see the "Cite this repository" drop-down menu on the top-right of the GitHub front page. The BibTeX is

@software{Pivarski_Awkward_Array_2018,
author = {Pivarski, Jim and Osborne, Ianna and Ifrim, Ioana and Schreiner, Henry and Hollands, Angus and Biswas, Anish and Das, Pratyush and Roy Choudhury, Santam and Smith, Nicholas and Goyal, Manasvi},
doi = {10.5281/zenodo.4341376},
month = {10},
title = {{Awkward Array}},
year = {2018}
}

Acknowledgements

Support for this work was provided by NSF cooperative agreement OAC-1836650 (IRIS-HEP), grant OAC-1450377 (DIANA/HEP), PHY-2121686 (US-CMS LHC Ops), and OAC-2103945 (Awkward Array).

We also thank Erez Shinan and the developers of the Lark standalone parser, which is used to parse type strings as type objects.

Thanks especially to the gracious help of Awkward Array contributors (including the original repository).

Jim Pivarski
Jim Pivarski

💻 📖 🚇 🚧
Ianna Osborne
Ianna Osborne

💻
Pratyush Das
Pratyush Das

💻
Anish Biswas
Anish Biswas

💻
glass-ships
glass-ships

💻 ⚠️
Henry Schreiner
Henry Schreiner

💻 🚇
Nicholas Smith
Nicholas Smith

💻 ⚠️
Lindsey Gray
Lindsey Gray

💻 ⚠️
Ellipse0934
Ellipse0934

⚠️
Dmitry Kalinkin
Dmitry Kalinkin

🚇
Charles Escott
Charles Escott

💻
Mason Proffitt
Mason Proffitt

💻
Michael Hedges
Michael Hedges

💻
Jonas Rembser
Jonas Rembser

💻
Jaydeep Nandi
Jaydeep Nandi

💻
benkrikler
benkrikler

💻
bfis
bfis

💻
Doug Davis
Doug Davis

💻
Joosep Pata
Joosep Pata

🤔
Martin Durant
Martin Durant

🤔
Gordon Watts
Gordon Watts

🤔
Nikolai Hartmann
Nikolai Hartmann

💻
Simon Perkins
Simon Perkins

💻
.hard
.hard

💻 ⚠️
HenryDayHall
HenryDayHall

💻
Angus Hollands
Angus Hollands

⚠️ 💻
ioanaif
ioanaif

💻 ⚠️
Bernhard M. Wiedemann
Bernhard M. Wiedemann

🚧
Matthew Feickert
Matthew Feickert

🚧
Santam Roy Choudhury
Santam Roy Choudhury

⚠️
Jeroen Van Goey
Jeroen Van Goey

📖
Ahmad-AlSubaie
Ahmad-AlSubaie

💻
Manasvi Goyal
Manasvi Goyal

💻
Aryan Roy
Aryan Roy

💻
Saransh
Saransh

💻
Laurits Tani
Laurits Tani

📖
Daniel Savoiu
Daniel Savoiu

💻
Ray Bell
Ray Bell

📖

💻: code, 📖: documentation, 🚇: infrastructure, 🚧: maintenance, ⚠: tests and feedback, 🤔: foundational ideas.

More Repositories

1

uproot3

ROOT I/O in pure Python and NumPy.
Python
315
star
2

iminuit

Jupyter-friendly Python interface for C++ MINUIT2
Python
280
star
3

pyhf

pure-Python HistFactory implementation with tensors and autodiff
Python
251
star
4

uproot5

ROOT I/O in pure Python and NumPy.
Python
234
star
5

awkward-0.x

Manipulate arrays of complex data structures as easily as Numpy.
Python
215
star
6

mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
Python
188
star
7

scikit-hep

Metapackage of Scikit-HEP project data analysis packages for Particle Physics.
Python
163
star
8

particle

Package to deal with particles, the PDG particle data table, PDGIDs, etc.
Python
149
star
9

boost-histogram

Python bindings for the C++14 Boost::Histogram library
Jupyter Notebook
143
star
10

root_numpy

The interface between ROOT and NumPy
Python
131
star
11

hist

Histogramming for analysis powered by boost-histogram
Python
127
star
12

root_pandas

A Python module for conveniently loading/saving ROOT files as pandas DataFrames
Python
109
star
13

histbook

Versatile, high-performance histogram toolkit for Numpy.
Jupyter Notebook
108
star
14

vector

Vector classes and utilities
Python
79
star
15

resample

Randomization-based inference in Python
Python
73
star
16

uproot-browser

A TUI viewer for ROOT files
Python
69
star
17

hepstats

Statistics tools and utilities.
Python
66
star
18

probfit

Cost function builder. For fitting distributions.
Jupyter Notebook
50
star
19

pylhe

Lightweight Python interface to read Les Houches Event (LHE) files
Python
39
star
20

decaylanguage

Package to parse decay files, describe and convert particle decays between digital representations.
Jupyter Notebook
38
star
21

vegascope

View Vega/Vega-Lite plots in your web browser from local or remote Python processes.
Python
36
star
22

numpythia

The interface between PYTHIA and NumPy
Cython
36
star
23

pyjet

The interface between FastJet and NumPy
C++
33
star
24

histoprint

Pretty print histograms to the console
Python
32
star
25

ragged

Manipulating ragged arrays in an Array API compliant way.
Python
29
star
26

cabinetry

design and steer profile likelihood fits
Python
25
star
27

fastjet

Jet-finding in the Scikit-HEP ecosystem.
Python
21
star
28

uproot3-methods

Pythonic behaviors for non-I/O related ROOT classes.
Python
21
star
29

hepunits

Units and constants in the HEP system of units
Python
21
star
30

pyhepmc

Easy-to-use Python bindings for HepMC3
Python
20
star
31

aghast

Aghast: aggregated, histogram-like statistics, sharable as Flatbuffers.
Python
17
star
32

scikit-hep-testdata

A common package to provide example files (e.g., ROOT) for testing and developing packages against.
C
13
star
33

formulate

Easy conversions between different styles of expressions
Python
12
star
34

scikit-hep.github.io

Pages defining the website of the Scikit-HEP project.
HTML
11
star
35

pyBumpHunter

Python implementation of the BumpHunter algorithm used by HEP community.
Jupyter Notebook
11
star
36

hepconvert

Python
11
star
37

uhi

Universal Histogram Interface
Python
9
star
38

scikit-hep-tutorials

Ecosystem tutorials, demos, examples
Jupyter Notebook
8
star
39

azure-wheel-helpers

Please use cibuildwheel instead!
Shell
8
star
40

NNDrone

Collection of tools and algorithms to enable conversion of HEP ML to mass usage model
Python
6
star
41

cuda-histogram

Histogramming tools on CUDA.
Python
6
star
42

scikit-hep-orgstats

Stats gathering tools for SciKit-HEP PyPI releases
Jupyter Notebook
3
star
43

manylinuxgcc

ManyLinux1 with modern GCC
Dockerfile
2
star
44

scikit-hep.github.io-source

Old sources for the Scikit-HEP org website pages.
Python
1
star