-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pivot_table always returns a DataFrame #13554
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
Conversation
pandas/tools/tests/test_pivot.py
Outdated
'col2': ['C', 'D', 'E'], | ||
'col3': [1, 3, 9]}) | ||
|
||
pivoted_1 = df.pivot_table('col1', index=['col3', 'col2'], aggfunc=np.sum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replicate all 3 tests form the issue:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this result
pandas/tools/tests/test_pivot.py
Outdated
index=Index([1, 3, 9], name='col3'), | ||
columns=m) | ||
|
||
tm.assert_frame_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice case 3 differs from the issue.
Should I rewrite to match with the issue?
The issue:
sum
col3
1 3
3 4
9 5
<class 'pandas.core.frame.DataFrame'>
This PR:
sum
col1
col3
1 3
3 4
9 5
<class 'pandas.core.frame.DataFrame'>
pivot_table
always returns a DataFrame
can you rebase / update? |
can you rebase and add a release note for 0.20.0 |
Sorry to my late response, I rebased and add note for 0.20.0. |
can you rebase |
Rebased ! |
@yui-knk looks like some test failures: https://travis-ci.org/pandas-dev/pandas/jobs/186874138#L1939 Can you test those out locally and see if you reproduce? |
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -321,3 +321,4 @@ Bug Fixes | |||
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`) | |||
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`) | |||
- Bug in ``pd.pivot_table()`` where no error was raised when values argument was not in the columns (:issue:`14938`) | |||
- Bug in ``pivot_table`` returns ``Series`` in specific circumstance (:issue:`4386`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add, when it should always return a DataFrame.
can you rebase. I think you have a failing test as well. |
can you rebase/update |
Before this commit, if * `values` is not list like * `columns` is `None` * `aggfunc` is not instance of `list` `pivot_table` returns a `Series`. This commit adds checking for `columns.nlevels` is greater than 1 to prevent from casting `table` to a `Series`. This will fix pandas-dev#4386.
I think you need to change this test to return DataFrame rather than Series. otherwise looks ok: https://travis-ci.org/pandas-dev/pandas/jobs/208224356 |
also, I'd like to have a sub-section in the whatsnew which shows the case where this used to return a Series, but now returns a DataFrame (you can use one of your tests examples). |
Before this commit, if * `values` is not list like * `columns` is `None` * `aggfunc` is not instance of `list` `pivot_table` returns a `Series`. This commit adds checking for `columns.nlevels` is greater than 1 to prevent from casting `table` to a `Series`. This will fix #4386. DOC: add docs for #13554
thanks @yui-knk rebase and merged. |
Before this commit, if * `values` is not list like * `columns` is `None` * `aggfunc` is not instance of `list` `pivot_table` returns a `Series`. This commit adds checking for `columns.nlevels` is greater than 1 to prevent from casting `table` to a `Series`. This will fix pandas-dev#4386. DOC: add docs for pandas-dev#13554
git diff upstream/master | flake8 --diff
Before this commit, if
values
is not list likecolumns
isNone
aggfunc
is not instance oflist
pivot_table
returns aSeries
.This commit adds checking for
columns.nlevels
isgreater than 1 to prevent from casting
table
toa
Series
.This will fix #4386.