@@ -180,6 +180,8 @@ def to_dataframe(self) -> pd.DataFrame:
180
180
1 4.0 5.0 6.0 TEXT4 TEXT567
181
181
2 7.0 8.0 9.0 TEXT8 TEXT90
182
182
3 10.0 11.0 12.0 TEXT123 TEXT456789
183
+ >>> df.dtypes.to_list()
184
+ [dtype('float64'), dtype('float64'), dtype('float64'), string[python]]
183
185
"""
184
186
# Deal with numeric columns
185
187
vectors = []
@@ -192,7 +194,7 @@ def to_dataframe(self) -> pd.DataFrame:
192
194
colvector .append (
193
195
np .ctypeslib .as_array (dseg .data [icol ], shape = (dseg .n_rows ,))
194
196
)
195
- vectors .append (np .concatenate (colvector ))
197
+ vectors .append (pd . Series ( data = np .concatenate (colvector ) ))
196
198
197
199
# Deal with trailing text column
198
200
textvector = []
@@ -203,16 +205,9 @@ def to_dataframe(self) -> pd.DataFrame:
203
205
if dseg .text :
204
206
textvector .extend (dseg .text [: dseg .n_rows ])
205
207
if textvector :
206
- vectors .append (np .char .decode (textvector ))
207
-
208
- df = pd .concat ([pd .Series (v ) for v in vectors ], axis = 1 )
209
-
210
- # convert text data from object dtype to string dtype
211
- if textvector :
212
- df = df .convert_dtypes (
213
- convert_string = True ,
214
- convert_integer = False ,
215
- convert_floating = False ,
216
- convert_boolean = False ,
208
+ vectors .append (
209
+ pd .Series (data = np .char .decode (textvector ), dtype = pd .StringDtype ())
217
210
)
211
+
212
+ df = pd .concat (objs = vectors , axis = 1 )
218
213
return df
0 commit comments