From 705994e27383c296e52eca46320f11149bc21786 Mon Sep 17 00:00:00 2001 From: addisonlynch Date: Sun, 9 Dec 2018 18:15:51 -0500 Subject: [PATCH 1/2] Repair doc/source/dsintro.rst flake8 issues, remove exclusion --- doc/source/dsintro.rst | 61 +++++++++++++++++++++--------------------- setup.cfg | 1 - 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst index 8bdb0005de53c..029824522a18e 100644 --- a/doc/source/dsintro.rst +++ b/doc/source/dsintro.rst @@ -71,7 +71,7 @@ Series can be instantiated from dicts: .. ipython:: python - d = {'b' : 1, 'a' : 0, 'c' : 2} + d = {'b': 1, 'a': 0, 'c': 2} pd.Series(d) .. note:: @@ -92,7 +92,7 @@ index will be pulled out. .. ipython:: python - d = {'a' : 0., 'b' : 1., 'c' : 2.} + d = {'a': 0., 'b': 1., 'c': 2.} pd.Series(d) pd.Series(d, index=['b', 'c', 'd', 'a']) @@ -304,8 +304,8 @@ keys. .. ipython:: python - d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']), - 'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])} + d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']), + 'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])} df = pd.DataFrame(d) df @@ -334,8 +334,8 @@ result will be ``range(n)``, where ``n`` is the array length. .. ipython:: python - d = {'one' : [1., 2., 3., 4.], - 'two' : [4., 3., 2., 1.]} + d = {'one': [1., 2., 3., 4.], + 'two': [4., 3., 2., 1.]} pd.DataFrame(d) pd.DataFrame(d, index=['a', 'b', 'c', 'd']) @@ -346,8 +346,8 @@ This case is handled identically to a dict of arrays. .. ipython:: python - data = np.zeros((2,), dtype=[('A', 'i4'),('B', 'f4'),('C', 'a10')]) - data[:] = [(1,2.,'Hello'), (2,3.,"World")] + data = np.zeros((2, ), dtype=[('A', 'i4'), ('B', 'f4'), ('C', 'a10')]) + data[:] = [(1, 2., 'Hello'), (2, 3., "World")] pd.DataFrame(data) pd.DataFrame(data, index=['first', 'second']) @@ -507,8 +507,7 @@ derived from existing columns. iris = pd.read_csv('data/iris.data') iris.head() - - (iris.assign(sepal_ratio = iris['SepalWidth'] / iris['SepalLength']) + (iris.assign(sepal_ratio=iris['SepalWidth'] / iris['SepalLength']) .head()) In the example above, we inserted a precomputed value. We can also pass in @@ -516,8 +515,7 @@ a function of one argument to be evaluated on the DataFrame being assigned to. .. ipython:: python - iris.assign(sepal_ratio = lambda x: (x['SepalWidth'] / - x['SepalLength'])).head() + iris.assign(sepal_ratio=lambda x: (x['SepalWidth'] / x['SepalLength'])).head() ``assign`` **always** returns a copy of the data, leaving the original DataFrame untouched. @@ -532,8 +530,8 @@ greater than 5, calculate the ratio, and plot: @savefig basics_assign.png (iris.query('SepalLength > 5') - .assign(SepalRatio = lambda x: x.SepalWidth / x.SepalLength, - PetalRatio = lambda x: x.PetalWidth / x.PetalLength) + .assign(SepalRatio=lambda x: x.SepalWidth / x.SepalLength, + PetalRatio=lambda x: x.PetalWidth / x.PetalLength) .plot(kind='scatter', x='SepalRatio', y='PetalRatio')) Since a function is passed in, the function is computed on the DataFrame @@ -705,8 +703,8 @@ Boolean operators work as well: .. ipython:: python - df1 = pd.DataFrame({'a' : [1, 0, 1], 'b' : [0, 1, 1] }, dtype=bool) - df2 = pd.DataFrame({'a' : [0, 1, 1], 'b' : [1, 1, 0] }, dtype=bool) + df1 = pd.DataFrame({'a': [1, 0, 1], 'b': [0, 1, 1]}, dtype=bool) + df2 = pd.DataFrame({'a': [0, 1, 1], 'b': [1, 1, 0]}, dtype=bool) df1 & df2 df1 | df2 df1 ^ df2 @@ -746,7 +744,7 @@ Similarly, the dot method on Series implements dot product: .. ipython:: python - s1 = pd.Series(np.arange(5,10)) + s1 = pd.Series(np.arange(5, 10)) s1.dot(s1) DataFrame is not intended to be a drop-in replacement for ndarray as its @@ -777,7 +775,7 @@ R package): :okwarning: # restore GlobalPrintConfig - pd.reset_option('^display\.') + pd.reset_option('^display\.') # noqa: W605 However, using ``to_string`` will return a string representation of the DataFrame in tabular form, though it won't always fit the console width: @@ -798,7 +796,7 @@ option: .. ipython:: python - pd.set_option('display.width', 40) # default is 80 + pd.set_option('display.width', 40) # default is 80 pd.DataFrame(np.random.randn(3, 12)) @@ -806,14 +804,14 @@ You can adjust the max width of the individual columns by setting ``display.max_ .. ipython:: python - datafile={'filename': ['filename_01','filename_02'], - 'path': ["media/user_name/storage/folder_01/filename_01", - "media/user_name/storage/folder_02/filename_02"]} + datafile = {'filename': ['filename_01', 'filename_02'], + 'path': ["media/user_name/storage/folder_01/filename_01", + "media/user_name/storage/folder_02/filename_02"]} - pd.set_option('display.max_colwidth',30) + pd.set_option('display.max_colwidth', 30) pd.DataFrame(datafile) - pd.set_option('display.max_colwidth',100) + pd.set_option('display.max_colwidth', 100) pd.DataFrame(datafile) .. ipython:: python @@ -833,8 +831,8 @@ accessed like an attribute: .. ipython:: python - df = pd.DataFrame({'foo1' : np.random.randn(5), - 'foo2' : np.random.randn(5)}) + df = pd.DataFrame({'foo1': np.random.randn(5), + 'foo2': np.random.randn(5)}) df df.foo1 @@ -843,7 +841,7 @@ completion mechanism so they can be tab-completed: .. code-block:: ipython - In [5]: df.fo + In [5]: df.fo # noqa: E225, E999 df.foo1 df.foo2 .. _basics.panel: @@ -890,8 +888,8 @@ From dict of DataFrame objects .. ipython:: python :okwarning: - data = {'Item1' : pd.DataFrame(np.random.randn(4, 3)), - 'Item2' : pd.DataFrame(np.random.randn(4, 2))} + data = {'Item1': pd.DataFrame(np.random.randn(4, 3)), + 'Item2': pd.DataFrame(np.random.randn(4, 2))} pd.Panel(data) Note that the values in the dict need only be **convertible to @@ -947,8 +945,9 @@ From DataFrame using ``to_panel`` method .. ipython:: python :okwarning: - midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]]) - df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx) + midx = pd.MultiIndex(levels=[['one', 'two'], ['x', 'y']], + codes=[[1, 1, 0, 0], [1, 0, 1, 0]]) + df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx) df.to_panel() .. _dsintro.panel_item_selection: diff --git a/setup.cfg b/setup.cfg index 73a3a6c136b53..e21836cb28e72 100644 --- a/setup.cfg +++ b/setup.cfg @@ -79,7 +79,6 @@ exclude = doc/source/10min.rst doc/source/basics.rst doc/source/contributing_docstring.rst - doc/source/dsintro.rst doc/source/enhancingperf.rst doc/source/groupby.rst doc/source/indexing.rst From aee19e8b2b9777824234c17337b8d3124bcbe2b9 Mon Sep 17 00:00:00 2001 From: addisonlynch Date: Sun, 9 Dec 2018 18:35:43 -0500 Subject: [PATCH 2/2] Remove noqa --- doc/source/dsintro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/dsintro.rst b/doc/source/dsintro.rst index 029824522a18e..d4a83b6807fd5 100644 --- a/doc/source/dsintro.rst +++ b/doc/source/dsintro.rst @@ -775,7 +775,7 @@ R package): :okwarning: # restore GlobalPrintConfig - pd.reset_option('^display\.') # noqa: W605 + pd.reset_option(r'^display\.') However, using ``to_string`` will return a string representation of the DataFrame in tabular form, though it won't always fit the console width: