@@ -46,6 +46,11 @@ def type(self) -> type[str]:
46
46
"""
47
47
return str
48
48
49
+ @property
50
+ def pyarrow_dtype (self ):
51
+ """Return the pyarrow data type used for storing data in the pyarrow array."""
52
+ return pa .string ()
53
+
49
54
@property
50
55
def _is_numeric (self ) -> bool :
51
56
return False
@@ -81,7 +86,7 @@ def _box_pa(
81
86
cls , value , pa_type : pa .DataType | None = None
82
87
) -> pa .Array | pa .ChunkedArray | pa .Scalar :
83
88
"""Box value into a pyarrow Array, ChunkedArray or Scalar."""
84
- assert pa_type is None or pa_type == pa . string ()
89
+ assert pa_type is None or pa_type == cls . _dtype . pyarrow_dtype
85
90
86
91
if isinstance (value , pa .Scalar ) or not (
87
92
common .is_list_like (value ) and not common .is_dict_like (value )
@@ -93,10 +98,12 @@ def _box_pa(
93
98
def _box_pa_scalar (cls , value ) -> pa .Scalar :
94
99
"""Box value into a pyarrow Scalar."""
95
100
if pd .isna (value ):
96
- pa_scalar = pa .scalar (None , type = pa . string () )
101
+ pa_scalar = pa .scalar (None , type = cls . _dtype . pyarrow_dtype )
97
102
else :
98
103
value = JSONArray ._serialize_json (value )
99
- pa_scalar = pa .scalar (value , type = pa .string (), from_pandas = True )
104
+ pa_scalar = pa .scalar (
105
+ value , type = cls ._dtype .pyarrow_dtype , from_pandas = True
106
+ )
100
107
101
108
return pa_scalar
102
109
@@ -107,7 +114,7 @@ def _box_pa_array(cls, value, copy: bool = False) -> pa.Array | pa.ChunkedArray:
107
114
pa_array = value ._pa_array
108
115
else :
109
116
value = [JSONArray ._serialize_json (x ) for x in value ]
110
- pa_array = pa .array (value , type = pa . string () , from_pandas = True )
117
+ pa_array = pa .array (value , type = cls . _dtype . pyarrow_dtype , from_pandas = True )
111
118
return pa_array
112
119
113
120
@classmethod
@@ -117,17 +124,6 @@ def _from_sequence(cls, scalars, *, dtype=None, copy=False):
117
124
arr = cls (pa_array )
118
125
return arr
119
126
120
- @classmethod
121
- def _concat_same_type (cls , to_concat ) -> JSONArray :
122
- """Concatenate multiple JSONArray."""
123
- chunks = [
124
- pa_array_chunks
125
- for item in to_concat
126
- for pa_array_chunks in item ._pa_array .iterchunks ()
127
- ]
128
- arr = pa .chunked_array (chunks , type = pa .string ())
129
- return cls (arr )
130
-
131
127
@staticmethod
132
128
def _serialize_json (value ):
133
129
"""A static method that converts a JSON value into a string representation."""
@@ -167,7 +163,7 @@ def __getitem__(self, item):
167
163
168
164
if isinstance (item , np .ndarray ):
169
165
if not len (item ):
170
- return type (self )(pa .chunked_array ([], type = pa . string () ))
166
+ return type (self )(pa .chunked_array ([], type = self . dtype . pyarrow_dtype ))
171
167
elif item .dtype .kind in "iu" :
172
168
return self .take (item )
173
169
else :
0 commit comments