Skip to content

Flake8 rst v0.14.x.rst #24253

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 9 commits into from
Dec 14, 2018
153 changes: 89 additions & 64 deletions doc/source/whatsnew/v0.14.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ v0.14.0 (May 31 , 2014)
.. ipython:: python
:suppress:

from pandas import * # noqa F401, F403


This is a major release from 0.13.1 and includes a small number of API changes, several new features,
Expand Down Expand Up @@ -64,21 +63,23 @@ API changes

.. ipython:: python

dfl = DataFrame(np.random.randn(5,2),columns=list('AB'))
import pandas.DataFrame as DataFrame
dfl = DataFrame(np.random.randn(5, 2), columns=list('AB'))
dfl
dfl.iloc[:,2:3]
dfl.iloc[:,1:3]
dfl.iloc[:, 2:3]
dfl.iloc[:, 1:3]
dfl.iloc[4:6]

These are out-of-bounds selections

.. code-block:: python

dfl.iloc[[4,5,6]]
IndexError: positional indexers are out-of-bounds
dfl.iloc[[4, 5, 6]]
IndexError: positional indexers are out-of-bounds

dfl.iloc[:,4]
IndexError: single positional indexer is out-of-bounds
.. code-block:: python
dfl.iloc[:, 4]
IndexError: single positional indexer is out-of-bounds

- Slicing with negative start, stop & step values handles corner cases better (:issue:`6531`):

Expand Down Expand Up @@ -120,29 +121,31 @@ API changes

.. ipython:: python

i = pd.Index([1, 2, 3, 'a' , 'b', 'c'])
i[[0,1,2]]
i = pd.Index([1, 2, 3, 'a', 'b', 'c'])
i[[0, 1, 2]]
i.drop(['a', 'b', 'c'])

Previously, the above operation would return ``Int64Index``. If you'd like
to do this manually, use :meth:`Index.astype`

.. ipython:: python

i[[0,1,2]].astype(np.int_)
i[[0, 1, 2]].astype(np.int_)

- ``set_index`` no longer converts MultiIndexes to an Index of tuples. For example,
the old behavior returned an Index in this case (:issue:`6459`):

.. ipython:: python
:suppress:

import pandas.MultiIndex as MultiIndex
import pandas.Series as Series
np.random.seed(1234)
from itertools import product
tuples = list(product(('a', 'b'), ('c', 'd')))
mi = MultiIndex.from_tuples(tuples)
df_multi = DataFrame(np.random.randn(4, 2), index=mi)
tuple_ind = pd.Index(tuples,tupleize_cols=False)
tuple_ind = pd.Index(tuples, tupleize_cols=False)
df_multi.index

.. ipython:: python
Expand Down Expand Up @@ -180,9 +183,13 @@ API changes

.. code-block:: ipython

In [1]: df = DataFrame(np.random.randn(10,4),columns=list('ABCD'))
In [1]: df = DataFrame(np.random.randn(10, 4), columns=list('ABCD'))

In [4]: covs = pd.rolling_cov(df[['A', 'B', 'C']],
....: df[['B', 'C', 'D']],
....: 5,
....: pairwise=True)

In [4]: covs = pd.rolling_cov(df[['A','B','C']], df[['B','C','D']], 5, pairwise=True)

In [5]: covs[df.index[-1]]
Out[5]:
Expand Down Expand Up @@ -219,7 +226,7 @@ API changes
x + y # warning generated: should do x | y instead
x / y # this raises because it doesn't make sense

NotImplementedError: operator '/' not implemented for bool dtypes
NotImplementedError: operator '/' not implemented for bool dtypes

- In ``HDFStore``, ``select_as_multiple`` will always raise a ``KeyError``, when a key or the selector is not found (:issue:`6177`)
- ``df['col'] = value`` and ``df.loc[:,'col'] = value`` are now completely equivalent;
Expand Down Expand Up @@ -274,17 +281,19 @@ Display Changes

.. ipython:: python

dfd = pd.DataFrame(np.arange(25).reshape(-1,5), index=[0,1,2,3,4], columns=[0,1,2,3,4])
dfd = pd.DataFrame(np.arange(25).reshape(-1, 5),
index=[0, 1, 2, 3, 4],
columns=[0, 1, 2, 3, 4])

# show dimensions since this is truncated
with pd.option_context('display.max_rows', 2, 'display.max_columns', 2,
'display.show_dimensions', 'truncate'):
print(dfd)
print(dfd)

