-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH/API: DataFrame.stack() support for level=None, sequentially=True/False, and NaN level values. #9023
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
I don't like this conversions to sets. why not just use a list and make a scalar into a single-element list. thus guaranteeing you can always iterate over the levels? (its kind of what you are doing with a set), but we use lists for this purpose. |
I didn't want to break backwards compatibility with the existing treatment of lists, e.g. the fact that The behavior I implemented for With this PR, one can do An alternative implementation, which would be more restrictive, would be be to stick with lists, but add a boolean |
Argh, Python 2.6 doesn't support set comprehension. |
cbbcceb
to
a2d4a2f
Compare
Arguments whose meaning changes depending on their type seems very un-pythonic to me, so I am -1 on the set/list distinction. Using a list of sets to control simultaneous stacking of levels is cute but complex, and I'm struggling to think of when this would actually be useful. I don't think it's so bad to call However, I do think handling stacking simultaneously would be a good change to the API. It is technically a break in backwards compatibility, so we'll need to think about how that could be rolled out. We could do that with a keyword. But I also think the number of people who would be effected by this is likely to be quite small (when the existing behavior is encountered, it is probably followed by dropna), and in the long term there wouldn't be any point to including the flag. |
a2d4a2f
to
6a328a2
Compare
I agree that providing a list of sets is extremely unlikely. My main requirement is to be able to support simultaneous stacking of multiple levels, and in particular of all levels: If I sort of like my current distinction between lists and sets, but if every else thinks it's non-pythonic, I'm happy to change it. It would be reasonably straightforward to change this PR to simply stack a list of levels either sequentially or simultaneously based on a new flag. The only thing one would give up is supporting a list of sets, which I agree is a rather unlikely use case. As an aside, it would be useful, I think, to support an 'all' value for the |
c9bb60c
to
41b30df
Compare
I agree, this would be useful functionality. But using Also: whatever we settle on here for changing |
another option is to do something like (IIRC this is useful other times as well)
|
I'm not sure why when I looked earlier I thought the changes I made to |
@seth-p can you revisit? |
Haven't looked at this in a while. Will try to revisit over next few days. |
@jreback, @shoyer, question for you guys: Is |
@seth-p I agree, I don't think we make any API guarantees for |
9facf36
to
6b660ba
Compare
@@ -123,6 +123,8 @@ class Index(IndexOpsMixin, PandasObject): | |||
|
|||
_engine_type = _index.ObjectEngine | |||
|
|||
ALL_LEVELS = -1000 |
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.
My preferred way to make sentinel values is usually ALL_LEVELS = object()
. Then, use is
to do comparisons.
I don't really like the |
6b660ba
to
0a84569
Compare
@jorisvandenbossche, ok, I've removed I haven't made any corresponding changes to In general the code (in Comparing the results of
|
@seth-p maybe don't rush with changing it And on |
226f6b5
to
cd9c777
Compare
I rebased. On first attempt I couldn't get asv to work with either conda or virtualenv (am I the only one struggling under Windows? Certain packages simply don't install automatically with pip; I have to download version-specific wheels from http://www.lfd.uci.edu/~gohlke/pythonlibs/), but I'll try to get it to work. |
I don't have any problems on windows with asv. What problems do you have? It is a very simple pure python package with no other difficult dependencies, so I just cloned it and did |
My problem isn't asv itself, but rather getting virtualenv/conda to set up the virtual environments with all the packages. Ok, now I know that it's just me, so I'll try to figure it out.
|
This is very easy on windows: http://pandas.pydata.org/pandas-docs/stable/contributing.html#creating-a-development-environment virtualenv works, but you have to set it up carefully, conda is quite easy |
But I advise you to use conda and not virtualenv, certainly on windows |
Neither one worked for me -- both seemed to fail at "pip install --update " -- but I will try to figure it out.
|
@seth-p there is NO pip install with conda. so you mean to say
doesn't work for you? |
@seth-p and by the way, you shouldn't be installing things yourself (at least for running the benchmarks), as |
@jreback, you're right the Now asv seems to be working with conda. I don't know what I was doing wrong previously. Thanks for the pushing me in that direction. |
I now get the following error from asv/conda. Is it really just a matter of taking too long? If so, can I tell it to wait longer?
|
@seth-p That was an issue with the time out calculation, bus should be fixed in asv master: airspeed-velocity/asv#319 (if not, best to report it there) |
I still get the timeout error after getting the latest master ( |
I overrode all
|
@seth-p an alternative for now to be able to run the benchmarks, is to run then using Best to something like I just tested the above approach, and I see some slowdown with this branch (~80 %) for |
Thanks. Looks like they just fixed the asv bug in airspeed-velocity/asv#336. I'll takes look later today or tomorrow.
|
OK, I have asv working. For the three (un)stack benchmarks, my changes are 15-70% slower. I'll see if I can speed them up. |
@seth-p how's this coming. |
@jreback, I'm afraid I haven't had a chance to work on it. |
xref #11847 |
closing, but if you wish to rebase / update pls do so |
closes #8851
closes #9399
closes #9406
closes #9533