Closed
Description
I don't think that pandas should make any assumptions on how subclasses __init__
method. Currently we assume that the first positional argument accepts an instance of the class or a sequence of the class's scalar type.
I'd rather break that into two distinct methods.
@classmedthod
def from_extension_array(cls, extension_array: ExtensionArray) -> ExtensionArray:
"""Construct a new ExtensionArray from an instance of the same type
Parameters
----------
extension_array : ExtensionArray
An instance of 'cls'
Returns
-------
ExtensionArray
"""
ScalarType = ExtensionArray.dtype.type
@classmethod
def from_scalars(cls, scalars: Sequence[ScalarType]) -> ExtensionArray:
"""Construct a new ExtensionArray from a sequence of the scalar type
Parameters
----------
scalars : Sequence[ScalarType]
A sequence of cls.dtype.type, the scalar type for this array
Returns
-------
ExtensionArray
"""
I think these should be abstract. For many subclasses, a simple cls(arg)
should suffice.