Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BUG: ValueError when performing rolling covariance on multi indexed DataFrame #16814

Merged
merged 6 commits into from Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/window.py
Original file line number Diff line number Diff line change
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
10 changes: 10 additions & 0 deletions pandas/tests/indexes/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ 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']],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment with the issue number

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

names=['1', '2'])
df = pd.DataFrame(np.ones((10, 6)), columns=cols)
rolling_result = df.rolling(3).cov()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just call this result

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. will do.

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
Expand Down