Skip to content

Commit 5362447

Browse files
Tuanri938
Tuan
authored andcommitted
fix BUG: ValueError when performing rolling covariance on multi indexed DataFrame (pandas-dev#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
1 parent 800b40d commit 5362447

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

doc/source/whatsnew/v0.20.3.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Bug Fixes
4646
- 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`)
4747
- Fixed a pytest marker failing downstream packages' tests suites (:issue:`16680`)
4848
- Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`)
49+
- Fixed bug where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`)
4950

5051
Conversion
5152
^^^^^^^^^^

pandas/tests/indexes/test_multi.py

+9
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ def f():
6161

6262
tm.assert_raises_regex(ValueError, 'The truth value of a', f)
6363

64+
def test_multi_index_names(self):
65+
66+
# GH 16789
67+
cols = pd.MultiIndex.from_product([['A', 'B'], ['C', 'D', 'E']],
68+
names=['1', '2'])
69+
df = pd.DataFrame(np.ones((10, 6)), columns=cols)
70+
rolling_result = df.rolling(3).cov()
71+
assert rolling_result.index.names == [None, '1', '2']
72+
6473
def test_labels_dtypes(self):
6574

6675
# GH 8456

0 commit comments

Comments
 (0)