From acf37548726d25e7d8735725031cb6dc197cd53b Mon Sep 17 00:00:00 2001 From: Tuan Date: Sun, 2 Jul 2017 22:02:48 +1000 Subject: [PATCH 1/5] fix multi index names --- pandas/core/window.py | 2 +- pandas/tests/indexes/test_multi.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 01b1bdc3e5054..1e16eff7d56cc 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -1948,7 +1948,7 @@ def dataframe_from_int_dict(data, frame_template): result.columns = Index(result.columns).set_names( arg2.columns.name) result.index = result.index.set_names( - [arg1.index.name, arg1.columns.name]) + arg1.index.names + arg1.columns.names) return result diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index ef8806246c2c5..0d3a4d391f9e4 100644 --- a/pandas/tests/indexes/test_multi.py +++ b/pandas/tests/indexes/test_multi.py @@ -61,6 +61,15 @@ def f(): tm.assert_raises_regex(ValueError, 'The truth value of a', f) + def test_multi_index_names(self): + cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], names=['1', '2']) + df = pd.DataFrame(np.ones((10, 6)), columns=cols) + rolling_result = df.rolling(3).cov() + assert rolling_result.index.names == [None, '1', '2'] + assert (rolling_result.index.levels[0] == list(range(10))).all() + assert (rolling_result.index.levels[1] == ['A', 'B']).all() + assert (rolling_result.index.levels[2] == ['C', 'D', 'E']).all() + def test_labels_dtypes(self): # GH 8456 From 6c9079a49276f2d2bc32bce430218a94a868f4cb Mon Sep 17 00:00:00 2001 From: Tuan Date: Sun, 2 Jul 2017 22:36:53 +1000 Subject: [PATCH 2/5] fix line length to pep8 --- pandas/tests/indexes/test_multi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index 0d3a4d391f9e4..4d8ba262bf17b 100644 --- a/pandas/tests/indexes/test_multi.py +++ b/pandas/tests/indexes/test_multi.py @@ -62,7 +62,8 @@ def f(): tm.assert_raises_regex(ValueError, 'The truth value of a', f) def test_multi_index_names(self): - cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], names=['1', '2']) + cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], + names=['1', '2']) df = pd.DataFrame(np.ones((10, 6)), columns=cols) rolling_result = df.rolling(3).cov() assert rolling_result.index.names == [None, '1', '2'] From e1c772e052a635f592aa5b40aed12e271519e596 Mon Sep 17 00:00:00 2001 From: Tuan Date: Mon, 3 Jul 2017 18:52:09 +1000 Subject: [PATCH 3/5] added what's new entry and reference issue number in test --- doc/source/whatsnew/v0.20.3.txt | 2 +- pandas/tests/indexes/test_multi.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index b2d382a3202a5..aadaff0806921 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -39,7 +39,7 @@ Bug Fixes - Fixed issue with dataframe scatter plot for categorical data that reports incorrect column key not found when categorical data is used for plotting (:issue:`16199`) - Fixed a pytest marker failing downstream packages' tests suites (:issue:`16680`) - Fixed compat with loading a ``DataFrame`` with a ``PeriodIndex``, from a ``format='fixed'`` HDFStore, in Python 3, that was written in Python 2 (:issue:`16781`) - +- Fixed bug in ``pandas.core.window_flex_binary_moment()`` when a multi-index DataFrame is passed in as ``arg1`` (:issue:`16789`) Conversion ^^^^^^^^^^ diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index 0d3a4d391f9e4..bfb0467bf9bd5 100644 --- a/pandas/tests/indexes/test_multi.py +++ b/pandas/tests/indexes/test_multi.py @@ -62,13 +62,12 @@ def f(): tm.assert_raises_regex(ValueError, 'The truth value of a', f) def test_multi_index_names(self): + + # GH 16789 cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], names=['1', '2']) df = pd.DataFrame(np.ones((10, 6)), columns=cols) rolling_result = df.rolling(3).cov() assert rolling_result.index.names == [None, '1', '2'] - assert (rolling_result.index.levels[0] == list(range(10))).all() - assert (rolling_result.index.levels[1] == ['A', 'B']).all() - assert (rolling_result.index.levels[2] == ['C', 'D', 'E']).all() def test_labels_dtypes(self): From a3a60c4712d0d533d7cb86c6590bd7c596871651 Mon Sep 17 00:00:00 2001 From: Tuan Date: Mon, 3 Jul 2017 18:56:34 +1000 Subject: [PATCH 4/5] Update test_multi.py --- pandas/tests/indexes/test_multi.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index 882612f35e5fa..03f90b25415bb 100644 --- a/pandas/tests/indexes/test_multi.py +++ b/pandas/tests/indexes/test_multi.py @@ -62,14 +62,10 @@ def f(): tm.assert_raises_regex(ValueError, 'The truth value of a', f) def test_multi_index_names(self): -<<<<<<< HEAD # GH 16789 - cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], names=['1', '2']) -======= cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']], names=['1', '2']) ->>>>>>> 6c9079a49276f2d2bc32bce430218a94a868f4cb df = pd.DataFrame(np.ones((10, 6)), columns=cols) rolling_result = df.rolling(3).cov() assert rolling_result.index.names == [None, '1', '2'] From 8782abbbb962f329809dee2c0f80a45684ba409d Mon Sep 17 00:00:00 2001 From: Tuan Date: Mon, 3 Jul 2017 23:05:25 +1000 Subject: [PATCH 5/5] Update v0.20.3.txt --- doc/source/whatsnew/v0.20.3.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index aadaff0806921..c4768f980bc6a 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -39,7 +39,7 @@ Bug Fixes - Fixed issue with dataframe scatter plot for categorical data that reports incorrect column key not found when categorical data is used for plotting (:issue:`16199`) - Fixed a pytest marker failing downstream packages' tests suites (:issue:`16680`) - Fixed compat with loading a ``DataFrame`` with a ``PeriodIndex``, from a ``format='fixed'`` HDFStore, in Python 3, that was written in Python 2 (:issue:`16781`) -- Fixed bug in ``pandas.core.window_flex_binary_moment()`` when a multi-index DataFrame is passed in as ``arg1`` (:issue:`16789`) +- Fixed bug where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`) Conversion ^^^^^^^^^^