# will not show dimensions since it is not truncated
with pd.option_context('display.max_rows', 10, 'display.max_columns', 40,
'display.show_dimensions', 'truncate'):
print(dfd)
print(dfd)

- Regression in the display of a MultiIndexed Series with ``display.max_rows`` is less than the
length of the series (:issue:`7101`)
Expand Down Expand Up @@ -361,7 +370,7 @@ More consistent behaviour for some groupby methods:

.. ipython:: python

gf = df.groupby('A',as_index=False)
gf = df.groupby('A', as_index=False)
gf.nth(0)
gf.nth(0, dropna='any')

Expand All @@ -380,7 +389,7 @@ More consistent behaviour for some groupby methods:
.. ipython:: python

df = DataFrame([[1, np.nan], [1, 4], [5, 6], [5, 8]], columns=['A', 'B'])
g = df.groupby('A',as_index=False)
g = df.groupby('A', as_index=False)
g.count()
g.describe()

Expand Down Expand Up @@ -434,7 +443,7 @@ This ``engine`` can then be used to write or read data to/from this database:

.. ipython:: python

df = pd.DataFrame({'A': [1,2,3], 'B': ['a', 'b', 'c']})
df = pd.DataFrame({'A': [1, 2, 3], 'B': ['a', 'b', 'c']})
df.to_sql('db_table', engine, index=False)

