Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: auto-cancel & blacken-docs #502

Merged
merged 6 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
env:
FORCE_COLOR: 3

concurrency:
group: ${ github.workflow }-${ github.head_ref }
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ repos:
hooks:
- id: black-jupyter

- repo: https://github.com/asottile/blacken-docs
rev: "1.13.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.1.0]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ from hist import Hist

# Quick construction, no other imports needed:
h = (
Hist.new
.Reg(10, 0 ,1, name="x", label="x-axis")
.Var(range(10), name="y", label="y-axis")
.Int64()
Hist.new.Reg(10, 0, 1, name="x", label="x-axis")
.Var(range(10), name="y", label="y-axis")
.Int64()
)

# Filling by names is allowed:
Expand All @@ -111,7 +110,7 @@ h.project("x")
h[{"y": 0.5j + 3, "x": 5j}]

# You can access data coordinates or rebin with a `j` suffix:
h[.3j:, ::2j] # x from .3 to the end, y is rebinned by 2
h[0.3j:, ::2j] # x from .3 to the end, y is rebinned by 2

# Elegant plotting functions:
h.plot()
Expand Down
11 changes: 5 additions & 6 deletions docs/banner_slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ Converted to GIF with ezgif.com, 300 ms delay time.
import hist

# Make a histogram
h = hist.Hist(
hist.axes.Regular(10, 0, 1, name="x")
)
h = hist.Hist(hist.axes.Regular(10, 0, 1, name="x"))

# Fill it with events
h.fill(x=[.2, .3, .6, .9])
h.fill(x=[0.2, 0.3, 0.6, 0.9])

# Compute the sum
total = h.sum()
Expand All @@ -36,7 +34,7 @@ from hist import Hist
h = Hist.new.Reg(10, 0, 1, name="x").Double()

# Fill it with events
h.fill(x=[.2, .3, .6, .9])
h.fill(x=[0.2, 0.3, 0.6, 0.9])

# Compute the sum
total = h.sum()
Expand Down Expand Up @@ -66,7 +64,7 @@ total = h.sum()

```python
# Slice in data coordinates
sliced_h = h[.5j:1.5j]
sliced_h = h[0.5j:1.5j]

# Sum over and rebin easily
smaller_1d = h_2d[sum, 2j]
Expand Down Expand Up @@ -137,6 +135,7 @@ Supports the UHI `PlottableHistogram` protocol!

```python
import mplhep

mplhep.histplot(h)
```

Expand Down
11 changes: 8 additions & 3 deletions docs/user-guide/axes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,25 @@ One use for an IntCategory axis is for an IntEnum:

import enum


class MyEnum(enum.IntEnum):
a = 1
b = 5


my_enum_axis = hist.axis.IntEnum(list(MyEnum), underflow=False, overflow=False)


You can sort the Categorty axes via ``.sort()`` method:

.. code-block:: python3

h = Hist(axis.IntCategory([3, 1, 2], label="Number"), axis.StrCategory(["Teacher", "Police", "Artist"], label="Profession"))
h.sort(0).axes[0] # IntCategory([1, 2, 3], label='Number')
h.sort(1, reverse=True).axes[1] # StrCategory(['Teacher', 'Police', 'Artist'], label='Profession')
h = Hist(
axis.IntCategory([3, 1, 2], label="Number"),
axis.StrCategory(["Teacher", "Police", "Artist"], label="Profession"),
)
# Sort Number axis increasing and Profession axis decreasing
h1 = h.sort("Number").sort("Profession", reverse=True)


.. py:function:: hist.axis.StrCategory([str1, ...], name, label, metadata="", growth=False)
Expand Down
25 changes: 12 additions & 13 deletions docs/user-guide/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ If you try the following in an IPython session, you will get:
import numpy as np
import hist

norm_vals = np.concatenate([
np.random.normal(loc=5, scale=1, size=1_000_000),
np.random.normal(loc=2, scale=.2, size=200_000),
np.random.normal(loc=8, scale=.2, size=200_000),
])
norm_vals = np.concatenate(
[
np.random.normal(loc=5, scale=1, size=1_000_000),
np.random.normal(loc=2, scale=0.2, size=200_000),
np.random.normal(loc=8, scale=0.2, size=200_000),
]
)

.. code-block:: python3
.. code-block:: ipython

%%timeit
bins, edges = np.histogram(norm_vals, bins=100, range=(0, 10))
Expand All @@ -64,7 +66,7 @@ ND histograms. But if you already use NumPy histograms and you really
don’t want to rewrite your code, hist has adaptors for the
three histogram functions in NumPy:

.. code-block:: python3
.. code-block:: ipython

%%timeit
bins, edges = hist.numpy.histogram(norm_vals, bins=100, range=(0, 10))
Expand Down Expand Up @@ -95,15 +97,12 @@ So you can transition your code slowly to hist.

.. code-block:: python3

data = np.random.multivariate_normal(
(0, 0),
((1, 0),(0, .5)),
10_000_000).T.copy()
data = np.random.multivariate_normal((0, 0), ((1, 0), (0, 0.5)), 10_000_000).T.copy()

We can check the performance against NumPy again; NumPy does not do well
with regular spaced bins in more than 1D:

.. code-block:: python3
.. code-block:: ipython

%%timeit
np.histogram2d(*data, bins=(400, 200), range=((-2, 2), (-1, 1)))
Expand All @@ -112,7 +111,7 @@ with regular spaced bins in more than 1D:

1.31 s ± 17.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

.. code-block:: python3
.. code-block:: ipython

%%timeit
hist.numpy.histogram2d(*data, bins=(400, 200), range=((-2, 2), (-1, 1)))
Expand Down
5 changes: 2 additions & 3 deletions docs/user-guide/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ The exact same syntax is used any number of dimensions:
.. code-block:: python3

hist3D = (
Hist.new
.Regular(10, 0, 100, circular=True, name="x")
Hist.new.Regular(10, 0, 100, circular=True, name="x")
.Regular(10, 0.0, 10.0, name="y")
.Variable([1, 2, 3, 4, 5, 5.5, 6], name="z")
.Weight()
Expand Down Expand Up @@ -85,7 +84,7 @@ in the third slice entry, or remove an entire axis using ``sum``:
hist.axis.Regular(10, 0, 1, name="y"),
hist.axis.Regular(10, 0, 1, name="z"),
)
mini = h[1:5, .2j:.9j, sum]
mini = h[1:5, 0.2j:0.9j, sum]
# Will be 4 bins x 7 bins

See :ref:`usage-indexing`.
Expand Down
6 changes: 1 addition & 5 deletions docs/user-guide/storages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ non-integer fills for data that should represent raw, unweighed counts.
.. code-block:: python3

# Method 2
h = (
Hist.new.Reg(10, 0, 1, name="x")
.Int64()
.fill([0.5, 0.5])
)
h = Hist.new.Reg(10, 0, 1, name="x").Int64().fill([0.5, 0.5])

print(h[0.5j])

Expand Down
2 changes: 2 additions & 0 deletions docs/user-guide/subclassing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ When you subclass, you will need to add a family. Any object can be used - the m
import hist
import my_package


class Histogram(hist.Hist, family=my_package):
...


class Regular(hist.axis.Regular, family=my_package):
...

Expand Down