Skip to content

Commit 226bc53

Browse files
committed
Fixed PEP8 issues in docstrings
Signed-off-by: Fabian Haase <[email protected]>
1 parent 8325caf commit 226bc53

File tree

5 files changed

+60
-50
lines changed

5 files changed

+60
-50
lines changed

doc/source/enhancingperf.rst

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ advanced Cython techniques:
298298
299299
Even faster, with the caveat that a bug in our Cython code (an off-by-one error,
300300
for example) might cause a segfault because memory access isn't checked.
301-
For more about ``boundscheck`` and ``wraparound``, see the Cython docs on
301+
For more about ``boundscheck`` and ``wraparound``, see the Cython docs on
302302
`compiler directives <http://cython.readthedocs.io/en/latest/src/reference/compilation.html?highlight=wraparound#compiler-directives>`__.
303303

304304
.. _enhancingperf.numba:
@@ -323,7 +323,7 @@ Numba works by generating optimized machine code using the LLVM compiler infrast
323323
Jit
324324
~~~
325325

326-
We demonstrate how to use Numba to just-in-time compile our code. We simply
326+
We demonstrate how to use Numba to just-in-time compile our code. We simply
327327
take the plain Python code from above and annotate with the ``@jit`` decorator.
328328

329329
.. code-block:: python
@@ -332,35 +332,38 @@ take the plain Python code from above and annotate with the ``@jit`` decorator.
332332
333333
@numba.jit
334334
def f_plain(x):
335-
return x * (x - 1)
335+
return x * (x - 1)
336+
336337
337338
@numba.jit
338339
def integrate_f_numba(a, b, N):
339-
s = 0
340-
dx = (b - a) / N
341-
for i in range(N):
342-
s += f_plain(a + i * dx)
343-
return s * dx
340+
s = 0
341+
dx = (b - a) / N
342+
for i in range(N):
343+
s += f_plain(a + i * dx)
344+
return s * dx
345+
344346
345347
@numba.jit
346348
def apply_integrate_f_numba(col_a, col_b, col_N):
347-
n = len(col_N)
348-
result = np.empty(n, dtype='float64')
349-
assert len(col_a) == len(col_b) == n
350-
for i in range(n):
351-
result[i] = integrate_f_numba(col_a[i], col_b[i], col_N[i])
352-
return result
349+
n = len(col_N)
350+
result = np.empty(n, dtype='float64')
351+
assert len(col_a) == len(col_b) == n
352+
for i in range(n):
353+
result[i] = integrate_f_numba(col_a[i], col_b[i], col_N[i])
354+
return result
355+
353356
354357
def compute_numba(df):
355-
result = apply_integrate_f_numba(df['a'].values, df['b'].values, df['N'].values)
356-
return pd.Series(result, index=df.index, name='result')
358+
result = apply_integrate_f_numba(df['a'].values, df['b'].values,
359+
df['N'].values)
360+
return pd.Series(result, index=df.index, name='result')
357361
358-
Note that we directly pass NumPy arrays to the Numba function. ``compute_numba`` is just a wrapper that provides a nicer interface by passing/returning pandas objects.
362+
Note that we directly pass NumPy arrays to the Numba function. ``compute_numba`` is just a wrapper that provides a
363+
nicer interface by passing/returning pandas objects.
359364

360-
.. code-block:: ipython
361-
362-
In [4]: %timeit compute_numba(df)
363-
1000 loops, best of 3: 798 us per loop
365+
>>> %timeit compute_numba(df)
366+
1000 loops, best of 3: 798 us per loop
364367

365368
In this example, using Numba was faster than Cython.
366369

@@ -376,24 +379,25 @@ Consider the following toy example of doubling each observation:
376379
import numba
377380
378381
def double_every_value_nonumba(x):
379-
return x*2
382+
return x * 2
383+
380384
381385
@numba.vectorize
382386
def double_every_value_withnumba(x):
383-
return x*2
387+
return x * 2
384388
385389
386-
# Custom function without numba
387-
In [5]: %timeit df['col1_doubled'] = df.a.apply(double_every_value_nonumba)
388-
1000 loops, best of 3: 797 us per loop
390+
>>> # Custom function without numba
391+
>>> %timeit df['col1_doubled'] = df.a.apply(double_every_value_nonumba)
392+
1000 loops, best of 3: 797 us per loop
389393

390-
# Standard implementation (faster than a custom function)
391-
In [6]: %timeit df['col1_doubled'] = df.a*2
392-
1000 loops, best of 3: 233 us per loop
394+
>>> # Standard implementation (faster than a custom function)
395+
>>> %timeit df['col1_doubled'] = df.a*2
396+
1000 loops, best of 3: 233 us per loop
393397

