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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.3.txt
Expand Up @@ -39,7 +39,7 @@ Bug Fixes
- Fixed issue with dataframe scatter plot for categorical data that reports incorrect column key not found when categorical data is used for plotting (:issue:`16199`)
- 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 in ``pandas.core.window_flex_binary_moment()`` when a multi-index DataFrame is passed in as ``arg1`` (:issue:`16789`)
Copy link
Contributor

Choose a reason for hiding this comment

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

window_flex_binary_moment is an internal method, so the user reading these notes doesn't need to care where exactly the bug is. Better to just say something like

Fixed bug where computing the rolling covariance of a MultiIndexed ``DataFrame`` improperly raised a ``ValueError`` (:issue:`16789`)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I'll quickly fix it now.


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']],
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']

def test_labels_dtypes(self):

# GH 8456
Expand Down