Skip to content

Commit 9e55af2

Browse files
TuanTomAugspurger
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 92e1cc8 commit 9e55af2

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.20.3.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Bug Fixes
4040
- Fixed issue with :meth:`DataFrame.style` where element id's were not unique (:issue:`16780`)
4141
- Fixed a pytest marker failing downstream packages' tests suites (:issue:`16680`)
4242
- 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`)
43-
43+
- Fixed bug where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`)
4444

4545
Conversion
4646
^^^^^^^^^^

pandas/core/window.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ def dataframe_from_int_dict(data, frame_template):
19481948
result.columns = Index(result.columns).set_names(
19491949
arg2.columns.name)
19501950
result.index = result.index.set_names(
1951-
[arg1.index.name, arg1.columns.name])
1951+
arg1.index.names + arg1.columns.names)
19521952

19531953
return result
19541954

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)