Skip to content

Commit 11a3632

Browse files
committed
Fixing PEP8 issues
Signed-off-by: Fabian Haase <[email protected]>
1 parent 472df59 commit 11a3632

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

doc/source/contributing.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,15 @@ Transitioning to ``pytest``
744744
.. code-block:: python
745745
746746
class TestReallyCoolFeature(object):
747-
....
747+
.... # noqa: E999
748748
749749
Going forward, we are moving to a more *functional* style using the `pytest <http://docs.pytest.org/en/latest/>`__ framework, which offers a richer testing
750750
framework that will facilitate testing and developing. Thus, instead of writing test classes, we will write test functions like this:
751751

752752
.. code-block:: python
753753
754754
def test_really_cool_feature():
755-
....
755+
.... # noqa: E999
756756
757757
Using ``pytest``
758758
~~~~~~~~~~~~~~~~
@@ -777,25 +777,32 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
777777
import pandas as pd
778778
from pandas.util import testing as tm
779779
780+
780781
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
781782
def test_dtypes(dtype):
782783
assert str(np.dtype(dtype)) == dtype
783784
784-
@pytest.mark.parametrize('dtype', ['float32',
785-
pytest.param('int16', marks=pytest.mark.skip),
786-
pytest.param('int32',
787-
marks=pytest.mark.xfail(reason='to show how it works'))])
785+
786+
@pytest.mark.parametrize('dtype',
787+
['float32',
788+
pytest.param('int16', marks=pytest.mark.skip),
789+
pytest.param('int32', marks=pytest.mark.xfail(
790+
reason='example'))
791+
])
788792
def test_mark(dtype):
789793
assert str(np.dtype(dtype)) == 'float32'
790794
795+
791796
@pytest.fixture
792797
def series():
793798
return pd.Series([1, 2, 3])
794799
800+
795801
@pytest.fixture(params=['int8', 'int16', 'int32', 'int64'])
796802
def dtype(request):
797803
return request.param
798804
805+
799806
def test_series(series, dtype):
800807
result = series.astype(dtype)
801808
assert result.dtype == dtype
@@ -864,6 +871,7 @@ for details <https://hypothesis.readthedocs.io/en/latest/index.html>`_.
864871
st.lists(any_json_value), st.dictionaries(st.text(), any_json_value)
865872
))
866873
874+
867875
@given(value=any_json_value)
868876
def test_json_roundtrip(value):
869877
result = json.loads(json.dumps(value))

doc/source/enhancingperf.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ take the plain Python code from above and annotate with the ``@jit`` decorator.
330330
331331
import numba
332332
333+
333334
@numba.jit
334335
def f_plain(x):
335336
return x * (x - 1)
@@ -378,6 +379,7 @@ Consider the following toy example of doubling each observation:
378379
379380
import numba
380381
382+
381383
def double_every_value_nonumba(x):
382384
return x * 2
383385

doc/source/io.rst

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,7 @@ For example:
18341834

18351835
.. code-block:: python
18361836
1837-
DataFrame([1.0, 2.0, complex(1.0, 2.0)]).to_json() # raises
1838-
1837+
>>> DataFrame([1.0, 2.0, complex(1.0, 2.0)]).to_json() # raises
18391838
RuntimeError: Unhandled numpy dtype 15
18401839
18411840
can be dealt with by specifying a simple ``default_handler``:
@@ -2411,8 +2410,8 @@ columns to strings.
24112410
.. code-block:: python
24122411
24132412
url_mcc = 'https://en.wikipedia.org/wiki/Mobile_country_code'
2414-
dfs = pd.read_html(url_mcc, match='Telekom Albania', header=0, converters={'MNC':
2415-
str})
2413+
dfs = pd.read_html(url_mcc, match='Telekom Albania', header=0,
2414+
converters={'MNC': str})
24162415
24172416
.. versionadded:: 0.19
24182417

