Skip to content

Commit 9e1b4e6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into pd.array
2 parents 50d4206 + 91802fb commit 9e1b4e6

File tree

128 files changed

+1537
-894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1537
-894
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
175175

176176
MSG='Doctests frame.py' ; echo $MSG
177177
pytest -q --doctest-modules pandas/core/frame.py \
178-
-k"-axes -combine -itertuples -join -pivot_table -quantile -query -reindex -reindex_axis -round"
178+
-k"-axes -combine -itertuples -join -pivot_table -query -reindex -reindex_axis -round"
179179
RET=$(($RET + $?)) ; echo $MSG "DONE"
180180

181181
MSG='Doctests series.py' ; echo $MSG

doc/source/10min.rst

+9-26
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
.. _10min:
22

3-
.. currentmodule:: pandas
4-
5-
.. ipython:: python
6-
:suppress:
7-
8-
import os
9-
import numpy as np
10-
11-
import pandas as pd
12-
13-
np.random.seed(123456)
14-
np.set_printoptions(precision=4, suppress=True)
15-
pd.options.display.max_rows = 15
16-
17-
# portions of this were borrowed from the
18-
# Pandas cheatsheet
19-
# created during the PyData Workshop-Sprint 2012
20-
# Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello
21-
3+
{{ header }}
224

235
********************
246
10 Minutes to pandas
@@ -69,7 +51,7 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s
6951
'F': 'foo'})
7052
df2
7153
72-
The columns of the resulting ``DataFrame`` have different
54+
The columns of the resulting ``DataFrame`` have different
7355
:ref:`dtypes <basics.dtypes>`.
7456

7557
.. ipython:: python
@@ -83,7 +65,7 @@ will be completed:
8365
.. ipython::
8466

8567
@verbatim
86-
In [1]: df2.<TAB>
68+
In [1]: df2.<TAB> # noqa: E225, E999
8769
df2.A df2.bool
8870
df2.abs df2.boxplot
8971
df2.add df2.C
@@ -513,7 +495,7 @@ Another example that can be given is:
513495
Append
514496
~~~~~~
515497

516-
Append rows to a dataframe. See the :ref:`Appending <merging.concatenation>`
498+
Append rows to a dataframe. See the :ref:`Appending <merging.concatenation>`
517499
section.
518500

519501
.. ipython:: python
@@ -546,14 +528,14 @@ See the :ref:`Grouping section <groupby>`.
546528
'D': np.random.randn(8)})
547529
df
548530
549-
Grouping and then applying the :meth:`~DataFrame.sum` function to the resulting
531+
Grouping and then applying the :meth:`~DataFrame.sum` function to the resulting
550532
groups.
551533

552534
.. ipython:: python
553535
554536
df.groupby('A').sum()
555537
556-
Grouping by multiple columns forms a hierarchical index, and again we can
538+
Grouping by multiple columns forms a hierarchical index, and again we can
557539
apply the ``sum`` function.
558540

559541
.. ipython:: python
@@ -689,7 +671,7 @@ Convert the raw grades to a categorical data type.
689671
df["grade"] = df["raw_grade"].astype("category")
690672
df["grade"]
691673
692-
Rename the categories to more meaningful names (assigning to
674+
Rename the categories to more meaningful names (assigning to
693675
``Series.cat.categories`` is inplace!).
694676

695677
.. ipython:: python
@@ -738,7 +720,7 @@ See the :ref:`Plotting <visualization>` docs.
738720
@savefig series_plot_basic.png
739721
ts.plot()
740722
741-
On a DataFrame, the :meth:`~DataFrame.plot` method is a convenience to plot all
723+
On a DataFrame, the :meth:`~DataFrame.plot` method is a convenience to plot all
742724
of the columns with labels:
743725

744726
.. ipython:: python
@@ -773,6 +755,7 @@ CSV
773755
.. ipython:: python
774756
:suppress:
775757
758+
import os
776759
os.remove('foo.csv')
777760
778761
HDF5

doc/source/advanced.rst

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
.. _advanced:
22

3-
.. currentmodule:: pandas
4-
5-
.. ipython:: python
6-
:suppress:
7-
8-
import numpy as np
9-
import pandas as pd
10-
np.random.seed(123456)
11-
np.set_printoptions(precision=4, suppress=True)
12-
pd.options.display.max_rows = 15
3+
{{ header }}
134

145
******************************
156
MultiIndex / Advanced Indexing
@@ -62,8 +53,9 @@ The :class:`MultiIndex` object is the hierarchical analogue of the standard
6253
can think of ``MultiIndex`` as an array of tuples where each tuple is unique. A
6354
``MultiIndex`` can be created from a list of arrays (using
6455
:meth:`MultiIndex.from_arrays`), an array of tuples (using
65-
:meth:`MultiIndex.from_tuples`), or a crossed set of iterables (using
66-
:meth:`MultiIndex.from_product`). The ``Index`` constructor will attempt to return
56+
:meth:`MultiIndex.from_tuples`), a crossed set of iterables (using
57+
:meth:`MultiIndex.from_product`), or a :class:`DataFrame` (using
58+
:meth:`MultiIndex.from_frame`). The ``Index`` constructor will attempt to return
6759
a ``MultiIndex`` when it is passed a list of tuples. The following examples
6860
demonstrate different ways to initialize MultiIndexes.
6961

