Skip to content

Commit eab787b

Browse files
committed
Merge remote-tracking branch 'upstream/main' into sphinx-fix
2 parents 841ddc7 + 1da0d02 commit eab787b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/source/user_guide/enhancingperf.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ We have a :class:`DataFrame` to which we want to apply a function row-wise.
5050
{
5151
"a": np.random.randn(1000),
5252
"b": np.random.randn(1000),
53-
"N": np.random.randint(100, 1000, (1000)),
53+
"N": np.random.randint(100, 1000, (1000), dtype="int64"),
5454
"x": "x",
5555
}
5656
)
@@ -84,7 +84,7 @@ using the `prun ipython magic function <https://ipython.readthedocs.io/en/stable
8484
:okexcept:
8585
8686
# most time consuming 4 calls
87-
%prun -l 4 df.apply(lambda x: integrate_f(x["a"], x["b"], x["N"]), axis=1) # noqa E999
87+
%prun -l 4 df.apply(lambda x: integrate_f(x['a'], x['b'], x['N']), axis=1)
8888
8989
By far the majority of time is spend inside either ``integrate_f`` or ``f``,
9090
hence we'll concentrate our efforts cythonizing these two functions.
@@ -166,7 +166,7 @@ can be improved by passing an ``np.ndarray``.
166166
.. ipython:: python
167167
:okexcept:
168168
169-
%prun -l 4 df.apply(lambda x: integrate_f_typed(x["a"], x["b"], x["N"]), axis=1)
169+
%prun -l 4 df.apply(lambda x: integrate_f_typed(x['a'], x['b'], x['N']), axis=1)
170170
171171
.. ipython::
172172

@@ -207,7 +207,7 @@ calls are needed to utilize this function.
207207
.. ipython:: python
208208
:okexcept:
209209
210-
%timeit apply_integrate_f(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy())
210+
%timeit apply_integrate_f(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy())
211211
212212
Performance has improved from the prior implementation by almost ten times.
213213

@@ -222,7 +222,7 @@ and ``wraparound`` checks can yield more performance.
222222
.. ipython:: python
223223
:okexcept:
224224
225-
%prun -l 4 apply_integrate_f(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy())
225+
%prun -l 4 apply_integrate_f(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy())
226226
227227
.. ipython::
228228

@@ -258,7 +258,7 @@ and ``wraparound`` checks can yield more performance.
258258
.. ipython:: python
259259
:okexcept:
260260
261-
%timeit apply_integrate_f_wrap(df["a"].to_numpy(), df["b"].to_numpy(), df["N"].to_numpy())
261+
%timeit apply_integrate_f_wrap(df['a'].to_numpy(), df['b'].to_numpy(), df['N'].to_numpy())
262262
263263
However, a loop indexer ``i`` accessing an invalid location in an array would cause a segfault because memory access isn't checked.
264264
For more about ``boundscheck`` and ``wraparound``, see the Cython docs on

0 commit comments

Comments
 (0)