-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH Add MultiIndex.from_product convenience function #6055
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
ENH Add MultiIndex.from_product convenience function #6055
Conversation
result = MultiIndex.from_iterables([first, second], names=names) | ||
|
||
product = list(itertools.product(first, second)) | ||
self.assertEquals(list(result), product) |
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.
use assert_array_equals here
also test that this equals to a constructed instance using MultiIndex.from_tuples (but construct if by writing out the tuples)
eg make it so it doesn't depend on iter tools or other routines)
that was if some ordering changes u are covered
- add a release notes entry in improvements section
- an example in v0.13.1
- same example in the multi-index construction section in main docs (eg where Multiindex.from_tuples is introduced)
I have a remark about this. First, it's really usefull functionality! (it's indeed a common usecase) But the name sounds confusing to me. Because it seems not that important that it are |
|
@mwaskom FYI, use this PR number in release notes / v0.13.1 (as the reference issue) |
OK, should be good |
shades = ['light', 'dark'] | ||
colors = ['red', 'green', 'blue'] | ||
|
||
index = pandas.MultiIndex.from_product([shades, colors], |
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.
dont't put the index =
(if you assign to a variable then ipython wont' show it), and don't need the pandas
everything is imported here
small changes pls rebase and squash into 1 commit, see here: https://github.com/pydata/pandas/wiki/Using-Git |
OK, sorry, git question. I rebased and squashed, i.e.
But now I cannot push to this branch due to
What's the right thing to do? |
try this
remove all but your commit then
(the |
OK that's what I thought but wasn't sure. |
@mwaskom excellent git-fu any other comments |
shades = ['light', 'dark'] | ||
colors = ['red', 'green', 'blue'] | ||
|
||
MultiIndex.from_product([shades, colors], names=['shade', 'color']) |
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.
These three code lines need an indentation. Also, I think they are meant as code that should be ran? Then the code-block
-> ipython
FIX typo in from_iterables docstring ENH Rename from_iterables to from_product TST rework from_product test to compare against from_tuples DOC Add notes on from_product to release notes and indexing docs DOC clean from_product examples in docs DOC Further clarify from_product docs
I think that addresses everything. |
@jorisvandenbossche ok by me...go ahead and merge if you are ok |
Yes, certainly fine. Thanks a lot @mwaskom ! |
ENH Add MultiIndex.from_product convenience function
I just reached for this and it was there. 👍 |
Following up on this StackOverflow post.
This is a convenience function for when you have a set of iterables and you want to make a MultiIndex with each unique paring of the values in those iterables.
I'm testing it againstitertools.product
since it uses the internalcartesian_product
function; please let me know if there are additional tests that would make sense.Testing against MultiIndex.from_tuples instead.