@@ -2724,7 +2723,8 @@ different parameters:
27242723
data = {}
27252724
# For when Sheet1's format differs from Sheet2
27262725
with pd.ExcelFile('path_to_file.xls') as xls:
2727-
data['Sheet1'] = pd.read_excel(xls, 'Sheet1', index_col=None, na_values=['NA'])
2726+
data['Sheet1'] = pd.read_excel(xls, 'Sheet1', index_col=None,
2727+
na_values=['NA'])
27282728
data['Sheet2'] = pd.read_excel(xls, 'Sheet2', index_col=1)
27292729
27302730
Note that if the same parsing parameters are used for all sheets, a list
@@ -2735,11 +2735,14 @@ of sheet names can simply be passed to ``read_excel`` with no loss in performanc
27352735
# using the ExcelFile class
27362736
data = {}
27372737
with pd.ExcelFile('path_to_file.xls') as xls:
2738-
data['Sheet1'] = read_excel(xls, 'Sheet1', index_col=None, na_values=['NA'])
2739-
data['Sheet2'] = read_excel(xls, 'Sheet2', index_col=None, na_values=['NA'])
2738+
data['Sheet1'] = read_excel(xls, 'Sheet1', index_col=None,
2739+
na_values=['NA'])
2740+
data['Sheet2'] = read_excel(xls, 'Sheet2', index_col=None,
2741+
na_values=['NA'])
27402742
27412743
# equivalent using the read_excel function
2742-
data = read_excel('path_to_file.xls', ['Sheet1', 'Sheet2'], index_col=None, na_values=['NA'])
2744+
data = read_excel('path_to_file.xls', ['Sheet1', 'Sheet2'],
2745+
index_col=None, na_values=['NA'])
27432746
27442747
.. _io.excel.specifying_sheets:
27452748

@@ -2899,7 +2902,10 @@ missing data to recover integer dtype:
28992902

29002903
.. code-block:: python
29012904
2902-
cfun = lambda x: int(x) if x else -1
2905+
def cfun(x):
2906+
return int(x) if x else -1
2907+
2908+
29032909
read_excel('path_to_file.xls', 'Sheet1', converters={'MyInts': cfun})
29042910
29052911
dtype Specifications
@@ -3040,7 +3046,7 @@ argument to ``to_excel`` and to ``ExcelWriter``. The built-in engines are:
30403046
writer = ExcelWriter('path_to_file.xlsx', engine='xlsxwriter')
30413047
30423048
# Or via pandas configuration.
3043-
from pandas import options
3049+
from pandas import options # noqa: E402
30443050
options.io.excel.xlsx.writer = 'xlsxwriter'
30453051
30463052
df.to_excel('path_to_file.xlsx', sheet_name='Sheet1')
@@ -3067,7 +3073,7 @@ which takes the contents of the clipboard buffer and passes them to the
30673073
``read_csv`` method. For instance, you can copy the following text to the
30683074
clipboard (CTRL-C on many operating systems):
30693075

3070-
.. code-block:: python
3076+
.. code-block:: console
30713077
30723078
A B C
30733079
x 1 4 p
@@ -3476,9 +3482,9 @@ This format is specified by default when using ``put`` or ``to_hdf`` or by ``for
34763482

34773483
.. code-block:: python
34783484
3479-
pd.DataFrame(randn(10, 2)).to_hdf('test_fixed.h5', 'df')
3485+
>>> pd.DataFrame(randn(10, 2)).to_hdf('test_fixed.h5', 'df')
34803486
3481-
pd.read_hdf('test_fixed.h5', 'df', where='index>5')
3487+
>>> pd.read_hdf('test_fixed.h5', 'df', where='index>5')
34823488
TypeError: cannot pass a where specification when reading a fixed format.
34833489
this store must be selected in its entirety
34843490
@@ -3576,12 +3582,11 @@ will yield a tuple for each group key along with the relative keys of its conten
35763582

35773583
.. code-block:: python
35783584
3579-
In [8]: store.foo.bar.bah
3585+
>>> store.foo.bar.bah
35803586
AttributeError: 'HDFStore' object has no attribute 'foo'
35813587
35823588
# you can directly access the actual PyTables node but using the root node
3583-
In [9]: store.root.foo.bar.bah
3584-
Out[9]:
3589+
>>> store.root.foo.bar.bah
35853590
/foo/bar/bah (Group) ''
35863591
children := ['block0_items' (Array), 'block0_values' (Array), 'axis0' (Array), 'axis1' (Array)]
35873592
@@ -3735,7 +3740,7 @@ The right-hand side of the sub-expression (after a comparison operator) can be:
37353740
.. code-block:: python
37363741
37373742
string = "HolyMoly'"
3738-
store.select('df', 'index == %s' % string)
3743+
store.select('df', 'index == %s' % string)
37393744
37403745
The latter will **not** work and will raise a ``SyntaxError``.Note that
37413746
there's a single quote followed by a double quote in the ``string``
@@ -3941,7 +3946,7 @@ The default is 50,000 rows returned in a chunk.
39413946

