-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: delegate attrs for CategoricalIndex, IntervalIndex #30605
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
def _delegate_method(self, name, *args, **kwargs): | ||
""" method delegation to the ._values """ | ||
method = getattr(self._values, name) | ||
if "inplace" in kwargs: | ||
raise ValueError("cannot use inplace with CategoricalIndex") | ||
res = method(*args, **kwargs) | ||
if is_scalar(res): | ||
if is_scalar(res) or name in self._raw_inherit: |
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.
can you add a comment here on what is happening
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.
is_scalar is the heavier check, can you put ‘name in self._raw_inherit’ as the first check.
@@ -192,6 +214,8 @@ class IntervalIndex(IntervalMixin, Index): | |||
# Immutable, so we are able to cache computations like isna in '_mask' | |||
_mask = None | |||
|
|||
_raw_inherit = {"_ndarray_values", "__array__", "overlaps", "contains"} |
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.
same as above, should we also add this attribute as an empty dict in Index?
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.
id rather not have a dummy attr on Index, but im building up to implementing ExtensionIndex which will have it
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.
see my comment below
""" method delegation to the ._data """ | ||
method = getattr(self._data, name) | ||
res = method(*args, **kwargs) | ||
if is_scalar(res) or name in self._raw_inherit: |
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.
comment.
can we not put these methods on Index?
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.
You mean remove them from IntervalIndex? No idea. @jschendel?
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.
no the delegation methods that you added could be on Index itself.
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 see. yes, the point of this exercise is to build up to moving as much of it to to either ExtensionIndex or even Index as possible. Doing this on II/CI before refactoring is just to limit the scope.
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.
its fine, but then will have to clean later
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.
Thanks, wanted to do this after I saw this pattern in DatetimeIndex
but haven't gotten around to it.
klass="IntervalIndex", | ||
examples=textwrap.dedent( | ||
"""\ | ||
>>> intervals = pd.IntervalIndex.from_tuples([(0, 1), (1, 3), (2, 4)]) |
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.
It looks like this means that we'll lose any IntervalIndex
specific portions of docstrings? And the docstring will just be whatever the IntervalArray
docstring is? I'm fine with this since the usage is basically identical between the two so I don't think it will cause any confusion. Will allow for some cleanup of the docstrings on the IntervalArray
side but that can be done later.
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.
It looks like this means that we'll lose any IntervalIndex specific portions of docstrings?
Yes
thanks @jbrockmendel comments above, but i think you have already noted them |
Working towards creating an ExtensionIndexMixin to be shared by all our backed-be-EA indexes, which would ideally grow into ExtensionIndex.
Removes CategoricalIndex._codes_for_groupby, which would raise AttributeError if it were ever called.