You can read data from a database by specifying the table name:
Expand Down Expand Up @@ -496,33 +505,34 @@ See also issues (:issue:`6134`, :issue:`4036`, :issue:`3057`, :issue:`2598`, :is

You should do this:

.. code-block:: python
.. code-block:: python

df.loc[(slice('A1','A3'),.....),:]
df.loc[(slice('A1', 'A3'), .....), :]

rather than this:

.. code-block:: python
.. code-block:: python

df.loc[(slice('A1','A3'),.....)]
df.loc[(slice('A1', 'A3'), .....)]

.. warning::

You will need to make sure that the selection axes are fully lexsorted!

.. ipython:: python

def mklbl(prefix,n):
return ["%s%s" % (prefix,i) for i in range(n)]

index = MultiIndex.from_product([mklbl('A',4),
mklbl('B',2),
mklbl('C',4),
mklbl('D',2)])
columns = MultiIndex.from_tuples([('a','foo'),('a','bar'),
('b','foo'),('b','bah')],
names=['lvl0', 'lvl1'])
df = DataFrame(np.arange(len(index)*len(columns)).reshape((len(index),len(columns))),
def mklbl(prefix, n):
return ["%s%s" % (prefix, i) for i in range(n)]

index = MultiIndex.from_product([mklbl('A', 4),
mklbl('B', 2),
mklbl('C', 4),
mklbl('D', 2)])
columns = MultiIndex.from_tuples([('a', 'foo'), ('a', 'bar'),
('b', 'foo'), ('b', 'bah')],
names=['lvl0', 'lvl1'])
df = DataFrame(np.arange(len(index) * len(columns)).reshape((len(index),
len(columns))),
index=index,
columns=columns).sort_index().sort_index(axis=1)
df
Expand All @@ -531,51 +541,51 @@ Basic MultiIndex slicing using slices, lists, and labels.

.. ipython:: python

df.loc[(slice('A1','A3'),slice(None), ['C1','C3']),:]
df.loc[(slice('A1', 'A3'), slice(None), ['C1', 'C3']), :]

You can use a ``pd.IndexSlice`` to shortcut the creation of these slices

.. ipython:: python

idx = pd.IndexSlice
df.loc[idx[:,:,['C1','C3']],idx[:,'foo']]
df.loc[idx[:, :, ['C1', 'C3']], idx[:, 'foo']]

It is possible to perform quite complicated selections using this method on multiple
axes at the same time.

.. ipython:: python

df.loc['A1',(slice(None),'foo')]
df.loc[idx[:,:,['C1','C3']],idx[:,'foo']]
df.loc['A1', (slice(None), 'foo')]
df.loc[idx[:, :, ['C1', 'C3']], idx[:, 'foo']]

Using a boolean indexer you can provide selection related to the *values*.

.. ipython:: python

mask = df[('a','foo')]>200
df.loc[idx[mask,:,['C1','C3']],idx[:,'foo']]
mask = df[('a', 'foo')] > 200
df.loc[idx[mask, :, ['C1', 'C3']], idx[:, 'foo']]

You can also specify the ``axis`` argument to ``.loc`` to interpret the passed
slicers on a single axis.

.. ipython:: python

df.loc(axis=0)[:,:,['C1','C3']]
df.loc(axis=0)[:, :, ['C1', 'C3']]

Furthermore you can *set* the values using these methods

.. ipython:: python

df2 = df.copy()
df2.loc(axis=0)[:,:,['C1','C3']] = -10
df2.loc(axis=0)[:, :, ['C1', 'C3']] = -10
df2

You can use a right-hand-side of an alignable object as well.

.. ipython:: python

df2 = df.copy()
df2.loc[idx[:,:,['C1','C3']],:] = df2*1000
df2.loc[idx[:, :, ['C1', 'C3']], :] = df2 * 1000
df2

.. _whatsnew_0140.plotting:
Expand Down Expand Up @@ -672,25 +682,25 @@ Deprecations
.. code-block:: ipython

# non-floating point indexes can only be indexed by integers / labels
In [1]: Series(1,np.arange(5))[3.0]
In [1]: Series(1, np.arange(5))[3.0]
pandas/core/index.py:469: FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[1]: 1

In [2]: Series(1,np.arange(5)).iloc[3.0]
In [2]: Series(1, np.arange(5)).iloc[3.0]
pandas/core/index.py:469: FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
Out[2]: 1

In [3]: Series(1,np.arange(5)).iloc[3.0:4]
In [3]: Series(1, np.arange(5)).iloc[3.0:4]
pandas/core/index.py:527: FutureWarning: slice indexers when using iloc should be integers and not floating point
Out[3]:
3 1
dtype: int64

# these are Float64Indexes, so integer or floating point is acceptable
In [4]: Series(1,np.arange(5.))[3]
In [4]: Series(1, np.arange(5.))[3]
Out[4]: 1

In [5]: Series(1,np.arange(5.))[3.0]
In [5]: Series(1, np.arange(5.))[3.0]
Out[6]: 1

- Numpy 1.9 compat w.r.t. deprecation warnings (:issue:`6960`)
Expand Down Expand Up @@ -762,20 +772,34 @@ Enhancements

.. ipython:: python

household = DataFrame(dict(household_id = [1,2,3],
male = [0,1,0],
wealth = [196087.3,316478.7,294750]),
columns = ['household_id','male','wealth']
).set_index('household_id')
household = DataFrame({
'household_id': [1, 2, 3],
'male': [0, 1, 0],
'wealth': [196087.3, 316478.7, 294750]
},
columns=['household_id', 'male', 'wealth']
).set_index('household_id')
household
portfolio = DataFrame(dict(household_id = [1,2,2,3,3,3,4],
asset_id = ["nl0000301109","nl0000289783","gb00b03mlx29",
"gb00b03mlx29","lu0197800237","nl0000289965",np.nan],
name = ["ABN Amro","Robeco","Royal Dutch Shell","Royal Dutch Shell",
"AAB Eastern Europe Equity Fund","Postbank BioTech Fonds",np.nan],
share = [1.0,0.4,0.6,0.15,0.6,0.25,1.0]),
columns = ['household_id','asset_id','name','share']
).set_index(['household_id','asset_id'])
portfolio = DataFrame({
'household_id': [1, 2, 2, 3, 3, 3, 4],
'asset_id': ["nl0000301109",
"nl0000289783",
"gb00b03mlx29",
"gb00b03mlx29",
"lu0197800237",
"nl0000289965",
np.nan],
'name': ["ABN Amro",
"Robeco",
"Royal Dutch Shell",
"Royal Dutch Shell",
"AAB Eastern Europe Equity Fund",
"Postbank BioTech Fonds",
np.nan],
'share': [1.0, 0.4, 0.6, 0.15, 0.6, 0.25, 1.0]
},
columns=['household_id', 'asset_id', 'name', 'share']
).set_index(['household_id', 'asset_id'])
portfolio

household.join(portfolio, how='inner')
Expand Down Expand Up @@ -833,6 +857,7 @@ Enhancements

.. ipython:: python

import pandas.period_range as period_range
prng = period_range('2013-01-01 09:00', periods=100, freq='H')
ps = Series(np.random.randn(len(prng)), index=prng)
ps
Expand Down Expand Up @@ -1062,4 +1087,4 @@ Bug Fixes
Contributors
~~~~~~~~~~~~

.. contributors:: v0.13.1..v0.14.0
.. contributors:: v0.13.1..v0.14.0
Loading