Skip to content

BUG: added missing fill_na parameter to DataFrame.unstack() with list of levels #30838

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

Merged
merged 33 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c3d6a2b
added missing fill_na parameter
tanmay1618 Jan 9, 2020
a780a18
BUG: fill_value ignored for multindex unstack (#30740)
tanmay1618 Jan 9, 2020
f4092fd
BUG: #30740 unstack mulitindex not ignoring fill_value
tanmay1618 Jan 9, 2020
76931e8
BUG : #30740
tanmay1618 Jan 9, 2020
3a320d0
BUG: #30740 merge request solved
tanmay1618 Jan 9, 2020
d45d176
Update pandas/tests/reshape/test_reshape.py
tanmay1618 Jan 9, 2020
efc579d
BUG: #30740 moved test to tests/frame/test_reshape.py
tanmay1618 Jan 9, 2020
1c4632a
BUG: #30740 added to whatsnew
tanmay1618 Jan 9, 2020
33ddaf0
Merge remote-tracking branch 'upstream/master' into unstack_fill_na
tanmay1618 Jan 9, 2020
4c06835
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
e1eb158
BUG: #30740 added gh to comment
tanmay1618 Jan 9, 2020
0018451
BUG #30740 moved to test/frames/test_reshape.py
tanmay1618 Jan 9, 2020
dcb8a3b
BUG #30740 moved bug doc to v1.0.0
tanmay1618 Jan 9, 2020
c984d5a
BUG: #30740 removed class for tests
tanmay1618 Jan 9, 2020
1e7f0fc
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
68b247a
Update v0.25.3.rst
tanmay1618 Jan 9, 2020
2d7a615
Merge remote-tracking branch 'upstream/master' into unstack_fill_na
tanmay1618 Jan 9, 2020
1ba9b34
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
b35fed9
BUG: #30740 added gh to comment
tanmay1618 Jan 9, 2020
7414e59
BUG #30740 moved bug doc to v1.0.0
tanmay1618 Jan 9, 2020
1d164ce
BUG: #30740 removed class for tests
tanmay1618 Jan 9, 2020
591c747
BUG #30740 moved to test/frames/test_reshape.py
tanmay1618 Jan 9, 2020
90086e4
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
f03ceb6
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
a1dbd08
removed self from function
tanmay1618 Jan 9, 2020
c3c3447
Update v1.0.0.rst
TomAugspurger Jan 9, 2020
fe3f487
Merge remote-tracking branch 'upstream/master' into unstack_fill_na
tanmay1618 Jan 9, 2020
386b13c
Merge branch 'unstack_fill_na' of https://github.com/tanmay1618/panda…
tanmay1618 Jan 9, 2020
c93cbc8
changed expected to fixed datframe in test
tanmay1618 Jan 9, 2020
6cc15ef
Update pandas/tests/frame/test_reshape.py
tanmay1618 Jan 9, 2020
d2249e0
Update pandas/tests/frame/test_reshape.py
tanmay1618 Jan 9, 2020
6f75025
Update pandas/core/reshape/reshape.py
tanmay1618 Jan 9, 2020
2809c55
Update pandas/tests/frame/test_reshape.py
tanmay1618 Jan 9, 2020
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ Reshaping
- Dtypes are now preserved when transposing a ``DataFrame`` where each column is the same extension dtype (:issue:`30091`)
- Bug in :func:`merge_asof` merging on a tz-aware ``left_index`` and ``right_on`` a tz-aware column (:issue:`29864`)
- Improved error message and docstring in :func:`cut` and :func:`qcut` when `labels=True` (:issue:`13318`)
- Bug in missing `fill_na` parameter to :meth:`DataFrame.unstack` with list of levels (:issue:`30740`)

Sparse
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _unstack_multiple(data, clocs, fill_value=None):
result = data
for i in range(len(clocs)):
val = clocs[i]
result = result.unstack(val)
result = result.unstack(val, fill_value)
clocs = [v if i > v else v - 1 for v in clocs]

return result
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/frame/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,3 +1128,21 @@ def test_stack_timezone_aware_values():
),
)
tm.assert_series_equal(result, expected)


def test_unstacking_multi_index_df():
# BUG: gh-30740
df = pd.DataFrame(
{
"name": ["Alice", "Bob"],
"score": [9.5, 8],
"employed": [False, True],
"kids": [0, 0],
"gender": ["female", "male"],
}
)
df = df.set_index(["name", "employed", "kids", "gender"])
df = df.unstack(["gender"], fill_value=0)
expected = df.unstack("employed", fill_value=0).unstack("kids", fill_value=0)
result = df.unstack(["employed", "kids"], fill_value=0)
tm.assert_frame_equal(result, expected)