Skip to content
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

ENH: implement ExtensionIndex.insert #32476

Merged
merged 5 commits into from
Mar 14, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

Sort of.

@@ -242,6 +243,10 @@ def repeat(self, repeats, axis=None):
result = self._data.repeat(repeats, axis=axis)
return self._shallow_copy(result)

def insert(self, loc: int, item):
# ExtensionIndex subclasses must override Index.insert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make an abstractmethod?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this I believe is ideal but any concerns on backward compat? Otherwise lgtm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any concerns on backward compat?

Nothing comes to mind

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gothca. This is non-public right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExtensionIndex needs to inherit from abc.ABC in order for the abstractmethod decorator to actually work, right?

In [1]: import abc

In [2]: class Foo: 
   ...:     @abc.abstractmethod 
   ...:     def some_meth(self): 
   ...:         pass 
   ...: 

In [3]: class Bar(Foo): 
   ...:     pass 
   ...: 

In [4]: bar = Bar()

In [5]: class Foo2(abc.ABC): 
   ...:     @abc.abstractmethod 
   ...:     def some_meth(self): 
   ...:         pass 
   ...: 

In [6]: class Bar2(Foo2): 
   ...:     pass 
   ...:

In [7]: bar2 = Bar2()
---------------------------------------------------------------------------
TypeError: Can't instantiate abstract class Bar2 with abstract methods some_meth

@WillAyd WillAyd added the ExtensionArray Extending pandas with custom dtypes or arrays. label Mar 6, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Mar 7, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ex #32476 (comment)

also, since the type of Index returned depends on the inserted item may be worth adding return types so we get mypy checking consistency.

@jbrockmendel
Copy link
Member Author

The abc.abstractmethod didn't appear to function as intended even when I subclassed abc.ABC, so reverted to use AbstractMethodError.

@jbrockmendel
Copy link
Member Author

comments addressed, sort of.

@jreback jreback merged commit 98a6b3c into pandas-dev:master Mar 14, 2020
@jreback
Copy link
Contributor

jreback commented Mar 14, 2020

seems fine

@jbrockmendel jbrockmendel deleted the insert-ei branch March 14, 2020 16:46
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants