Skip to content

Commit 472df59

Browse files
committed
Fixing PEP8 issues within code-blocks
1 parent 226bc53 commit 472df59

7 files changed

+71
-76
lines changed

doc/source/10min.rst

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ a default integer index:
4545

4646
.. ipython:: python
4747
48-
s = pd.Series([1,3,5,np.nan,6,8])
48+
s = pd.Series([1, 3, 5, np.nan, 6, 8])
4949
s
5050
5151
Creating a :class:`DataFrame` by passing a NumPy array, with a datetime index
@@ -62,12 +62,12 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s
6262

6363
.. ipython:: python
6464
65-
df2 = pd.DataFrame({ 'A' : 1.,
66-
'B' : pd.Timestamp('20130102'),
67-
'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
68-
'D' : np.array([3] * 4,dtype='int32'),
69-
'E' : pd.Categorical(["test","train","test","train"]),
70-
'F' : 'foo' })
65+
df2 = pd.DataFrame({'A': 1.,
66+
'B': pd.Timestamp('20130102'),
67+
'C': pd.Series(1, index=list(range(4)),dtype='float32'),
68+
'D': np.array([3] * 4, dtype='int32'),
69+
'E': pd.Categorical(["test", "train", "test", "train"]),
70+
'F': 'foo'})
7171
df2
7272
7373
The columns of the resulting ``DataFrame`` have different
@@ -283,9 +283,9 @@ Using the :func:`~Series.isin` method for filtering:
283283
.. ipython:: python
284284
285285
df2 = df.copy()
286-
df2['E'] = ['one', 'one','two','three','four','three']
286+
df2['E'] = ['one', 'one', 'two', 'three', 'four', 'three']
287287
df2
288-
df2[df2['E'].isin(['two','four'])]
288+
df2[df2['E'].isin(['two', 'four'])]
289289
290290
Setting
291291
~~~~~~~
@@ -295,7 +295,7 @@ by the indexes.
295295

296296
.. ipython:: python
297297
298-
s1 = pd.Series([1,2,3,4,5,6], index=pd.date_range('20130102', periods=6))
298+
s1 = pd.Series([1, 2, 3, 4, 5, 6], index=pd.date_range('20130102', periods=6))
299299
s1
300300
df['F'] = s1
301301
@@ -394,7 +394,7 @@ In addition, pandas automatically broadcasts along the specified dimension.
394394

395395
.. ipython:: python
396396
397-
s = pd.Series([1,3,5,np.nan,6,8], index=dates).shift(2)
397+
s = pd.Series([1, 3, 5, np.nan, 6, 8], index=dates).shift(2)
398398
s
399399
df.sub(s, axis='index')
400400
@@ -492,7 +492,7 @@ section.
492492

493493
.. ipython:: python
494494
495-
df = pd.DataFrame(np.random.randn(8, 4), columns=['A','B','C','D'])
495+
df = pd.DataFrame(np.random.randn(8, 4), columns=['A', 'B', 'C', 'D'])
496496
df
497497
s = df.iloc[3]
498498
df.append(s, ignore_index=True)
@@ -512,12 +512,12 @@ See the :ref:`Grouping section <groupby>`.
512512

513513
.. ipython:: python
514514
515-
df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
516-
'foo', 'bar', 'foo', 'foo'],
517-
'B' : ['one', 'one', 'two', 'three',
518-
'two', 'two', 'one', 'three'],
519-
'C' : np.random.randn(8),
520-
'D' : np.random.randn(8)})
515+
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
516+
'foo', 'bar', 'foo', 'foo'],
517+
'B': ['one', 'one', 'two', 'three',
518+
'two', 'two', 'one', 'three'],
519+
'C': np.random.randn(8),
520+
'D': np.random.randn(8)})
521521
df
522522
523523
Grouping and then applying the :meth:`~DataFrame.sum` function to the resulting
@@ -532,7 +532,7 @@ apply the ``sum`` function.
532532

533533
.. ipython:: python
534534
535-
df.groupby(['A','B']).sum()
535+
df.groupby(['A', 'B']).sum()
536536
537537
Reshaping
538538
---------
@@ -578,11 +578,11 @@ See the section on :ref:`Pivot Tables <reshaping.pivot>`.
578578

