Skip to content

DOC: fix old whatsnew examples + few sphinx warnings #26780

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
Jun 11, 2019
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
57 changes: 42 additions & 15 deletions doc/source/whatsnew/v0.11.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,54 @@ Conversion

Mixed Conversion

.. ipython:: python
:okwarning:
.. code-block:: ipython

df3['D'] = '1.'
df3['E'] = '1'
df3.convert_objects(convert_numeric=True).dtypes
In [12]: df3['D'] = '1.'

# same, but specific dtype conversion
df3['D'] = df3['D'].astype('float16')
df3['E'] = df3['E'].astype('int32')
df3.dtypes
In [13]: df3['E'] = '1'

In [14]: df3.convert_objects(convert_numeric=True).dtypes
Out[14]:
A float32
B float64
C float64
D float64
E int64
dtype: object

# same, but specific dtype conversion
In [15]: df3['D'] = df3['D'].astype('float16')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe not a big issue since this matches current documentation, but are these types supposed to be exactly the same as the above? Comment suggests so but result does not

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think they are supposed to be exactly the same. convert_objects did a generic conversion, so using the 64 bit version by default. With astype you could specify a specific type.


In [16]: df3['E'] = df3['E'].astype('int32')

In [17]: df3.dtypes
Out[17]:
A float32
B float64
C float64
D float16
E int32
dtype: object

Forcing Date coercion (and setting ``NaT`` when not datelike)

.. ipython:: python
:okwarning:
.. code-block:: ipython

In [18]: import datetime

In [19]: s = pd.Series([datetime.datetime(2001, 1, 1, 0, 0), 'foo', 1.0, 1,
....: pd.Timestamp('20010104'), '20010105'], dtype='O')
....:

import datetime
s = pd.Series([datetime.datetime(2001, 1, 1, 0, 0), 'foo', 1.0, 1,
pd.Timestamp('20010104'), '20010105'], dtype='O')
s.convert_objects(convert_dates='coerce')
In [20]: s.convert_objects(convert_dates='coerce')
Out[20]:
0 2001-01-01
1 NaT
2 NaT
3 NaT
4 2001-01-04
5 2001-01-05
dtype: datetime64[ns]

Dtype Gotchas
~~~~~~~~~~~~~
Expand Down
44 changes: 33 additions & 11 deletions doc/source/whatsnew/v0.13.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,39 @@ This is like an ``append`` operation.

A Panel setting operation on an arbitrary axis aligns the input to the Panel

.. ipython:: python
:okwarning:

p = pd.Panel(np.arange(16).reshape(2, 4, 2),
items=['Item1', 'Item2'],
major_axis=pd.date_range('2001/1/12', periods=4),
minor_axis=['A', 'B'], dtype='float64')
p
p.loc[:, :, 'C'] = pd.Series([30, 32], index=p.items)
p
p.loc[:, :, 'C']
.. code-block:: ipython

In [20]: p = pd.Panel(np.arange(16).reshape(2, 4, 2),
....: items=['Item1', 'Item2'],
....: major_axis=pd.date_range('2001/1/12', periods=4),
....: minor_axis=['A', 'B'], dtype='float64')
....:

In [21]: p
Out[21]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to B

In [22]: p.loc[:, :, 'C'] = pd.Series([30, 32], index=p.items)

In [23]: p
Out[23]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 3 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to C

In [24]: p.loc[:, :, 'C']
Out[24]:
Item1 Item2
2001-01-12 30.0 32.0
2001-01-13 30.0 32.0
2001-01-14 30.0 32.0
2001-01-15 30.0 32.0

Float64Index API Change
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
18 changes: 8 additions & 10 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,27 @@ Constructing a :class:`MultiIndex` with ``NaN`` levels or codes value < -1 was a
Now, construction with codes value < -1 is not allowed and ``NaN`` levels' corresponding codes
would be reassigned as -1. (:issue:`19387`)

.. ipython:: python

mi1 = pd.MultiIndex(levels=[[np.nan, None, pd.NaT, 128, 2]],
codes=[[0, -1, 1, 2, 3, 4]])
mi2 = pd.MultiIndex(levels=[[1, 2]], codes=[[0, -2]])

*Previous Behavior*:

.. code-block:: ipython

In [1]: mi1
In [1]: pd.MultiIndex(levels=[[np.nan, None, pd.NaT, 128, 2]],
...: codes=[[0, -1, 1, 2, 3, 4]])
...:
Out[1]: MultiIndex(levels=[[nan, None, NaT, 128, 2]],
codes=[[0, -1, 1, 2, 3, 4]])
In [2]: mi2

In [2]: pd.MultiIndex(levels=[[1, 2]], codes=[[0, -2]])
Out[2]: MultiIndex(levels=[[1, 2]],
codes=[[0, -2]])

*New Behavior*:

.. ipython:: python

mi1
mi2
mi1 = pd.MultiIndex(levels=[[np.nan, None, pd.NaT, 128, 2]],
Copy link
Member

Choose a reason for hiding this comment

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

This isn't equivalent right? Don't we need to show construction and print separately?

Copy link
Member Author

Choose a reason for hiding this comment

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

whoops, good catch. Meant to remove the mi1 = as I did above

codes=[[0, -1, 1, 2, 3, 4]])
mi2 = pd.MultiIndex(levels=[[1, 2]], codes=[[0, -2]])


.. _whatsnew_0250.api_breaking.groupby_apply_first_group_once:
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4000,6 +4000,7 @@ def rename(self, *args, **kwargs):
intent.

Rename columns using a mapping:

>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df.rename(columns={"A": "a", "B": "c"})
a c
Expand All @@ -4008,13 +4009,15 @@ def rename(self, *args, **kwargs):
2 3 6

Rename index using a mapping:

>>> df.rename(index={0: "x", 1: "y", 2: "z"})
A B
x 1 4
y 2 5
z 3 6

Cast index labels to a different type:

>>> df.index
RangeIndex(start=0, stop=3, step=1)
>>> df.rename(index=str).index
Expand Down
1 change: 1 addition & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10867,6 +10867,7 @@ def _doc_parms(cls):
level_output_1=0)

_stat_func_see_also = """

See Also
--------
Series.sum : Return the sum.
Expand Down