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

Include MultiIndex slice in non-reducing slices #19881

Merged
merged 4 commits into from
Jan 2, 2019

Conversation

fleimgruber
Copy link
Contributor

@fleimgruber fleimgruber commented Feb 24, 2018

Changes behaviour of user-passed IndexSlice to return DataFrame instead of
reducing to Series. MultiIndex slices are tuples so this explicitly checks type
and guards with braces.

This seems deceptively simple. WDYT?

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex labels Feb 24, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add the original example (e.g. with the full style usage) as a tests (in the style tests), just as a smoke that it doesn't raise is ok.

@jreback
Copy link
Contributor

jreback commented Feb 24, 2018

also pls add a whatsnew note (bug fix, multiindex is ok)

@codecov
Copy link

codecov bot commented Feb 24, 2018

Codecov Report

Merging #19881 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #19881      +/-   ##
==========================================
- Coverage   92.32%   92.32%   -0.01%     
==========================================
  Files         166      166              
  Lines       52440    52429      -11     
==========================================
- Hits        48417    48404      -13     
- Misses       4023     4025       +2
Flag Coverage Δ
#multiple 90.74% <100%> (-0.01%) ⬇️
#single 43.01% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexing.py 93.87% <100%> (ø) ⬆️
pandas/core/missing.py 91.7% <0%> (-0.6%) ⬇️
pandas/core/arrays/datetimelike.py 96.44% <0%> (-0.17%) ⬇️
pandas/core/arrays/period.py 98.59% <0%> (+0.06%) ⬆️

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 cf92230...a00dd9e. Read the comment docs.

@fleimgruber
Copy link
Contributor Author

Thanks for review, changed as requested, but still two minor questions for clarification (comment)

@jreback
Copy link
Contributor

jreback commented Nov 1, 2018

this got a bit lost. can you rebase and move the note to 0.24.0

@fleimgruber fleimgruber force-pushed the style_applymap_multiindex branch from 2370e0b to eaa9dba Compare November 1, 2018 08:47
@pep8speaks
Copy link

pep8speaks commented Nov 1, 2018

Hello @fleimgruber! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on January 02, 2019 at 00:28 Hours UTC

@fleimgruber fleimgruber force-pushed the style_applymap_multiindex branch from eaa9dba to 0d7abf3 Compare November 1, 2018 08:53
@fleimgruber
Copy link
Contributor Author

Rebased and whatsnew 0.24.0.

@alimcmaster1
Copy link
Member

@fleimgruber mind rebasing and resolving the conflicts above. ( The build issues on azure you are seeing is resolved on master )

@fleimgruber fleimgruber force-pushed the style_applymap_multiindex branch 2 times, most recently from da6c250 to 3d3b80f Compare November 21, 2018 18:48
@fleimgruber
Copy link
Contributor Author

@alimcmaster1 rebased. Which conflicts were you referring to? Still failing on Azure - a new bug?

@alimcmaster1
Copy link
Member

@fleimgruber thanks ( you have resolved the conflicts now ). It appears to be a flakey test, i've raised a PR here #23849 to hopefully fix the problem

@alimcmaster1
Copy link
Member

@jreback @gfyoung @mroeschke does someone mind restarting the azure 27 build on this PR - seems to be a flakey test. Im look in #23849

@jreback
Copy link
Contributor

jreback commented Dec 23, 2018

pls merge master

@fleimgruber fleimgruber force-pushed the style_applymap_multiindex branch from 3d3b80f to 10976fd Compare December 27, 2018 10:58
@fleimgruber
Copy link
Contributor Author

fleimgruber commented Dec 27, 2018

Rebased on master.

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

One small note otherwise LGTM.

return isinstance(part, slice) or is_list_like(part)
# true when slice does *not* reduce, False when part is a tuple,
# i.e. MultiIndex slice
return (isinstance(part, slice) or is_list_like(part))\
Copy link
Member

Choose a reason for hiding this comment

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

We are moving away from using \ line breaks in the codebase. Could you wrap this condition in parenthesis instead?

@@ -274,6 +274,31 @@ def f(x):
col in self.df.loc[slice_].columns}
assert result == expected

def test_applymap_subset_multiindex(self):
# https://github.com/pandas-dev/pandas/issues/19861
Copy link
Member

Choose a reason for hiding this comment

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

Can you leave a comment that this is just a smoke test.

@jreback jreback added this to the 0.24.0 milestone Dec 27, 2018
@jreback
Copy link
Contributor

jreback commented Jan 1, 2019

@fleimgruber can you update for comments

Changes behaviour of user-passed IndexSlice to return DataFrame instead of
reducing to Series.  MultiIndex slices are tuples so this explicitly checks type
and guards with parentheses.

Fixes pandas-dev#19861
@fleimgruber fleimgruber force-pushed the style_applymap_multiindex branch from 5b5cdd8 to a00dd9e Compare January 2, 2019 00:28
@jreback jreback merged commit 71efe61 into pandas-dev:master Jan 2, 2019
@jreback
Copy link
Contributor

jreback commented Jan 2, 2019

thanks @fleimgruber

thoo added a commit to thoo/pandas that referenced this pull request Jan 2, 2019
* upstream/master:
  Include MultiIndex slice in non-reducing slices (pandas-dev#19881)
@fleimgruber fleimgruber deleted the style_applymap_multiindex branch January 2, 2019 09:40
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame.style.applymap: subset kwarg fails with MultiIndexSlice
5 participants