579579
.. ipython:: python
580580
581-
df = pd.DataFrame({'A' : ['one', 'one', 'two', 'three'] * 3,
582-
'B' : ['A', 'B', 'C'] * 4,
583-
'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
584-
'D' : np.random.randn(12),
585-
'E' : np.random.randn(12)})
581+
df = pd.DataFrame({'A': ['one', 'one', 'two', 'three'] * 3,
582+
'B': ['A', 'B', 'C'] * 4,
583+
'C': ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
584+
'D': np.random.randn(12),
585+
'E': np.random.randn(12)})
586586
df
587587
588588
We can produce pivot tables from this data very easily:
@@ -653,7 +653,7 @@ pandas can include categorical data in a ``DataFrame``. For full docs, see the
653653

654654
.. ipython:: python
655655
656-
df = pd.DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
656+
df = pd.DataFrame({"id":[1, 2, 3, 4, 5, 6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
657657
658658
Convert the raw grades to a categorical data type.
659659

@@ -753,13 +753,13 @@ Writing to a HDF5 Store.
753753

754754
.. ipython:: python
755755
756-
df.to_hdf('foo.h5','df')
756+
df.to_hdf('foo.h5', 'df')
757757
758758
Reading from a HDF5 Store.
759759

760760
.. ipython:: python
761761
762-
pd.read_hdf('foo.h5','df')
762+
pd.read_hdf('foo.h5', 'df')
763763
764764
.. ipython:: python
765765
:suppress:
@@ -796,7 +796,7 @@ If you are attempting to perform an operation you might see an exception like:
796796
.. code-block:: python
797797
798798
>>> if pd.Series([False, True, False]):
799-
print("I was true")
799+
... print("I was true")
800800
Traceback
801801
...
802802
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().

doc/source/comparison_with_sas.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ see the :ref:`timeseries documentation<timeseries>` for more details.
298298
.. ipython:: python
299299
:suppress:
300300
301-
tips = tips.drop(['date1','date2','date1_year',
302-
'date2_month','date1_next','months_between'], axis=1)
301+
tips = tips.drop(['date1', 'date2', 'date1_year', 'date2_month',
302+
'date1_next', 'months_between'], axis=1)
303303
304304
Selection of Columns
305305
~~~~~~~~~~~~~~~~~~~~
@@ -744,12 +744,9 @@ XPORT is a relatively limited format and the parsing of it is not as
744744
optimized as some of the other pandas readers. An alternative way
745745
to interop data between SAS and pandas is to serialize to csv.
746746

747-
.. code-block:: python
748-
749-
# version 0.17, 10M rows
750-
751-
In [8]: %time df = pd.read_sas('big.xpt')
752-
Wall time: 14.6 s
747+
>>> # version 0.17, 10M rows
748+
>>> %time df = pd.read_sas('big.xpt')
749+
Wall time: 14.6 s
753750

754-
In [9]: %time df = pd.read_csv('big.csv')
755-
Wall time: 4.86 s
751+
>>> %time df = pd.read_csv('big.csv')
752+
Wall time: 4.86 s

doc/source/contributing_docstring.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,31 +189,34 @@ infinitive verb.
189189

190190
.. code-block:: python
191191
192-
def astype(dtype):
192+
def astype(dtype): # noqa: F811
193193
"""
194194
Casts Series type.
195195
196196
Verb in third-person of the present simple, should be infinitive.
197197
"""
198198
pass
199199
200-
def astype(dtype):
200+
201+
def astype(dtype): # noqa: F811
201202
"""
202203
Method to cast Series type.
203204
204205
Does not start with verb.
205206
"""
206207
pass
207208
208-
def astype(dtype):
209+
210+
def astype(dtype): # noqa: F811
209211
"""
210212
Cast Series type
211213
212214
Missing dot at the end.
213215
"""
214216
pass
215217
216-
def astype(dtype):
218+
219+
def astype(dtype): # noqa: F811
217220
"""
218221
Cast Series type from its current type to the new type defined in
219222
the parameter dtype.
@@ -624,6 +627,7 @@ A simple example could be:
624627
.. code-block:: python
625628
626629
class Series:
630+
627631
def head(self, n=5):
628632
"""
629633
Return the first elements of the Series.
@@ -684,9 +688,8 @@ shown:
684688
import numpy as np
685689
import pandas as pd
686690
687-
688691
Any other module used in the examples must be explicitly imported, one per line (as
689-
recommended in `PEP-8 <https://www.python.org/dev/peps/pep-0008/#imports>`_)
692+
recommended in :pep:`8#imports`)
690693
and avoiding aliases. Avoid excessive imports, but if needed, imports from
691694
the standard library go first, followed by third-party libraries (like
692695
matplotlib).
@@ -720,6 +723,7 @@ positional arguments ``head(3)``.
720723
.. code-block:: python
721724
722725
class Series:
726+
723727
def mean(self):
724728
"""
725729
Compute the mean of the input.
@@ -946,12 +950,14 @@ substitute the children's class names in this docstring.
946950
"""Apply my function to %(klass)s."""
947951
...
948952
953+
949954
class ChildA(Parent):
950955
@Substitution(klass="ChildA")
951956
@Appender(Parent.my_function.__doc__)
952957
def my_function(self):
953958
...
954959
960+
955961
class ChildB(Parent):
956962
@Substitution(klass="ChildB")
957963
@Appender(Parent.my_function.__doc__)

doc/source/gotchas.rst

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,32 @@ something to a ``bool``. This happens in an ``if``-statement or when using the
9696
boolean operations: ``and``, ``or``, and ``not``. It is not clear what the result
9797
of the following code should be:
9898

99-
.. code-block:: python
100-
101-
>>> if pd.Series([False, True, False]):
102-
...
99+
>>> if pd.Series([False, True, False]):
100+
... print("I was true")
103101

104102
Should it be ``True`` because it's not zero-length, or ``False`` because there
105103
are ``False`` values? It is unclear, so instead, pandas raises a ``ValueError``:
106104

107-
.. code-block:: python
108-
109-
>>> if pd.Series([False, True, False]):
110-
print("I was true")
111-
Traceback
112-
...
113-
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
105+
>>> if pd.Series([False, True, False]):
106+
... print("I was true")
107+
Traceback
108+
...
109+
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().
114110

115111
You need to explicitly choose what you want to do with the ``DataFrame``, e.g.
116112
use :meth:`~DataFrame.any`, :meth:`~DataFrame.all` or :meth:`~DataFrame.empty`.
117113
Alternatively, you might want to compare if the pandas object is ``None``:
118114

119-
.. code-block:: python
120-
121-
>>> if pd.Series([False, True, False]) is not None:
122-
print("I was not None")
123-
>>> I was not None
115+
>>> if pd.Series([False, True, False]) is not None:
116+
... print("I was not None")
117+
I was not None
124118

125119

126120
Below is how to check if any of the values are ``True``:
127121

128-
.. code-block:: python
129-
130-
>>> if pd.Series([False, True, False]).any():
131-
print("I am any")
132-
>>> I am any
122+
>>> if pd.Series([False, True, False]).any():
123+
... print("I am any")
124+
I am any
133125

134126
To evaluate single-element pandas objects in a boolean context, use the method
135127
:meth:`~DataFrame.bool`:
@@ -316,7 +308,7 @@ Occasionally you may have to deal with data that were created on a machine with
316308
a different byte order than the one on which you are running Python. A common
317309
symptom of this issue is an error like:
318310

319-
.. code-block:: python
311+
.. code-block:: console
320312
321313
Traceback
322314
...

doc/source/groupby.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ pandas objects can be split on any of their axes. The abstract definition of
7979
grouping is to provide a mapping of labels to group names. To create a GroupBy
8080
object (more on what the GroupBy object is later), you may do the following:
8181

82-
.. code-block:: ipython
82+
.. code-block:: python
8383
84-
# default is axis=0
85-
>>> grouped = obj.groupby(key)
86-
>>> grouped = obj.groupby(key, axis=1)
87-
>>> grouped = obj.groupby([key1, key2])
84+
# default is axis=0
85+
>>> grouped = obj.groupby(key)
86+
>>> grouped = obj.groupby(key, axis=1)
87+
>>> grouped = obj.groupby([key1, key2])
8888
8989
The mapping can be specified many different ways:
9090

@@ -1272,7 +1272,7 @@ arbitrary function, for example:
12721272

12731273
.. code-block:: python
12741274
1275-
(df.groupby(['Store', 'Product']).pipe(report_func)
1275+
df.groupby(['Store', 'Product']).pipe(report_func)
12761276
12771277
where ``report_func`` takes a GroupBy object and creates a report
12781278
from that.

doc/source/timeseries.rst

Lines changed: 1 addition & 1 deletion
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

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ exclude =
3232
.tox
3333

3434
[flake8-rst]
35-
bootstrap =
36-
import pandas as pd
37-
import numpy as np
3835
ignore =
3936
F821, # undefined name
37+
F401, # imported but unused
38+
W391, # blank line at end of file [Seems to be a bug (v0.4.1)]
39+
4040

4141
[yapf]
4242
based_on_style = pep8

0 commit comments

Comments
 (0)