Skip to content

Commit 6071588

Browse files
committed
Fix highlighting of cells
1 parent 818c7b8 commit 6071588

File tree

9 files changed

+43
-41
lines changed

9 files changed

+43
-41
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373

7474
nbsphinx_execute = "never" # Can change to auto
7575

76+
highlight_language = "python3"
77+
7678
nbsphinx_execute_arguments = [
7779
"--InlineBackend.figure_formats={'png2x'}",
7880
"--InlineBackend.rc={'figure.dpi': 96}",

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Conda via `conda-forge <https://github.com/conda-forge/boost-histogram-feedstock
3131
All the normal best-practices for Python apply; you should be in a
3232
virtual environment, etc. See :ref:`usage-installation` for more details. An example of usage:
3333

34-
.. code:: python
34+
.. code:: python3
3535
3636
import boost_histogram as bh
3737

docs/usage/analyses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In a traditional analysis, you might bin over ``value`` where
2424
each run number. With boost-histogram, you can make a single histogram,
2525
and use an axis for each:
2626

27-
.. code:: python
27+
.. code:: python3
2828
2929
value_ax = bh.axis.Regular(100, -5, 5)
3030
bool_ax = bh.axis.Integer(0, 2, underflow=False, overflow=False)
@@ -34,7 +34,7 @@ Now, you can use these axes to create a single histogram that you can
3434
fill. If you want to get a histogram of all run numbers and just the
3535
True ``is_valid`` selection, you can use a ``sum``:
3636

37-
.. code:: python
37+
.. code:: python3
3838
3939
h1 = hist[:, True, ::bh.sum]
4040

docs/usage/axes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Integer axis
8585

8686
One common use for an integer axis could be a true/false axis:
8787

88-
.. code:: python
88+
.. code:: python3
8989
9090
bool_axis = bh.axis.Integer(0, 2, underflow=False, overflow=False)
9191
@@ -104,7 +104,7 @@ Category axis
104104

105105
One use for an IntCategory axis is for an IntEnum (Python 3):
106106

107-
.. code:: python
107+
.. code:: python3
108108
109109
import enum
110110

docs/usage/histogram.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Saving a Histogram
6262

6363
You can save a histogram using pickle:
6464

65-
.. code:: python
65+
.. code:: python3
6666
6767
import pickle
6868

docs/usage/indexing.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ implements UHI.
1919
Access:
2020
^^^^^^^
2121

22-
.. code:: python
22+
.. code:: python3
2323
2424
v = h[b] # Returns bin contents, indexed by bin number
2525
v = h[loc(b)] # Returns the bin containing the value
@@ -29,7 +29,7 @@ Access:
2929
Slicing:
3030
^^^^^^^^
3131

32-
.. code:: python
32+
.. code:: python3
3333
3434
h == h[:] # Slice over everything
3535
h2 = h[a:b] # Slice of histogram (includes flow bins)
@@ -46,7 +46,7 @@ Slicing:
4646
Setting
4747
^^^^^^^
4848

49-
.. code:: python
49+
.. code:: python3
5050
5151
# Single values
5252
h[b] = v # Returns bin contents, indexed by bin number
@@ -75,7 +75,7 @@ to run on an axis or a few axes out of many. For this use case, you can pass a
7575
dictionary to the index, and that has the syntax ``{axis:action}``. The actions
7676
are slices, and follow the rules listed above. This looks like:
7777

78-
.. code:: python
78+
.. code:: python3
7979
8080
h[{0: slice(None, None, bh.rebin(2))}] # rebin axis 0 by two
8181
h[{1: slice(0, bh.loc(3.5))}] # slice axis 1 from 0 to the data coordinate 3.5
@@ -85,7 +85,7 @@ are slices, and follow the rules listed above. This looks like:
8585
If you don't like manually building slices, you can use the `Slicer()` utility
8686
to recover the original slicing syntax inside the dict:
8787

88-
.. code:: python
88+
.. code:: python3
8989
9090
s = bh.tag.Slicer()
9191
@@ -98,7 +98,7 @@ to recover the original slicing syntax inside the dict:
9898
Invalid syntax:
9999
^^^^^^^^^^^^^^^
100100

101-
.. code:: python
101+
.. code:: python3
102102
103103
h[1.0] # Floats are not allowed, just like numpy
104104
h[::2] # Skipping is not (currently) supported
@@ -107,7 +107,7 @@ Invalid syntax:
107107
Rejected proposals or proposals for future consideration, maybe ``hist``-only:
108108
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109

110-
.. code:: python
110+
.. code:: python3
111111
112112
h2 = h[1.0j:2.5j + 1] # Adding a j suffix to a number could be used in place of `loc(x)`
113113
h2 = h[1.0] # Floats in place of `loc(x)`: too easy to make a mistake
@@ -118,7 +118,7 @@ Examples
118118

119119
For a histogram, the slice should be thought of like this:
120120

121-
.. code:: python
121+
.. code:: python3
122122
123123
histogram[start:stop:action]
124124
@@ -145,7 +145,7 @@ axis 3 should be summed over. You have a 4D histogram.
145145

146146
Solution:
147147

148-
.. code:: python
148+
.. code:: python3
149149
150150
ans = h[:20, bh.loc(-.5):bh.loc(1.5), ::bh.rebin(2), ::bh.sum]
151151
@@ -157,7 +157,7 @@ histogram.
157157

158158
Solution:
159159

160-
.. code:: python
160+
.. code:: python3
161161
162162
h[bh.loc(4.0):] = 0
163163
@@ -166,7 +166,7 @@ length as the range you give, or the same length as the range +
166166
under/overflows if the range is open ended (no limit given). For
167167
example:
168168

169-
.. code:: python
169+
.. code:: python3
170170
171171
h = bh.Histogram(bh.axis.Regular(10, 0, 1))
172172
h[:] = np.ones(10) # underflow/overflow still 0
@@ -184,7 +184,7 @@ leaving all other axes alone. You have an ND histogram, with N >= 2.
184184

185185
Solution:
186186

187-
.. code:: python
187+
.. code:: python3
188188
189189
ans = h[:, :bh.loc(2.4):bh.sum, ...]
190190
@@ -193,7 +193,7 @@ this case, was large or programmatically defined. In these cases, you
193193
can pass a dictionary of ``{axis:slice}`` into the indexing operation. A
194194
shortcut to quickly generate slices is provided, as well:
195195

196-
.. code:: python
196+
.. code:: python3
197197
198198
ans = h[{1: slice(None,bh.loc(2.4),bh.sum)}]
199199
@@ -208,7 +208,7 @@ You want the underflow bin of a 1D histogram.
208208

209209
Solution:
210210

211-
.. code:: python
211+
.. code:: python3
212212
213213
val = h1[bh.underflow]
214214
@@ -245,7 +245,7 @@ without the operators.
245245

246246
Basic implementation (WIP):
247247

248-
.. code:: python
248+
.. code:: python3
249249
250250
class loc:
251251
"When used in the start or stop of a Histogram's slice, x is taken to be the position in data coordinates."

docs/usage/numpy.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tuple, and ``threads=N`` to select a number of threads to fill with.
3636

3737
If you try the following in an IPython session, you will get:
3838

39-
.. code:: python
39+
.. code:: python3
4040
4141
import numpy as np
4242
import boost_histogram as bh
@@ -62,7 +62,7 @@ ND histograms. But if you already use Numpy histograms and you really
6262
don’t want to rewrite your code, boost-histogram has adaptors for the
6363
three histogram functions in Numpy:
6464

65-
.. code:: python
65+
.. code:: python3
6666
6767
%%timeit
6868
bins, edges = bh.numpy.histogram(norm_vals, bins=100, range=(0, 10))
@@ -75,13 +75,13 @@ This is only a hair slower than using the raw boost-histogram API,
7575
and is still a nice performance boost over Numpy. You can even use the
7676
Numpy syntax if you want a boost-histogram object later:
7777

78-
.. code:: python
78+
.. code:: python3
7979
8080
hist = bh.numpy.histogram(norm_vals, bins=100, range=(0, 10), histogram=bh.Histogram)
8181
8282
You can later get a Numpy style output tuple from a histogram object:
8383

84-
.. code:: python
84+
.. code:: python3
8585
8686
bins, edges = hist.to_numpy()
8787
@@ -91,7 +91,7 @@ So you can transition your code slowly to boost-histogram.
9191
2D Histogram example
9292
^^^^^^^^^^^^^^^^^^^^
9393

94-
.. code:: python
94+
.. code:: python3
9595
9696
data = np.random.multivariate_normal(
9797
(0, 0),
@@ -101,16 +101,16 @@ So you can transition your code slowly to boost-histogram.
101101
We can check the performance against Numpy again; Numpy does not do well
102102
with regular spaced bins in more than 1D:
103103

104-
.. code:: python
104+
.. code:: python3
105105
106106
%%timeit
107107
np.histogram2d(*data, bins=(400, 200), range=((-2, 2), (-1, 1)))
108108
109-
.. code::
109+
.. code:: text
110110
111111
1.31 s ± 17.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
112112
113-
.. code:: python
113+
.. code:: python3
114114
115115
%%timeit
116116
bh.numpy.histogram2d(*data, bins=(400, 200), range=((-2, 2), (-1, 1)))

docs/usage/quickstart.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Quickstart
55

66
All of the examples will assume the following import:
77

8-
.. code:: python
8+
.. code:: python3
99
1010
import boost_histogram as bh
1111
@@ -22,20 +22,20 @@ Making a histogram
2222

2323
You can make a histogram like this:
2424

25-
.. code:: python
25+
.. code:: python3
2626
2727
hist = bh.Histogram(bh.axis.Regular(bins=10, start=0, stop=1))
2828
2929
If you’d like to type less, you can leave out the keywords:
3030

31-
.. code:: python
31+
.. code:: python3
3232
3333
hist = bh.Histogram(bh.axis.Regular(10, 0, 1))
3434
3535
3636
The exact same syntax is used for 1D, 2D, and ND histograms:
3737

38-
.. code:: python
38+
.. code:: python3
3939
4040
hist3D = bh.Histogram(
4141
bh.axis.Regular(10, 0, 100, circular=True),
@@ -54,7 +54,7 @@ Filling a histogram
5454
Once you have a histogram, you can fill it using ``.fill``. Ideally, you
5555
should give arrays, but single values work as well:
5656

57-
.. code:: python
57+
.. code:: python3
5858
5959
hist = bh.Histogram(bh.axis.Regular(10, 0.0, 1.0))
6060
hist.fill(0.9)
@@ -69,7 +69,7 @@ or data coordinates using ``bh.loc(v)``. You can also
6969
rebin with ``bh.rebin(n)`` or remove an entire axis
7070
using ``bh.sum`` as the third slice argument:
7171

72-
.. code:: python
72+
.. code:: python3
7373
7474
hist = bh.Histogram(
7575
bh.axis.Regular(10, 0, 1),
@@ -90,7 +90,7 @@ Most methods like ``.view()`` offer an optional keyword
9090
argument that you can pass, ``flow=True``, to enable the under and
9191
overflow bins (disabled by default).
9292

93-
.. code:: python
93+
.. code:: python3
9494
9595
np_array = hist.view()
9696
@@ -101,7 +101,7 @@ Setting the contents
101101
You can set the contents directly as you would a Numpy array;
102102
you can set either values or arrays at a time:
103103

104-
.. code:: python
104+
.. code:: python3
105105
106106
hist[2] = 3.5
107107
hist[bh.underflow] = 0 # set the underflow bin
@@ -117,7 +117,7 @@ The axes are directly available in the histogram, and you can access
117117
a variety of properties, such as the ``edges`` or the ``centers``. All
118118
properties and methods are also available directly on the ``axes`` tuple:
119119

120-
.. code:: python
120+
.. code:: python3
121121
122122
ax0 = hist.axes[0]
123123
X, Y = hist.axes.centers
@@ -130,7 +130,7 @@ Saving Histograms
130130

131131
You can save histograms using pickle:
132132

133-
.. code:: python
133+
.. code:: python3
134134
135135
import pickle
136136

docs/usage/storage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ up to 53 bits of information (9 quadrillion) counts per cell, and supports
2121
weighted fills. It can also be scaled by a floating point values without making
2222
a copy.
2323

24-
.. code:: python
24+
.. code:: python3
2525
2626
h = bh.Histogram(bh.axis.Regular(10, 0, 1)) # Double() is the default
2727
h.fill([.2, .3], weight=[.5, 2]) # Weights are optional
@@ -47,7 +47,7 @@ A true integer storage is provided, as well; this storage has the ``np.uint64``
4747
datatype. This eventually should provide type safety by not accepting
4848
non-integer fills for data that should represent raw, unweighed counts.
4949

50-
.. code:: python
50+
.. code:: python3
5151
5252
h = bh.Histogram(bh.axis.Regular(10, 0, 1), storage=bh.storage.Int64())
5353
h.fill([.2, .3], weight=[1, 2]) # Integer weights supported

0 commit comments

Comments
 (0)