39423947
.. code-block:: python
39433948
3944-
for df in pd.read_hdf('store.h5','df', chunksize=3):
3949+
for df in pd.read_hdf('store.h5', 'df', chunksize=3):
39453950
print(df)
39463951
39473952
Note, that the chunksize keyword applies to the **source** rows. So if you
@@ -4841,7 +4846,8 @@ to pass to :func:`pandas.to_datetime`:
48414846
.. code-block:: python
48424847
48434848
pd.read_sql_table('data', engine, parse_dates={'Date': '%Y-%m-%d'})
4844-
pd.read_sql_table('data', engine, parse_dates={'Date': {'format': '%Y-%m-%d %H:%M:%S'}})
4849+
pd.read_sql_table('data', engine,
4850+
parse_dates={'Date': {'format': '%Y-%m-%d %H:%M:%S'}})
48454851
48464852
48474853
You can check if a table exists using :func:`~pandas.io.sql.has_table`
@@ -5349,62 +5355,81 @@ And here's the code:
53495355
sz = 1000000
53505356
df = pd.DataFrame({'A': randn(sz), 'B': [1] * sz})
53515357
5358+
53525359
def test_sql_write(df):
53535360
if os.path.exists('test.sql'):
53545361
os.remove('test.sql')
53555362
sql_db = sqlite3.connect('test.sql')
53565363
df.to_sql(name='test_table', con=sql_db)
53575364
sql_db.close()
53585365
5366+
53595367
def test_sql_read():
53605368
sql_db = sqlite3.connect('test.sql')
53615369
pd.read_sql_query("select * from test_table", sql_db)
53625370
sql_db.close()
53635371
5372+
53645373
def test_hdf_fixed_write(df):
53655374
df.to_hdf('test_fixed.hdf', 'test', mode='w')
53665375
5376+
53675377
def test_hdf_fixed_read():
53685378
pd.read_hdf('test_fixed.hdf', 'test')
53695379
5380+
53705381
def test_hdf_fixed_write_compress(df):
53715382
df.to_hdf('test_fixed_compress.hdf', 'test', mode='w', complib='blosc')
53725383
5384+
53735385
def test_hdf_fixed_read_compress():
53745386
pd.read_hdf('test_fixed_compress.hdf', 'test')
53755387
5388+
53765389
def test_hdf_table_write(df):
53775390
df.to_hdf('test_table.hdf', 'test', mode='w', format='table')
53785391
5392+
53795393
def test_hdf_table_read():
53805394
pd.read_hdf('test_table.hdf', 'test')
53815395
5396+
53825397
def test_hdf_table_write_compress(df):
5383-
df.to_hdf('test_table_compress.hdf', 'test', mode='w', complib='blosc', format='table')
5398+
df.to_hdf('test_table_compress.hdf', 'test', mode='w',
5399+
complib='blosc', format='table')
5400+
53845401
53855402
def test_hdf_table_read_compress():
53865403
pd.read_hdf('test_table_compress.hdf', 'test')
53875404
5405+
53885406
def test_csv_write(df):
53895407
df.to_csv('test.csv', mode='w')
53905408
5409+
53915410
def test_csv_read():
53925411
pd.read_csv('test.csv', index_col=0)
53935412
5413+
53945414
def test_feather_write(df):
53955415
df.to_feather('test.feather')
53965416
5417+
53975418
def test_feather_read():
53985419
pd.read_feather('test.feather')
53995420
5421+
54005422
def test_pickle_write(df):
54015423
df.to_pickle('test.pkl')
54025424
5425+
54035426
def test_pickle_read():
54045427
pd.read_pickle('test.pkl')
54055428
5429+
54065430
def test_pickle_write_compress(df):
54075431
df.to_pickle('test.pkl.compress', compression='xz')
54085432
5433+
54095434
def test_pickle_read_compress():
54105435
pd.read_pickle('test.pkl.compress', compression='xz')

0 commit comments

Comments
 (0)