-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: performance improvement in MultiIndex.sortlevel #9445
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
behzadnouri
commented
Feb 8, 2015
comp_ids, obs_ids = _compress_group_index(group_index) | ||
max_group = len(obs_ids) | ||
if not compress: | ||
ngroups = (ids.size and ids.max()) + 1 |
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.
Both idx.size
and ids.max()
are integers, yes?
I find using and
for integers rather confusing. Perhaps this could be: (idx.max() if ids.size else 0) + 1
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.
The expression
x and y
first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.
note that the documentation follows with an example of s or 'foo'
, i.e. or
ing two strings, as a use-case of boolean operations.
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.
@behzadnouri I agree with @shoyer here. We get the idiom, but I don't think a casual glance is intuitve here. Pls change to what @shoyer suggests.
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.
i gave an example from python's documentation that this is an actual use-case for boolean operations:
This is sometimes useful, e.g., if
s
is a string that should be replaced by a default value if it is empty, the expressions or 'foo'
yields the desired value.
this is right off from python's documentation, and i have seen it used a lot.
that said, if you like to change it, please do.
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.
I get that it is from python docs
but not all of that idioms are useful
in the context of assignment with a value that could be None I would agree with you
but these are integers and it's not obvious at all
pls make the change
looks good otherwise, ping when green after that change. |
PERF: performance improvement in MultiIndex.sortlevel
@behzadnouri thanks! |