@@ -33,13 +33,21 @@ def __init__(self, values):
33
33
raise TypeError
34
34
self .data = values
35
35
36
+ @classmethod
37
+ def _from_extension_array (cls , array , copy = True ):
38
+ return cls (array )
39
+
40
+ @classmethod
41
+ def _from_scalars (cls , scalars ):
42
+ return cls (scalars )
43
+
36
44
def __getitem__ (self , item ):
37
45
if isinstance (item , numbers .Integral ):
38
46
return self .data [item ]
39
47
elif isinstance (item , np .ndarray ) and item .dtype == 'bool' :
40
- return type ( self ) ([x for x , m in zip (self , item ) if m ])
48
+ return self . _from_scalars ([x for x , m in zip (self , item ) if m ])
41
49
else :
42
- return type ( self ) (self .data [item ])
50
+ return self . _from_extension_array (self .data [item ])
43
51
44
52
def __setitem__ (self , key , value ):
45
53
if isinstance (key , numbers .Integral ):
@@ -77,10 +85,10 @@ def isna(self):
77
85
def take (self , indexer , allow_fill = True , fill_value = None ):
78
86
output = [self .data [loc ] if loc != - 1 else self ._na_value
79
87
for loc in indexer ]
80
- return type ( self ) (output )
88
+ return self . _from_scalars (output )
81
89
82
90
def copy (self , deep = False ):
83
- return type ( self ) (self .data [:])
91
+ return self . _from_extension_array (self .data [:])
84
92
85
93
@property
86
94
def _na_value (self ):
0 commit comments