Skip to content

DOC: Fix flake8 issues with whatsnew v0.18.* #24303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions doc/source/whatsnew/v0.18.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -102,7 +102,7 @@ with tab-completion of available methods and properties.

.. code-block:: ipython

In [9]: r.
In [9]: r.<TAB>
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

Expand All @@ -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:

Expand Down Expand Up @@ -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)

Expand All @@ -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``.
Expand Down Expand Up @@ -270,13 +270,13 @@ match.

s = pd.Series(["a1a2", "b1", "c1"], ["A", "B", "C"])
s
s.str.extract("(?P<letter>[ab])(?P<digit>\d)", expand=False)
s.str.extract(r"(?P<letter>[ab])(?P<digit>\d)", expand=False)

The ``extractall`` method returns all matches.

.. ipython:: python

s.str.extractall("(?P<letter>[ab])(?P<digit>\d)")
s.str.extractall(r"(?P<letter>[ab])(?P<digit>\d)")

.. _whatsnew_0180.enhancements.strcat:

Expand All @@ -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?


Expand Down Expand Up @@ -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')

Expand All @@ -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]:
Expand All @@ -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))
Expand Down Expand Up @@ -727,7 +727,8 @@ Like the change in the window functions API :ref:`above <whatsnew_0180.enhanceme
np.random.seed(1234)
df = pd.DataFrame(np.random.rand(10,4),
columns=list('ABCD'),
index=pd.date_range('2010-01-01 09:00:00', periods=10, freq='s'))
index=pd.date_range('2010-01-01 09:00:00',
periods=10, freq='s'))
df


Expand Down
34 changes: 22 additions & 12 deletions doc/source/whatsnew/v0.18.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Friday before MLK Day

.. ipython:: python

from datetime import datetime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use import datetime instead, and use datetime.datetime(...) below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. May I ask why you prefer that?
Is that because it can cause some namespace issues?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many reasons, and some are not trivial to explain.

The main one is that if I see a bare datetime in Python code, I need to guess whether it's the main module, or the datetime.datetime module. While there is no ambiguity in reading datetime.datetime.

Then, with a from datetime import datetime I load the whole datetime module in sys.modules, but I only have access in the namespace to the datetime.datetime submodule (with the name datetime). This won't let me perform operations like imp.reload(datetime), as I don't have anything in the namespace pointing to the main datetime module.

dt = datetime(2014, 1, 17, 15)

dt + bhour_us
Expand Down Expand Up @@ -171,8 +172,7 @@ without using temporary variable.
bb = pd.read_csv('data/baseball.csv', index_col='id')
(bb.groupby(['year', 'team'])
.sum()
.loc[lambda df: df.r > 100]
)
.loc[lambda df: df.r > 100])

.. _whatsnew_0181.partial_string_indexing:

Expand All @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this indentation confusing. If the lines are too long, can we use something like:

dft2 = pd.DataFrame(
    np.random.randn(20, 1),
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment. I wasn't flexible with that. I'll fix it.

periods=10,
freq='12H'),
['a', 'b']]))
dft2
dft2.loc['2013-01-05']

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -451,15 +454,17 @@ New Behavior:
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block:: python
.. code-block:: ipython


# 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
2000-11-30 13
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
Expand All @@ -471,6 +476,11 @@ New Behavior:
Changes in ``read_csv`` exceptions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. ipython:: python
:suppress:

from io import StringIO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use import io instead, and have the import visible in the next block, where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll fix it.


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`)

Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down