From 67ff7aec78a55cc32f2eb2c2a437e02360ae5c23 Mon Sep 17 00:00:00 2001 From: JimJeon Date: Sun, 16 Dec 2018 16:49:20 +0900 Subject: [PATCH 1/6] DOC: Fix flake8 issues with whatsnew v0.18.* Fixed almost every flake8 issues in v0.18.*.rst except one issue about tab-completion. --- doc/source/whatsnew/v0.18.0.rst | 35 +++++++++++++++++---------------- doc/source/whatsnew/v0.18.1.rst | 34 +++++++++++++++++++++----------- setup.cfg | 2 -- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index da7d409fb8922..5f55f550745c6 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -64,14 +64,14 @@ Window functions have been refactored to be methods on ``Series/DataFrame`` obje .. ipython:: python np.random.seed(1234) - df = pd.DataFrame({'A' : range(10), 'B' : np.random.randn(10)}) + df = pd.DataFrame({'A': range(10), 'B': np.random.randn(10)}) df Previous Behavior: .. code-block:: ipython - In [8]: pd.rolling_mean(df,window=3) + In [8]: pd.rolling_mean(df, window=3) FutureWarning: pd.rolling_mean is deprecated for DataFrame and will be removed in a future version, replace with DataFrame.rolling(window=3,center=False).mean() Out[8]: @@ -102,7 +102,7 @@ with tab-completion of available methods and properties. .. code-block:: ipython - In [9]: r. + In [9]: r. r.A r.agg r.apply r.count r.exclusions r.max r.median r.name r.skew r.sum r.B r.aggregate r.corr r.cov r.kurt r.mean r.min r.quantile r.std r.var @@ -122,8 +122,8 @@ And multiple aggregations .. ipython:: python - r.agg({'A' : ['mean','std'], - 'B' : ['mean','std']}) + r.agg({'A': ['mean', 'std'], + 'B': ['mean', 'std']}) .. _whatsnew_0180.enhancements.rename: @@ -201,7 +201,7 @@ Currently the default is ``expand=None`` which gives a ``FutureWarning`` and use .. code-block:: ipython - In [1]: pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=None) + In [1]: pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=None) FutureWarning: currently extract(expand=None) means expand=False (return Index/Series/DataFrame) but in a future version of pandas this will be changed to expand=True (return DataFrame) @@ -216,13 +216,13 @@ Extracting a regular expression with one group returns a Series if .. ipython:: python - pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=False) + pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=False) It returns a ``DataFrame`` with one column if ``expand=True``. .. ipython:: python - pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)', expand=True) + pd.Series(['a1', 'b2', 'c3']).str.extract(r'[ab](\d)', expand=True) Calling on an ``Index`` with a regex with exactly one capture group returns an ``Index`` if ``expand=False``. @@ -270,13 +270,13 @@ match. s = pd.Series(["a1a2", "b1", "c1"], ["A", "B", "C"]) s - s.str.extract("(?P[ab])(?P\d)", expand=False) + s.str.extract(r"(?P[ab])(?P\d)", expand=False) The ``extractall`` method returns all matches. .. ipython:: python - s.str.extractall("(?P[ab])(?P\d)") + s.str.extractall(r"(?P[ab])(?P\d)") .. _whatsnew_0180.enhancements.strcat: @@ -289,12 +289,12 @@ A new, friendlier ``ValueError`` is added to protect against the mistake of supp .. ipython:: python - pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ') - pd.Series(['a','b',np.nan,'c']).str.cat(sep=' ', na_rep='?') + pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ') + pd.Series(['a', 'b', np.nan, 'c']).str.cat(sep=' ', na_rep='?') .. code-block:: ipython - In [2]: pd.Series(['a','b',np.nan,'c']).str.cat(' ') + In [2]: pd.Series(['a', 'b', np.nan, 'c']).str.cat(' ') ValueError: Did you mean to supply a `sep` keyword? @@ -329,7 +329,7 @@ Timedeltas .. ipython:: python - t = timedelta_range('1 days 2 hr 13 min 45 us',periods=3,freq='d') + t = timedelta_range('1 days 2 hr 13 min 45 us', periods=3, freq='d') t t.round('10min') @@ -356,7 +356,7 @@ Previous Behavior: .. code-block:: ipython - In [2]: s = pd.Series([1,2,3], index=np.arange(3.)) + In [2]: s = pd.Series([1, 2, 3], index=np.arange(3.)) In [3]: s Out[3]: @@ -378,7 +378,7 @@ New Behavior: .. ipython:: python - s = pd.Series([1,2,3], index=np.arange(3.)) + s = pd.Series([1, 2, 3], index=np.arange(3.)) s s.index print(s.to_csv(path_or_buf=None, header=False)) @@ -727,7 +727,8 @@ Like the change in the window functions API :ref:`above 100] - ) + .loc[lambda df: df.r > 100]) .. _whatsnew_0181.partial_string_indexing: @@ -185,10 +185,11 @@ Partial string indexing now matches on ``DateTimeIndex`` when part of a ``MultiI dft2 = pd.DataFrame(np.random.randn(20, 1), columns=['A'], - index=pd.MultiIndex.from_product([pd.date_range('20130101', - periods=10, - freq='12H'), - ['a', 'b']])) + index=pd.MultiIndex. + from_product([pd.date_range('20130101', + periods=10, + freq='12H'), + ['a', 'b']])) dft2 dft2.loc['2013-01-05'] @@ -317,8 +318,8 @@ The index in ``.groupby(..).nth()`` output is now more consistent when the ``as_ .. ipython:: python - df = DataFrame({'A' : ['a', 'b', 'a'], - 'B' : [1, 2, 3]}) + df = pd.DataFrame({'A': ['a', 'b', 'a'], + 'B': [1, 2, 3]}) df Previous Behavior: @@ -433,13 +434,15 @@ Previous behavior: .. code-block:: ipython - In [1]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum()) + In [1]: df.groupby(pd.TimeGrouper(key='date', + ...: freq='M')).apply(lambda x: x.value.sum()) Out[1]: ... TypeError: cannot concatenate a non-NDFrame object # Output is a Series - In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()) + In [2]: df.groupby(pd.TimeGrouper(key='date', + ...: freq='M')).apply(lambda x: x[['value']].sum()) Out[2]: date 2000-10-31 value 10 @@ -451,7 +454,8 @@ New Behavior: .. code-block:: python # Output is a Series - In [55]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum()) + In [55]: df.groupby(pd.TimeGrouper(key='date', + ...: freq='M')).apply(lambda x: x.value.sum()) Out[55]: date 2000-10-31 10 @@ -459,7 +463,8 @@ New Behavior: Freq: M, dtype: int64 # Output is a DataFrame - In [56]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()) + In [56]: df.groupby(pd.TimeGrouper(key='date', + ...: freq='M')).apply(lambda x: x[['value']].sum()) Out[56]: value date @@ -471,6 +476,11 @@ New Behavior: Changes in ``read_csv`` exceptions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. ipython:: python + :suppress: + + from pandas.compat import StringIO + In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` engines, both will now raise an ``EmptyDataError``, a subclass of ``ValueError``, in response to empty columns or header (:issue:`12493`, :issue:`12506`) diff --git a/setup.cfg b/setup.cfg index f9b4f27dda919..121faf0b6b619 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,8 +56,6 @@ exclude = doc/source/whatsnew/v0.16.2.rst doc/source/whatsnew/v0.17.0.rst doc/source/whatsnew/v0.17.1.rst - doc/source/whatsnew/v0.18.0.rst - doc/source/whatsnew/v0.18.1.rst doc/source/basics.rst doc/source/contributing_docstring.rst doc/source/enhancingperf.rst From 7e4bc37742fc151b1411785c64a17263fb09a22c Mon Sep 17 00:00:00 2001 From: JimJeon Date: Sun, 16 Dec 2018 17:10:21 +0900 Subject: [PATCH 2/6] DOC: Fixes import of StringIO From conversations in #24273, I found that everywhere in pandas documentation should use `io` and not `compat`. --- doc/source/whatsnew/v0.18.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst index 6f6c6b982c40f..ed6838369d450 100644 --- a/doc/source/whatsnew/v0.18.1.rst +++ b/doc/source/whatsnew/v0.18.1.rst @@ -479,7 +479,7 @@ Changes in ``read_csv`` exceptions .. ipython:: python :suppress: - from pandas.compat import StringIO + from io import StringIO In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` engines, both will now raise an ``EmptyDataError``, a subclass of ``ValueError``, in response to empty columns or header (:issue:`12493`, :issue:`12506`) From f898da759dcde5b63b25703d8139155dae65356c Mon Sep 17 00:00:00 2001 From: JimJeon Date: Mon, 17 Dec 2018 10:28:24 +0900 Subject: [PATCH 3/6] DOC: Fix reviewed issues --- doc/source/whatsnew/v0.18.0.rst | 9 ++------- doc/source/whatsnew/v0.18.1.rst | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/doc/source/whatsnew/v0.18.0.rst b/doc/source/whatsnew/v0.18.0.rst index 5f55f550745c6..e9d4891df70c5 100644 --- a/doc/source/whatsnew/v0.18.0.rst +++ b/doc/source/whatsnew/v0.18.0.rst @@ -5,11 +5,6 @@ v0.18.0 (March 13, 2016) {{ header }} -.. ipython:: python - :suppress: - - from pandas import * # noqa F401, F403 - This is a major release from 0.17.1 and includes a small number of API changes, several new features, enhancements, and performance improvements along with a large number of bug fixes. We recommend that all @@ -102,7 +97,7 @@ with tab-completion of available methods and properties. .. code-block:: ipython - In [9]: r. + In [9]: r. # noqa E225, E999 r.A r.agg r.apply r.count r.exclusions r.max r.median r.name r.skew r.sum r.B r.aggregate r.corr r.cov r.kurt r.mean r.min r.quantile r.std r.var @@ -1138,7 +1133,7 @@ and setting Positional setting with ``.ix`` and a float indexer will ADD this value to the index, rather than previously setting the value by position. -.. code-block:: python +.. code-block:: ipython In [3]: s2.ix[1.0] = 10 In [4]: s2 diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst index ed6838369d450..306fbfb7c94f3 100644 --- a/doc/source/whatsnew/v0.18.1.rst +++ b/doc/source/whatsnew/v0.18.1.rst @@ -53,8 +53,8 @@ Friday before MLK Day .. ipython:: python - from datetime import datetime - dt = datetime(2014, 1, 17, 15) + import datetime + dt = datetime.datetime(2014, 1, 17, 15) dt + bhour_us @@ -183,13 +183,13 @@ Partial string indexing now matches on ``DateTimeIndex`` when part of a ``MultiI .. ipython:: python - dft2 = pd.DataFrame(np.random.randn(20, 1), - columns=['A'], - index=pd.MultiIndex. - from_product([pd.date_range('20130101', - periods=10, - freq='12H'), - ['a', 'b']])) + dft2 = pd.DataFrame( + np.random.randn(20, 1), + columns=['A'], + index=pd.MultiIndex.from_product([pd.date_range('20130101', + periods=10, + freq='12H'), + ['a', 'b']])) dft2 dft2.loc['2013-01-05'] @@ -451,7 +451,7 @@ Previous behavior: New Behavior: -.. code-block:: python +.. code-block:: ipython # Output is a Series In [55]: df.groupby(pd.TimeGrouper(key='date', @@ -479,7 +479,7 @@ Changes in ``read_csv`` exceptions .. ipython:: python :suppress: - from io import StringIO + import io In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` engines, both will now raise an ``EmptyDataError``, a subclass of ``ValueError``, in response to empty columns or header (:issue:`12493`, :issue:`12506`) @@ -488,11 +488,11 @@ Previous behaviour: .. code-block:: ipython - In [1]: df = pd.read_csv(StringIO(''), engine='c') + In [1]: df = pd.read_csv(io.StringIO(''), engine='c') ... ValueError: No columns to parse from file - In [2]: df = pd.read_csv(StringIO(''), engine='python') + In [2]: df = pd.read_csv(io.StringIO(''), engine='python') ... StopIteration @@ -500,11 +500,11 @@ New behaviour: .. code-block:: ipython - In [1]: df = pd.read_csv(StringIO(''), engine='c') + In [1]: df = pd.read_csv(io.StringIO(''), engine='c') ... pandas.io.common.EmptyDataError: No columns to parse from file - In [2]: df = pd.read_csv(StringIO(''), engine='python') + In [2]: df = pd.read_csv(io.StringIO(''), engine='python') ... pandas.io.common.EmptyDataError: No columns to parse from file From 2d7d5e5382e371130009e73e0b19df9e2e9dde22 Mon Sep 17 00:00:00 2001 From: JimJeon Date: Mon, 17 Dec 2018 10:30:37 +0900 Subject: [PATCH 4/6] DOC: Remove pandas import from v0.18.1 --- doc/source/whatsnew/v0.18.1.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst index 306fbfb7c94f3..9c1844ac363f8 100644 --- a/doc/source/whatsnew/v0.18.1.rst +++ b/doc/source/whatsnew/v0.18.1.rst @@ -5,11 +5,6 @@ v0.18.1 (May 3, 2016) {{ header }} -.. ipython:: python - :suppress: - - from pandas import * # noqa F401, F403 - This is a minor bug-fix release from 0.18.0 and includes a large number of bug fixes along with several new features, enhancements, and performance improvements. From c3fd30fd456bf3f9ce4f22f3b2b6f902752ee83c Mon Sep 17 00:00:00 2001 From: JimJeon Date: Mon, 17 Dec 2018 12:09:11 +0900 Subject: [PATCH 5/6] DOC: Rearrange the import block --- doc/source/whatsnew/v0.18.1.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst index 9c1844ac363f8..419a7eace010e 100644 --- a/doc/source/whatsnew/v0.18.1.rst +++ b/doc/source/whatsnew/v0.18.1.rst @@ -471,10 +471,6 @@ New Behavior: Changes in ``read_csv`` exceptions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. ipython:: python - :suppress: - - import io In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` engines, both will now raise an ``EmptyDataError``, a subclass of ``ValueError``, in response to empty columns or header (:issue:`12493`, :issue:`12506`) @@ -482,12 +478,13 @@ In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` e Previous behaviour: .. code-block:: ipython + In [1]: import io - In [1]: df = pd.read_csv(io.StringIO(''), engine='c') + In [2]: df = pd.read_csv(io.StringIO(''), engine='c') ... ValueError: No columns to parse from file - In [2]: df = pd.read_csv(io.StringIO(''), engine='python') + In [3]: df = pd.read_csv(io.StringIO(''), engine='python') ... StopIteration From a17fa1b6b47d9af29fe6e5c9acf6089c1db0e359 Mon Sep 17 00:00:00 2001 From: JimJeon Date: Tue, 18 Dec 2018 10:31:04 +0900 Subject: [PATCH 6/6] DOC: Add a blank line --- doc/source/whatsnew/v0.18.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.18.1.rst b/doc/source/whatsnew/v0.18.1.rst index 419a7eace010e..f099ccf284bc2 100644 --- a/doc/source/whatsnew/v0.18.1.rst +++ b/doc/source/whatsnew/v0.18.1.rst @@ -478,6 +478,7 @@ In order to standardize the ``read_csv`` API for both the ``c`` and ``python`` e Previous behaviour: .. code-block:: ipython + In [1]: import io In [2]: df = pd.read_csv(io.StringIO(''), engine='c')