Skip to content

Commit

Permalink
fix BUG: ValueError when performing rolling covariance on multi index…
Browse files Browse the repository at this point in the history
…ed 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
  • Loading branch information
Tuan authored and TomAugspurger committed Jul 3, 2017
1 parent 92e1cc8 commit 9e55af2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.3.txt
Expand Up @@ -40,7 +40,7 @@ Bug Fixes
- Fixed issue with :meth:`DataFrame.style` where element id's were not unique (:issue:`16780`)
- 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 where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`)

Conversion
^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window.py
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/test_multi.py
Expand Up @@ -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
Expand Down

0 comments on commit 9e55af2

Please sign in to comment.