Skip to content

Commit 0e9c4a4

Browse files
committed
fix docs as per review & column name changes
1 parent 3df0abe commit 0e9c4a4

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

doc/source/computation.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ In financial data analysis and other fields it's common to compute covariance
534534
and correlation matrices for a collection of time series. Often one is also
535535
interested in moving-window covariance and correlation matrices. This can be
536536
done by passing the ``pairwise`` keyword argument, which in the case of
537-
``DataFrame`` inputs will yield a ``MultiIndexed DataFrame`` whose ``index`` are the dates in
537+
``DataFrame`` inputs will yield a MultiIndexed ``DataFrame`` whose ``index`` are the dates in
538538
question. In the case of a single DataFrame argument the ``pairwise`` argument
539539
can even be omitted:
540540

@@ -549,12 +549,12 @@ can even be omitted:
549549
.. ipython:: python
550550
551551
covs = df[['B','C','D']].rolling(window=50).cov(df[['A','B','C']], pairwise=True)
552-
covs.unstack(-1).iloc[-50]
552+
covs.loc['2002-09-22':]
553553
554554
.. ipython:: python
555555
556556
correls = df.rolling(window=50).corr()
557-
correls.unstack(-1).iloc[-50]
557+
correls.loc['2002-09-22':]
558558
559559
You can efficiently retrieve the time series of correlations between two
560560
columns using ``.loc`` indexing:
@@ -567,7 +567,7 @@ columns using ``.loc`` indexing:
567567
.. ipython:: python
568568
569569
@savefig rolling_corr_pairwise_ex.png
570-
correls.unstack(-1).[('A', 'C')].plot()
570+
correls.loc[:, ('A', 'C')].plot()
571571
572572
.. _stats.aggregate:
573573

doc/source/dsintro.rst

+9
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ From 3D ndarray with optional axis labels
788788
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
789789

790790
.. ipython:: python
791+
:okwarning:
791792
792793
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
793794
major_axis=pd.date_range('1/1/2000', periods=5),
@@ -799,6 +800,7 @@ From dict of DataFrame objects
799800
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
800801

801802
.. ipython:: python
803+
:okwarning:
802804
803805
data = {'Item1' : pd.DataFrame(np.random.randn(4, 3)),
804806
'Item2' : pd.DataFrame(np.random.randn(4, 2))}
@@ -821,6 +823,7 @@ dictionary of DataFrames as above, and the following named parameters:
821823
For example, compare to the construction above:
822824

823825
.. ipython:: python
826+
:okwarning:
824827
825828
pd.Panel.from_dict(data, orient='minor')
826829
@@ -829,6 +832,7 @@ DataFrame objects with mixed-type columns, all of the data will get upcasted to
829832
``dtype=object`` unless you pass ``orient='minor'``:
830833

831834
.. ipython:: python
835+
:okwarning:
832836
833837
df = pd.DataFrame({'a': ['foo', 'bar', 'baz'],
834838
'b': np.random.randn(3)})
@@ -856,6 +860,7 @@ This method was introduced in v0.7 to replace ``LongPanel.to_long``, and convert
856860
a DataFrame with a two-level index to a Panel.
857861

858862
.. ipython:: python
863+
:okwarning:
859864
860865
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]])
861866
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
@@ -885,6 +890,7 @@ A Panel can be rearranged using its ``transpose`` method (which does not make a
885890
copy by default unless the data are heterogeneous):
886891

887892
.. ipython:: python
893+
:okwarning:
888894
889895
wp.transpose(2, 0, 1)
890896
@@ -914,6 +920,7 @@ Squeezing
914920
Another way to change the dimensionality of an object is to ``squeeze`` a 1-len object, similar to ``wp['Item1']``
915921

916922
.. ipython:: python
923+
:okwarning:
917924
918925
wp.reindex(items=['Item1']).squeeze()
919926
wp.reindex(items=['Item1'], minor=['B']).squeeze()
@@ -928,6 +935,7 @@ for more on this. To convert a Panel to a DataFrame, use the ``to_frame``
928935
method:
929936