@@ -89,6 +81,19 @@ to use the :meth:`MultiIndex.from_product` method:
8981
iterables = [['bar', 'baz', 'foo', 'qux'], ['one', 'two']]
9082
pd.MultiIndex.from_product(iterables, names=['first', 'second'])
9183
84+
You can also construct a ``MultiIndex`` from a ``DataFrame`` directly, using
85+
the method :meth:`MultiIndex.from_frame`. This is a complementary method to
86+
:meth:`MultiIndex.to_frame`.
87+
88+
.. versionadded:: 0.24.0
89+
90+
.. ipython:: python
91+
92+
df = pd.DataFrame([['bar', 'one'], ['bar', 'two'],
93+
['foo', 'one'], ['foo', 'two']],
94+
columns=['first', 'second'])
95+
pd.MultiIndex.from_frame(df)
96+
9297
As a convenience, you can pass a list of arrays directly into ``Series`` or
9398
``DataFrame`` to construct a ``MultiIndex`` automatically:
9499

@@ -558,7 +563,8 @@ they need to be sorted. As with any index, you can use :meth:`~DataFrame.sort_in
558563

559564
.. ipython:: python
560565
561-
import random; random.shuffle(tuples)
566+
import random
567+
random.shuffle(tuples)
562568
s = pd.Series(np.random.randn(8), index=pd.MultiIndex.from_tuples(tuples))
563569
s
564570
s.sort_index()

doc/source/api.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.. currentmodule:: pandas
21
.. _api:
32

3+
{{ header }}
4+
45
*************
56
API Reference
67
*************
@@ -1776,6 +1777,7 @@ MultiIndex Constructors
17761777
MultiIndex.from_arrays
17771778
MultiIndex.from_tuples
17781779
MultiIndex.from_product
1780+
MultiIndex.from_frame
17791781

17801782
MultiIndex Attributes
17811783
~~~~~~~~~~~~~~~~~~~~~

doc/source/basics.rst

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
.. currentmodule:: pandas
2-
3-
.. ipython:: python
4-
:suppress:
5-
6-
import numpy as np
7-
import pandas as pd
8-
9-
np.set_printoptions(precision=4, suppress=True)
10-
pd.options.display.max_rows = 15
11-
121
.. _basics:
132

3+
{{ header }}
4+
145
==============================
156
Essential Basic Functionality
167
==============================

doc/source/categorical.rst

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
.. _categorical:
22

3-
.. currentmodule:: pandas
4-
5-
.. ipython:: python
6-
:suppress:
7-
8-
import numpy as np
9-
import pandas as pd
10-
np.random.seed(123456)
11-
np.set_printoptions(precision=4, suppress=True)
12-
pd.options.display.max_rows = 15
13-
3+
{{ header }}
144

155
****************
166
Categorical Data
@@ -792,7 +782,7 @@ Setting values by assigning categorical data will also check that the `categorie
792782
df
793783
try:
794784
df.loc["j":"k", "cats"] = pd.Categorical(["b", "b"],
795-
categories=["a", "b", "c"])
785+
categories=["a", "b", "c"])
796786
except ValueError as e:
797787
print("ValueError:", str(e))
798788

