-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REF: check monotonicity inside _can_use_libjoin #55342
Conversation
and self.is_monotonic_increasing | ||
and other.is_monotonic_increasing | ||
and not (self.has_duplicates and other.has_duplicates) | ||
and (self.is_unique or other.is_unique) |
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 think the order here can have a difference. is_monotonic_increasing
will provide is_unique
"for free" if the index is both monotonic and unique and it hasn't already been cached.
import pandas as pd
import numpy as np
arr = np.arange(1_000_000)
%timeit idx=pd.Index(arr); idx.is_unique and idx.is_monotonic_increasing
# 68.7 ms ± 5.13 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit idx=pd.Index(arr); idx.is_monotonic_increasing and idx.is_unique
# 2.91 ms ± 121 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
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.
Good catch. i had expected the cache for all of these to get populated at the same time inside IndexEngine, will take a closer look
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.
OK, looks like engine.is_monotonic_increasing will populate the engine.is_unique cache but not vice-versa. All of the paths within the engine that check is_unique do that check after checking self.is_monotonic_increasing. im inclined to update the engine code so that the unique check always populates the is_monotonic_increasing cache in order to 1) make the perf not dependent on the order these are accessed and 2) avoid populating engine.mapping
in these cases (which allocates memory)
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.
im inclined to update the engine code so that the unique check always populates the is_monotonic_increasing cache in order to 1) make the perf not dependent on the order these are accessed and 2) avoid populating engine.mapping in these cases (which allocates memory)
that sounds good to me
@lukemanley any interest in taking over on this one? im at risk of letting it fall through the cracks |
Sure, I'll take this one. |
It looks like this is now down to one test failure: The underlying issue currently exists on Now that
We could either check for nulls in |
Where would this live? some places would be uglier than others. |
@@ -280,7 +286,7 @@ cdef class IndexEngine: | |||
values = self.values | |||
self.monotonic_inc, self.monotonic_dec, is_strict_monotonic = \ | |||
self._call_monotonic(values) | |||
except TypeError: | |||
except (TypeError, InvalidOperation): |
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.
added to catch the Decimal("NaN") < Decimal("NaN")
case
Added to the existing try/except in This is now passing all tests. |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
gentle ping @jbrockmendel if you have any thoughts on this |
LGTM. Is the perf issue you noted addressed? One more merge main and ping on green pls |
@jbrockmendel - merged main and now green. I think this is ready |
Thanks @jbrockmendel |
thanks @lukemanley |
* REF: fix can_use_libjoin check * DOC: docstring for can_use_libjoin * Make can_use_libjoin checks more-correct * avoid allocating mapping in monotonic cases * fix categorical memory usage tests * catch decimal.InvalidOperation --------- Co-authored-by: Luke Manley <[email protected]>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.