Skip to content

BUG: support "fill_value" for ".unstack()" called with list of levels #17887

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 1 commit into from
Oct 16, 2017

Conversation

toobaz
Copy link
Member

@toobaz toobaz commented Oct 16, 2017

Notice this is a simple fix which doesn't make @kordek 's more general comment about the opportunity for refactoring less valid.

@toobaz toobaz force-pushed the unstack_multi branch 3 times, most recently from 65171d9 to 2d56672 Compare October 16, 2017 09:06
@codecov
Copy link

codecov bot commented Oct 16, 2017

Codecov Report

Merging #17887 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17887      +/-   ##
==========================================
- Coverage   91.23%   91.21%   -0.02%     
==========================================
  Files         163      163              
  Lines       50102    50102              
==========================================
- Hits        45712    45703       -9     
- Misses       4390     4399       +9
Flag Coverage Δ
#multiple 89.03% <100%> (ø) ⬆️
#single 40.31% <25%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/reshape/reshape.py 99.27% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00f23ca...2d56672. Read the comment docs.

@codecov
Copy link

codecov bot commented Oct 16, 2017

Codecov Report

Merging #17887 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17887      +/-   ##
==========================================
+ Coverage   91.23%   91.24%   +<.01%     
==========================================
  Files         163      163              
  Lines       50105    50105              
==========================================
+ Hits        45714    45718       +4     
+ Misses       4391     4387       -4
Flag Coverage Δ
#multiple 89.05% <100%> (+0.02%) ⬆️
#single 40.31% <25%> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/core/reshape/reshape.py 99.27% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️
pandas/core/indexes/datetimes.py 95.5% <0%> (+0.09%) ⬆️
pandas/plotting/_converter.py 65.2% <0%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9092445...74a2104. Read the comment docs.

expected = unstacked[key]
result = pd.Series([0, 0, 2], index=unstacked.index, name=key)
assert_series_equal(result, expected)
stacked = unstacked.stack(['x', 'y'])
Copy link
Contributor

Choose a reason for hiding this comment

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

put blank lines between cases

assert_series_equal(result, expected)
stacked = unstacked.stack(['x', 'y'])
stacked.index = stacked.index.reorder_levels(f.index.names)
# Workaround for GH #17886:
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment here on why (in addition to the issue number)

@@ -154,6 +154,29 @@ def test_unstack_fill(self):
index=['x', 'y', 'z'], dtype=np.float)
assert_frame_equal(result, expected)

# GH #13971: fill_value when unstacking multiple levels:
f = DataFrame({'x': ['a', 'a', 'b'],
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually call this df.

@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 16, 2017
@jreback jreback added this to the 0.21.0 milestone Oct 16, 2017
@jreback
Copy link
Contributor

jreback commented Oct 16, 2017

lgtm minor comments.

@jreback jreback merged commit 5bf7f9a into pandas-dev:master Oct 16, 2017
@jreback
Copy link
Contributor

jreback commented Oct 16, 2017

thanks @toobaz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: unstack(fill_value) does nothing when unstacking multiple columns
2 participants