@@ -43,18 +43,27 @@ def _is_boolean(self):
43
43
return True
44
44
45
45
46
- class ArrowBoolArray (ExtensionArray ):
47
- def __init__ (self , values ):
48
- if not isinstance (values , pa .ChunkedArray ):
49
- raise ValueError
46
+ @register_extension_dtype
47
+ class ArrowStringDtype (ExtensionDtype ):
50
48
51
- assert values .type == pa .bool_ ()
52
- self ._data = values
53
- self ._dtype = ArrowBoolDtype ()
49
+ type = str
50
+ kind = "U"
51
+ name = "arrow_string"
52
+ na_value = pa .NULL
54
53
55
- def __repr__ (self ):
56
- return "ArrowBoolArray({})" .format (repr (self ._data ))
54
+ @classmethod
55
+ def construct_from_string (cls , string ):
56
+ if string == cls .name :
57
+ return cls ()
58
+ else :
59
+ raise TypeError ("Cannot construct a '{}' from '{}'" .format (cls , string ))
57
60
61
+ @classmethod
62
+ def construct_array_type (cls ):
63
+ return ArrowStringArray
64
+
65
+
66
+ class ArrowExtensionArray (ExtensionArray ):
58
67
@classmethod
59
68
def from_scalars (cls , values ):
60
69
arr = pa .chunked_array ([pa .array (np .asarray (values ))])
@@ -142,3 +151,29 @@ def any(self, axis=0, out=None):
142
151
143
152
def all (self , axis = 0 , out = None ):
144
153
return self ._data .to_pandas ().all ()
154
+
155
+
156
+ class ArrowBoolArray (ArrowExtensionArray ):
157
+ def __init__ (self , values ):
158
+ if not isinstance (values , pa .ChunkedArray ):
159
+ raise ValueError
160
+
161
+ assert values .type == pa .bool_ ()
162
+ self ._data = values
163
+ self ._dtype = ArrowBoolDtype ()
164
+
165
+ def __repr__ (self ):
166
+ return "ArrowBoolArray({})" .format (repr (self ._data ))
167
+
168
+
169
+ class ArrowStringArray (ArrowExtensionArray ):
170
+ def __init__ (self , values ):
171
+ if not isinstance (values , pa .ChunkedArray ):
172
+ raise ValueError
173
+
174
+ assert values .type == pa .string ()
175
+ self ._data = values
176
+ self ._dtype = ArrowStringDtype ()
177
+
178
+ def __repr__ (self ):
179
+ return "ArrowStringArray({})" .format (repr (self ._data ))
0 commit comments