doc/source/comparison_with_r.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
.. currentmodule:: pandas
21
.. _compare_with_r:
32

4-
.. ipython:: python
5-
:suppress:
6-
7-
import pandas as pd
8-
import numpy as np
9-
pd.options.display.max_rows = 15
3+
{{ header }}
104

115
Comparison with R / R libraries
126
*******************************

doc/source/comparison_with_sas.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.. currentmodule:: pandas
21
.. _compare_with_sas:
32

3+
{{ header }}
4+
45
Comparison with SAS
56
********************
67
For potential users coming from `SAS <https://en.wikipedia.org/wiki/SAS_(software)>`__

doc/source/comparison_with_sql.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.. currentmodule:: pandas
21
.. _compare_with_sql:
32

3+
{{ header }}
4+
45
Comparison with SQL
56
********************
67
Since many potential pandas users have some familiarity with

doc/source/comparison_with_stata.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.. currentmodule:: pandas
21
.. _compare_with_stata:
32

3+
{{ header }}
4+
45
Comparison with Stata
56
*********************
67
For potential users coming from `Stata <https://en.wikipedia.org/wiki/Stata>`__
@@ -675,5 +676,3 @@ If out of core processing is needed, one possibility is the
675676
`dask.dataframe <http://dask.pydata.org/en/latest/dataframe.html>`_
676677
library, which provides a subset of pandas functionality for an
677678
on-disk ``DataFrame``.
678-
679-

doc/source/computation.rst

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
.. currentmodule:: pandas
2-
3-
.. ipython:: python
4-
:suppress:
5-
6-
import numpy as np
7-
import matplotlib.pyplot as plt
8-
9-
import pandas as pd
10-
11-
np.random.seed(123456)
12-
np.set_printoptions(precision=4, suppress=True)
13-
pd.options.display.max_rows = 15
14-
15-
plt.close('all')
16-
171
.. _computation:
182

3+
{{ header }}
4+
195
Computational tools
206
===================
217

doc/source/conf.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,25 @@
301301
}
302302

303303

304-
common_imports = """\
304+
header = """\
305305
.. currentmodule:: pandas
306306
307307
.. ipython:: python
308308
:suppress:
309309
310310
import numpy as np
311-
from pandas import *
312311
import pandas as pd
312+
313313
randn = np.random.randn
314+
np.random.seed(123456)
314315
np.set_printoptions(precision=4, suppress=True)
315-
options.display.max_rows = 15
316-
from pandas.compat import StringIO
316+
pd.options.display.max_rows = 15
317317
"""
318318

319319

320320
html_context = {
321321
'redirects': {old: new for old, new in moved_api_pages},
322-
'common_imports': common_imports,
322+
'header': header
323323
}
324324

325325
# If false, no module index is generated.

doc/source/contributing.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. _contributing:
22

3+
{{ header }}
4+
35
**********************
46
Contributing to pandas
57
**********************
@@ -672,6 +674,7 @@ Otherwise, you need to do it manually:
672674
673675
import warnings
674676
677+
675678
def old_func():
676679
"""Summary of the function.
677680
@@ -681,6 +684,7 @@ Otherwise, you need to do it manually:
681684
warnings.warn('Use new_func instead.', FutureWarning, stacklevel=2)
682685
new_func()
683686
687+
684688
def new_func():
685689
pass
686690
@@ -816,7 +820,6 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
816820
import pytest
817821
import numpy as np
818822
import pandas as pd
819-
from pandas.util import testing as tm
820823
821824
822825
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
@@ -938,8 +941,10 @@ If your change involves checking that a warning is actually emitted, use
938941

939942
.. code-block:: python
940943
941-
df = pd.DataFrame()
944+
import pandas.util.testing as tm
945+
942946
947+
df = pd.DataFrame()
943948
with tm.assert_produces_warning(FutureWarning):
944949
df.some_operation()
945950

doc/source/contributing_docstring.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
.. _docstring:
22

3+
{{ header }}
4+
35
======================
46
pandas docstring guide
57
======================
68

7-
.. note::
8-
`Video tutorial: Pandas docstring guide
9-
<https://www.youtube.com/watch?v=EOA0lUeW4NI>`_ by Frank Akogun.
10-
119
About docstrings and standards
1210
------------------------------
1311

0 commit comments

Comments
 (0)