930937
.. ipython:: python
938+
:okwarning:
931939
932940
panel = pd.Panel(np.random.randn(3, 5, 4), items=['one', 'two', 'three'],
933941
major_axis=pd.date_range('1/1/2000', periods=5),
@@ -964,6 +972,7 @@ support the multi-dimensional analysis that is one of ``Panel`` s main usecases.
964972
Convert to a MultiIndex DataFrame
965973

966974
.. ipython:: python
975+
:okwarning:
967976
968977
p.to_frame()
969978

doc/source/whatsnew/v0.20.0.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Highlights include:
1414
- Improved user API when accessing levels in ``.groupby()``, see :ref:`here <whatsnew_0200.enhancements.groupby_access>`
1515
- Improved support for UInt64 dtypes, see :ref:`here <whatsnew_0200.enhancements.uint64_support>`
1616
- A new orient for JSON serialization, ``orient='table'``, that uses the Table Schema spec, see :ref:`here <whatsnew_0200.enhancements.table_schema>`
17-
- Window Binary Corr/Cov operations return a MultiIndex DataFrame rather than a Panel, see :ref:`here <whhatsnew_0200.api_breaking.rolling_pairwise>`
17+
- Window Binary Corr/Cov operations return a MultiIndexed ``DataFrame`` rather than a ``Panel``, as ``Panel`` is now deprecated, see :ref:`here <whatsnew_0200.api_breaking.rolling_pairwise>`
1818
- Support for S3 handling now uses ``s3fs``, see :ref:`here <whatsnew_0200.api_breaking.s3>`
1919
- Google BigQuery support now uses the ``pandas-gbq`` library, see :ref:`here <whatsnew_0200.api_breaking.gbq>`
2020
- Switched the test framework to use `pytest <http://doc.pytest.org/en/latest>`__ (:issue:`13097`)
@@ -872,8 +872,9 @@ Window Binary Corr/Cov operations return a MultiIndex DataFrame
872872
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
873873

874874
A binary window operation, like ``.corr()`` or ``.cov()``, when operating on a ``.rolling(..)``, ``.expanding(..)``, or ``.ewm(..)`` object,
875-
will now return a 2-level ``MultiIndexed DataFrame`` rather than a ``Panel``. These are equivalent in function,
876-
but MultiIndexed DataFrames enjoy more support in pandas.
875+
will now return a 2-level ``MultiIndexed DataFrame`` rather than a ``Panel``, as ``Panel`` is now deprecated,
876+
see :ref:`here <_whatsnew_0200.api_breaking.deprecate_panel>`. These are equivalent in function,
877+
but MultiIndexed ``DataFrame`` s enjoy more support in pandas.
877878
See the section on :ref:`Windowed Binary Operations <stats.moments.binary>` for more information. (:issue:`15677`)
878879

879880
.. ipython:: python
@@ -883,7 +884,7 @@ See the section on :ref:`Windowed Binary Operations <stats.moments.binary>` for
883884
columns=pd.Index(['A', 'B'], name='bar'),
884885
index=pd.date_range('20160101',
885886
periods=100, freq='D', name='foo'))
886-
df
887+
df.tail()
887888

888889
Old Behavior:
889890

@@ -902,7 +903,7 @@ New Behavior:
902903
.. ipython:: python
903904

904905
res = df.rolling(12).corr()
905-
res
906+
res.tail()
906907

907908
Retrieving a correlation matrix for a cross-section
908909

pandas/core/window.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1730,9 +1730,11 @@ def dataframe_from_int_dict(data, frame_template):
17301730
columns=arg2.columns,
17311731
dtype='float64')
17321732

1733-
# reset our names to arg1 names
1733+
# reset our index names to arg1 names
1734+
# reset our column names to arg2 names
17341735
# careful not to mutate the original names
1735-
result.columns = Index(result.columns).set_names(None)
1736+
result.columns = Index(result.columns).set_names(
1737+
arg2.columns.name)
17361738
result.index = result.index.set_names(
17371739
[arg1.index.name, arg1.columns.name])
17381740

pandas/tests/test_window.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2751,7 +2751,7 @@ def test_moment_functions_zero_length_pairwise(self):
27512751
df2_expected = DataFrame(
27522752
index=pd.MultiIndex.from_product([df2.index, df2.columns],
27532753
names=['bar', 'foo']),
2754-
columns=Index(['a']),
2754+
columns=Index(['a'], name='foo'),
27552755
dtype='float64')
27562756

27572757
functions = [lambda x: (x.expanding(min_periods=5)
@@ -2789,7 +2789,7 @@ def test_expanding_cov_pairwise_diff_length(self):
27892789
result3 = df1a.expanding().cov(df2, pairwise=True).loc[2]
27902790
result4 = df1a.expanding().cov(df2a, pairwise=True).loc[2]
27912791
expected = DataFrame([[-3.0, -6.0], [-5.0, -10.0]],
2792-
columns=['A', 'B'],
2792+
columns=Index(['A', 'B'], name='foo'),
27932793
index=Index(['X', 'Y'], name='foo'))
27942794
tm.assert_frame_equal(result1, expected)
27952795
tm.assert_frame_equal(result2, expected)

0 commit comments

Comments
 (0)