From 5362447d38d9885131f990d6876007c43d739f30 Mon Sep 17 00:00:00 2001 From: Tuan Date: Tue, 4 Jul 2017 03:23:45 +1000 Subject: [PATCH] fix BUG: ValueError when performing rolling covariance on multi indexed DataFrame (#16814) * fix multi index names * fix line length to pep8 * added what's new entry and reference issue number in test * Update test_multi.py * Update v0.20.3.txt --- doc/source/whatsnew/v0.20.3.txt | 1 + pandas/tests/indexes/test_multi.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index 5bb06d9809a22..e300d252a78e8 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -46,6 +46,7 @@ Bug Fixes - 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 a pytest marker failing downstream packages' tests suites (:issue:`16680`) - Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`) +- Fixed bug where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`) Conversion ^^^^^^^^^^ diff --git a/pandas/tests/indexes/test_multi.py b/pandas/tests/indexes/test_multi.py index 719cd2f7e01a4..8e383a7c1de2f 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): + + # 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'] + def test_labels_dtypes(self): # GH 8456