From f8f8950acebf467dbd34c99c4ec115ca7bd90a02 Mon Sep 17 00:00:00 2001 From: Saurav Chakravorty Date: Fri, 4 Jan 2019 00:10:25 +0530 Subject: [PATCH 1/3] DOC: Remove flake8 errors for basics.rst and contributing_docstring.rst --- doc/source/basics.rst | 8 ++--- doc/source/contributing_docstring.rst | 44 ++++++++++++++------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/doc/source/basics.rst b/doc/source/basics.rst index 8dca000dfa969..f52b7b9a0b2ea 100644 --- a/doc/source/basics.rst +++ b/doc/source/basics.rst @@ -807,15 +807,15 @@ Compare the following .. code-block:: python # f, g, and h are functions taking and returning ``DataFrames`` - >>> f(g(h(df), arg1=1), arg2=2, arg3=3) + >>> f(g(h(df), arg1=1), arg2=2, arg3=3) # noqa F821 with the equivalent .. code-block:: python - >>> (df.pipe(h) - ... .pipe(g, arg1=1) - ... .pipe(f, arg2=2, arg3=3)) + >>> (df.pipe(h) # noqa F821 + ... .pipe(g, arg1=1) # noqa F821 + ... .pipe(f, arg2=2, arg3=3)) # noqa F821 Pandas encourages the second style, which is known as method chaining. ``pipe`` makes it easy to use your own or another library's functions diff --git a/doc/source/contributing_docstring.rst b/doc/source/contributing_docstring.rst index 7c7847a47a1a2..66120c581fba0 100644 --- a/doc/source/contributing_docstring.rst +++ b/doc/source/contributing_docstring.rst @@ -47,11 +47,11 @@ Next example gives an idea on how a docstring looks like: Examples -------- - >>> add(2, 2) + >>> add(2, 2) # noqa F821 4 - >>> add(25, 0) + >>> add(25, 0) # noqa F821 25 - >>> add(10, -10) + >>> add(10, -10) # noqa F821 0 """ return num1 + num2 @@ -187,7 +187,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): + def astype(dtype): # noqa F811 """ Casts Series type. @@ -197,7 +197,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): + def astype(dtype): # noqa F811 """ Method to cast Series type. @@ -207,7 +207,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): + def astype(dtype): # noqa F811 """ Cast Series type @@ -217,7 +217,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): + def astype(dtype): # noqa F811 """ Cast Series type from its current type to the new type defined in the parameter dtype. @@ -322,7 +322,7 @@ would be used, then we will specify "str, int or None, default None". .. code-block:: python - class Series: + class Series: # noqa F811 def plot(self, kind, **kwargs): """ Generate a plot. @@ -457,12 +457,14 @@ For example, with a single value: float Random number generated. """ - return random.random() + return np.random.random() With more than one value: .. code-block:: python + import string + def random_letters(): """ Generate and return a sequence of random letters. @@ -477,8 +479,8 @@ With more than one value: letters : str String of random letters. """ - length = random.randint(1, 10) - letters = ''.join(random.choice(string.ascii_lowercase) + length = np.random.randint(1, 10) + letters = ''.join(np.random.choice(string.ascii_lowercase) for i in range(length)) return length, letters @@ -499,7 +501,7 @@ If the method yields its value: Random number generated. """ while True: - yield random.random() + yield np.random.random() .. _docstring.see_also: @@ -558,7 +560,7 @@ For example: .. code-block:: python - class Series: + class Series: # noqa F811 def head(self): """ Return the first 5 elements of the Series. @@ -776,7 +778,7 @@ positional arguments ``head(3)``. Examples -------- - >>> s = pd.Series('Antelope', 'Lion', 'Zebra', numpy.nan) + >>> s = pd.Series('Antelope', 'Lion', 'Zebra', np.nan) >>> s.contains(pattern='a') 0 False 1 False @@ -834,7 +836,7 @@ positional arguments ``head(3)``. -------- >>> import numpy as np >>> import pandas as pd - >>> df = pd.DataFrame(numpy.random.randn(3, 3), + >>> df = pd.DataFrame(np.random.randn(3, 3), ... columns=('a', 'b', 'c')) >>> df.method(1) 21 @@ -909,7 +911,7 @@ plot will be generated automatically when building the documentation. .. code-block:: python - class Series: + class Series: # noqa F811 def plot(self): """ Generate a plot with the `Series` data. @@ -953,15 +955,15 @@ substitute the children's class names in this docstring. class ChildA(Parent): - @Substitution(klass="ChildA") - @Appender(Parent.my_function.__doc__) + @Substitution(klass="ChildA") # noqa F821 + @Appender(Parent.my_function.__doc__) # noqa F821 def my_function(self): ... class ChildB(Parent): - @Substitution(klass="ChildB") - @Appender(Parent.my_function.__doc__) + @Substitution(klass="ChildB") # noqa F821 + @Appender(Parent.my_function.__doc__) # noqa F821 def my_function(self): ... @@ -990,7 +992,7 @@ You can substitute and append in one shot with something like .. code-block:: python - @Appender(template % _shared_doc_kwargs) + @Appender(template % _shared_doc_kwargs) # noqa F821 def my_function(self): ... From bd591d91161782f950d36c9b59e43d0d145671c5 Mon Sep 17 00:00:00 2001 From: Saurav Chakravorty Date: Fri, 4 Jan 2019 00:12:24 +0530 Subject: [PATCH 2/3] Removed from setup.cfg --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index c21f09f131dbd..6e01f7a0d1a22 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,8 +49,6 @@ exclude = doc/source/whatsnew/v0.15.0.rst doc/source/whatsnew/v0.15.1.rst doc/source/whatsnew/v0.15.2.rst - doc/source/basics.rst - doc/source/contributing_docstring.rst doc/source/enhancingperf.rst From be8d2530a810d179fd88c05706d24ca57f0cdcea Mon Sep 17 00:00:00 2001 From: Saurav Chakravorty Date: Fri, 4 Jan 2019 08:47:30 +0530 Subject: [PATCH 3/3] DOC: removed noqa --- doc/source/basics.rst | 8 +++---- doc/source/contributing_docstring.rst | 34 +++++++++++++-------------- setup.cfg | 2 ++ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/doc/source/basics.rst b/doc/source/basics.rst index f52b7b9a0b2ea..8dca000dfa969 100644 --- a/doc/source/basics.rst +++ b/doc/source/basics.rst @@ -807,15 +807,15 @@ Compare the following .. code-block:: python # f, g, and h are functions taking and returning ``DataFrames`` - >>> f(g(h(df), arg1=1), arg2=2, arg3=3) # noqa F821 + >>> f(g(h(df), arg1=1), arg2=2, arg3=3) with the equivalent .. code-block:: python - >>> (df.pipe(h) # noqa F821 - ... .pipe(g, arg1=1) # noqa F821 - ... .pipe(f, arg2=2, arg3=3)) # noqa F821 + >>> (df.pipe(h) + ... .pipe(g, arg1=1) + ... .pipe(f, arg2=2, arg3=3)) Pandas encourages the second style, which is known as method chaining. ``pipe`` makes it easy to use your own or another library's functions diff --git a/doc/source/contributing_docstring.rst b/doc/source/contributing_docstring.rst index 66120c581fba0..f7e2b42a1ccbd 100644 --- a/doc/source/contributing_docstring.rst +++ b/doc/source/contributing_docstring.rst @@ -47,11 +47,11 @@ Next example gives an idea on how a docstring looks like: Examples -------- - >>> add(2, 2) # noqa F821 + >>> add(2, 2) 4 - >>> add(25, 0) # noqa F821 + >>> add(25, 0) 25 - >>> add(10, -10) # noqa F821 + >>> add(10, -10) 0 """ return num1 + num2 @@ -187,7 +187,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): # noqa F811 + def astype(dtype): """ Casts Series type. @@ -197,7 +197,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): # noqa F811 + def astype(dtype): """ Method to cast Series type. @@ -207,7 +207,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): # noqa F811 + def astype(dtype): """ Cast Series type @@ -217,7 +217,7 @@ infinitive verb. .. code-block:: python - def astype(dtype): # noqa F811 + def astype(dtype): """ Cast Series type from its current type to the new type defined in the parameter dtype. @@ -322,7 +322,7 @@ would be used, then we will specify "str, int or None, default None". .. code-block:: python - class Series: # noqa F811 + class Series: def plot(self, kind, **kwargs): """ Generate a plot. @@ -560,7 +560,7 @@ For example: .. code-block:: python - class Series: # noqa F811 + class Series: def head(self): """ Return the first 5 elements of the Series. @@ -688,8 +688,8 @@ shown: .. code-block:: python - import numpy as np # noqa: F401 - import pandas as pd # noqa: F401 + import numpy as np + import pandas as pd Any other module used in the examples must be explicitly imported, one per line (as recommended in :pep:`8#imports`) @@ -911,7 +911,7 @@ plot will be generated automatically when building the documentation. .. code-block:: python - class Series: # noqa F811 + class Series: def plot(self): """ Generate a plot with the `Series` data. @@ -955,15 +955,15 @@ substitute the children's class names in this docstring. class ChildA(Parent): - @Substitution(klass="ChildA") # noqa F821 - @Appender(Parent.my_function.__doc__) # noqa F821 + @Substitution(klass="ChildA") + @Appender(Parent.my_function.__doc__) def my_function(self): ... class ChildB(Parent): - @Substitution(klass="ChildB") # noqa F821 - @Appender(Parent.my_function.__doc__) # noqa F821 + @Substitution(klass="ChildB") + @Appender(Parent.my_function.__doc__) def my_function(self): ... @@ -992,7 +992,7 @@ You can substitute and append in one shot with something like .. code-block:: python - @Appender(template % _shared_doc_kwargs) # noqa F821 + @Appender(template % _shared_doc_kwargs) def my_function(self): ... diff --git a/setup.cfg b/setup.cfg index 6e01f7a0d1a22..c21f09f131dbd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,6 +49,8 @@ exclude = doc/source/whatsnew/v0.15.0.rst doc/source/whatsnew/v0.15.1.rst doc/source/whatsnew/v0.15.2.rst + doc/source/basics.rst + doc/source/contributing_docstring.rst doc/source/enhancingperf.rst