Remove special Index class from the general index class hierarchy - #8309
Conversation
|
This should be a non-breaking change, but should be reviewed carefully for edge cases where this solution fails. It will also need to be rebased once the forward merge of 21.06 brings the changes from #8254 onto 21.08, since this relies on that PR. |
|
Note that users who subclass In [10]: class MyIndex(cudf.Index):
...: pass
...:
In [11]: isinstance(cudf.StringIndex(), MyIndex)
True # !!!What they should do is subclass |
I think the above makes this a breaking change, as any existing user code that subclasses |
|
I think that's a valid concern. I have two main reasons why I think this is OK to do and shouldn't prevent us from moving forward with this PR. First, someone who subclassed Second, subclassing
For those reasons, I think we would be justified in just telling users that instead of subclassing |
|
Understood. Let's add a note along these lines in the
If nothing, it will serve as a reminder to internal developers... |
|
If you like, I think that we could explicitly prohibit this with an |
|
I'd be +1 for that |
…structors for other index types.
Done. Of course this won't save us from subclasses that actually override |
12bd233 to
18995b7
Compare
|
rerun tests |
|
This is blocked by rapidsai/integration#282, which is necessary to run 21.08 tests. Once that's merged tests can be rerun. |
|
rerun tests |
|
Integration PR is now merged, but this PR is now blocked by #8419 . |
Codecov Report
@@ Coverage Diff @@
## branch-21.08 #8309 +/- ##
===============================================
Coverage ? 82.85%
===============================================
Files ? 109
Lines ? 17920
Branches ? 0
===============================================
Hits ? 14847
Misses ? 3073
Partials ? 0 Continue to review full report at Codecov.
|
rjzamora
left a comment
There was a problem hiding this comment.
I only looked at the minor dask_cudf changes and the index.py changes. This seems fine to me :)
|
@gpucibot merge |
The changes in #8309 allow us to avoid overriding `__new__` for all index types and instead use the more standard `__init__`, which also makes it easier to share logic between different index classes via typical inheritance patterns. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Ashwin Srinath (https://github.com/shwina) - GALI PREM SAGAR (https://github.com/galipremsagar) URL: #8485
Fixes: #715 With the recent `cudf` refactor done in NVIDIA/cudf#8309, we will need to update `cudf.Index` to `cudf.BaseIndex` at these places. Authors: - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - Benjamin Zaitlen (https://github.com/quasiben) URL: #718
Renames the old
Indexclass toBaseIndexas the parent for all index types and creates a newIndexclass that subclassesBaseIndexto provide the expected API forcudf.Index. The critical change is that this class has a custom metaclass to make it look likeBaseIndexfrom an inheritance perspective, and it takes on the__new__method that allows it to return differentIndextypes depending on the input. This change will allow us to rewrite the hierarchy of different Index types in much simpler, more robust, and more performant ways. In particular, we will no longer have to override__new__in those classes, we will be able to make use of__init__rather than the custom_initializemethod we are currently using, and we reduce ambiguities with respect to which and how many__new__and__init__methods are called.