394-
# Custom function with numba
395-
In [7]: %timeit df['col1_doubled'] = double_every_value_withnumba(df.a.values)
396-
1000 loops, best of 3: 145 us per loop
398+
>>> # Custom function with numba
399+
>>> %timeit df['col1_doubled'] = double_every_value_withnumba(df.a.values)
400+
1000 loops, best of 3: 145 us per loop
397401

398402
Caveats
399403
~~~~~~~
@@ -402,18 +406,18 @@ Caveats
402406

403407
Numba will execute on any function, but can only accelerate certain classes of functions.
404408

405-
Numba is best at accelerating functions that apply numerical functions to NumPy
406-
arrays. When passed a function that only uses operations it knows how to
409+
Numba is best at accelerating functions that apply numerical functions to NumPy
410+
arrays. When passed a function that only uses operations it knows how to
407411
accelerate, it will execute in ``nopython`` mode.
408412

409-
If Numba is passed a function that includes something it doesn't know how to
410-
work with -- a category that currently includes sets, lists, dictionaries, or
411-
string functions -- it will revert to ``object mode``. In ``object mode``,
412-
Numba will execute but your code will not speed up significantly. If you would
413-
prefer that Numba throw an error if it cannot compile a function in a way that
414-
speeds up your code, pass Numba the argument
415-
``nopython=True`` (e.g. ``@numba.jit(nopython=True)``). For more on
416-
troubleshooting Numba modes, see the `Numba troubleshooting page
413+
If Numba is passed a function that includes something it doesn't know how to
414+
work with -- a category that currently includes sets, lists, dictionaries, or
415+
string functions -- it will revert to ``object mode``. In ``object mode``,
416+
Numba will execute but your code will not speed up significantly. If you would
417+
prefer that Numba throw an error if it cannot compile a function in a way that
418+
speeds up your code, pass Numba the argument
419+
``nopython=True`` (e.g. ``@numba.jit(nopython=True)``). For more on
420+
troubleshooting Numba modes, see the `Numba troubleshooting page
417421
<http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#the-compiled-code-is-too-slow>`__.
418422

419423
Read more in the `Numba docs <http://numba.pydata.org/>`__.

doc/source/reshaping.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ For the curious here is how the above ``DataFrame`` was created:
4848
import pandas.util.testing as tm; tm.N = 3
4949
def unpivot(frame):
5050
N, K = frame.shape
51-
data = {'value' : frame.values.ravel('F'),
52-
'variable' : np.asarray(frame.columns).repeat(N),
53-
'date' : np.tile(np.asarray(frame.index), K)}
51+
data = {'value': frame.values.ravel('F'),
52+
'variable': np.asarray(frame.columns).repeat(N),
53+
'date': np.tile(np.asarray(frame.index), K)}
5454
return pd.DataFrame(data, columns=['date', 'variable', 'value'])
55+
56+
5557
df = unpivot(tm.makeTimeDataFrame())
5658
5759
To select out everything for variable ``A`` we could do:

doc/source/timeseries.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ custom date increment logic, such as adding business days:
898898
.. code-block:: python
899899
900900
class BDay(DateOffset):
901-
"""DateOffset increments between business days"""
901+
"""DateOffset increments between business days"""
902902
def apply(self, other):
903903
...
904904
@@ -2133,7 +2133,8 @@ To convert from an ``int64`` based YYYYMMDD representation.
21332133
s
21342134
21352135
def conv(x):
2136-
return pd.Period(year = x // 10000, month = x//100 % 100, day = x%100, freq='D')
2136+
return pd.Period(year=x // 10000, month=x // 100 % 100,
2137+
day=x % 100, freq='D')
21372138
21382139
s.apply(conv)
21392140
s.apply(conv)[2]

pandas/core/missing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,10 @@ def _interp_limit(invalid, fw_limit, bw_limit):
760760
761761
.. code-block:: python
762762
763-
for x in np.where(invalid)[0]:
764-
if invalid[max(0, x - fw_limit):x + bw_limit + 1].all():
765-
yield x
763+
def _interp_limit(invalid, fw_limit, bw_limit):
764+
for x in np.where(invalid)[0]:
765+
if invalid[max(0, x - fw_limit):x + bw_limit + 1].all():
766+
yield x
766767
"""
767768
# handle forward first; the backward direction is the same except
768769
# 1. operate on the reversed array

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ exclude =
3535
bootstrap =
3636
import pandas as pd
3737
import numpy as np
38+
ignore =
39+
F821, # undefined name
3840

3941
[yapf]
4042
based_on_style = pep8

0 commit comments

Comments
 (0)