From 01e6c1bf11625b042dc97d86e549007350061e51 Mon Sep 17 00:00:00 2001 From: fabriceMUKARAGE Date: Thu, 8 Jun 2023 10:27:42 +0200 Subject: [PATCH 1/6] chore: adding blacken-docs --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a9004b8..6332000c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: From 103070130252746a140d224289352dd7813f4c71 Mon Sep 17 00:00:00 2001 From: Fabrice MUKARAGE <79330798+fabriceMUKARAGE@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:04:43 +0200 Subject: [PATCH 2/6] chore: add Auto-cancel --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76fe19b4..69280a80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From 2fd5d9f1d471625133187aae2ef781881708fcc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:24:18 +0000 Subject: [PATCH 3/6] style: pre-commit fixes --- README.md | 9 ++++----- docs/banner_slides.md | 11 +++++------ docs/user-guide/axes.rst | 13 ++++++++++--- docs/user-guide/quickstart.rst | 5 ++--- docs/user-guide/storages.rst | 6 +----- docs/user-guide/subclassing.rst | 2 ++ 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b51f1bb0..0732542a 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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() diff --git a/docs/banner_slides.md b/docs/banner_slides.md index 69a64bf1..40bdf7e3 100644 --- a/docs/banner_slides.md +++ b/docs/banner_slides.md @@ -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() @@ -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() @@ -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] @@ -137,6 +135,7 @@ Supports the UHI `PlottableHistogram` protocol! ```python import mplhep + mplhep.histplot(h) ``` diff --git a/docs/user-guide/axes.rst b/docs/user-guide/axes.rst index 8663d171..2ff8e2ea 100644 --- a/docs/user-guide/axes.rst +++ b/docs/user-guide/axes.rst @@ -184,10 +184,12 @@ 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) @@ -195,9 +197,14 @@ 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"), + ) + h.sort(0).axes[0] # IntCategory([1, 2, 3], label='Number') + h.sort(1, reverse=True).axes[ + 1 + ] # StrCategory(['Teacher', 'Police', 'Artist'], label='Profession') .. py:function:: hist.axis.StrCategory([str1, ...], name, label, metadata="", growth=False) diff --git a/docs/user-guide/quickstart.rst b/docs/user-guide/quickstart.rst index a0c57424..46349aa9 100644 --- a/docs/user-guide/quickstart.rst +++ b/docs/user-guide/quickstart.rst @@ -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() @@ -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`. diff --git a/docs/user-guide/storages.rst b/docs/user-guide/storages.rst index aceba98b..f6ed62fb 100644 --- a/docs/user-guide/storages.rst +++ b/docs/user-guide/storages.rst @@ -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]) diff --git a/docs/user-guide/subclassing.rst b/docs/user-guide/subclassing.rst index 46204bb0..3de36686 100644 --- a/docs/user-guide/subclassing.rst +++ b/docs/user-guide/subclassing.rst @@ -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): ... From bdf4effc208954aeafd8e3763f7bc54ad6217a74 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 9 Jun 2023 10:32:26 -0400 Subject: [PATCH 4/6] Update docs/user-guide/axes.rst --- docs/user-guide/axes.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/axes.rst b/docs/user-guide/axes.rst index 2ff8e2ea..2cf32deb 100644 --- a/docs/user-guide/axes.rst +++ b/docs/user-guide/axes.rst @@ -201,10 +201,8 @@ You can sort the Categorty axes via ``.sort()`` method: 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') + # 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) From 1b3eadbdab1b086f725b638a110a094989a000cb Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 9 Jun 2023 10:37:34 -0400 Subject: [PATCH 5/6] docs: fix lexer for ipython --- docs/user-guide/numpy.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/numpy.rst b/docs/user-guide/numpy.rst index 16533405..62d18a65 100644 --- a/docs/user-guide/numpy.rst +++ b/docs/user-guide/numpy.rst @@ -47,7 +47,7 @@ If you try the following in an IPython session, you will get: np.random.normal(loc=8, scale=.2, size=200_000), ]) -.. code-block:: python3 +.. code-block:: ipython %%timeit bins, edges = np.histogram(norm_vals, bins=100, range=(0, 10)) @@ -64,7 +64,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)) @@ -103,7 +103,7 @@ So you can transition your code slowly to hist. 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))) @@ -112,7 +112,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))) From 36b32f7a3b952d47ec9596672f03bb54ffdbaecd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:37:48 +0000 Subject: [PATCH 6/6] style: pre-commit fixes --- docs/user-guide/numpy.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/user-guide/numpy.rst b/docs/user-guide/numpy.rst index 62d18a65..7212c54e 100644 --- a/docs/user-guide/numpy.rst +++ b/docs/user-guide/numpy.rst @@ -41,11 +41,13 @@ 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:: ipython @@ -95,10 +97,7 @@ 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: