@@ -27,11 +27,11 @@ class ExtensionArray(object):
27
27
* copy
28
28
* _concat_same_type
29
29
30
- Some additional methods are available to satisfy pandas' internal, private
31
- block API.
30
+ Some additional methods are available to satisfy pandas' internals.
32
31
33
32
* _can_hold_na
34
33
* _formatting_values
34
+ * _constructor
35
35
36
36
This class does not inherit from 'abc.ABCMeta' for performance reasons.
37
37
Methods and properties required by the interface raise
@@ -49,13 +49,32 @@ class ExtensionArray(object):
49
49
assumptions on how the data are stored, just that it can be converted
50
50
to a NumPy array.
51
51
52
- Extension arrays should be able to be constructed with instances of
53
- the class, i.e. ``ExtensionArray(extension_array)`` should return
54
- an instance, not error.
52
+ There are a few restrictions on how ExtensionArrays are created.
53
+
54
+ * An ExtensionArray should be valid, i.e.
55
+ ``ExtensionArray(extension_array)`` should return an instance
56
+ * A sequence of the scalar type should be valid, i.e.
57
+ ``ExtensionArray(Sequence[ExtensionDtype.type]])`` should return
58
+ an instance, not error.
55
59
"""
56
60
# '_typ' is for pandas.core.dtypes.generic.ABCExtensionArray.
57
61
# Don't override this.
58
62
_typ = 'extension'
63
+
64
+ @classmethod
65
+ def _constructor (cls , data ):
66
+ """Construct a new instance of of the extension array.
67
+
68
+ Parameters
69
+ ----------
70
+ data : Sequence
71
+
72
+ Returns
73
+ -------
74
+ ExtensionArray
75
+ """
76
+ return cls (data )
77
+
59
78
# ------------------------------------------------------------------------
60
79
# Must be a Sequence
61
80
# ------------------------------------------------------------------------
@@ -226,7 +245,7 @@ def unique(self):
226
245
from pandas import unique
227
246
228
247
uniques = unique (self .astype (object ))
229
- return type ( self ) (uniques )
248
+ return self . _constructor (uniques )
230
249
231
250
# ------------------------------------------------------------------------
232
251
# Indexing methods
0 commit comments