@@ -2385,8 +2385,7 @@ def _prepare_data(self):
2385
2385
data = self ._convert_strls (data )
2386
2386
2387
2387
# 3. Convert bad string data to '' and pad to correct length
2388
- dtypes = []
2389
- data_cols = []
2388
+ dtypes = {}
2390
2389
has_strings = False
2391
2390
native_byteorder = self ._byteorder == _set_endianness (sys .byteorder )
2392
2391
for i , col in enumerate (data ):
@@ -2395,22 +2394,16 @@ def _prepare_data(self):
2395
2394
has_strings = True
2396
2395
data [col ] = data [col ].fillna ('' ).apply (_pad_bytes , args = (typ ,))
2397
2396
stype = 'S{type}' .format (type = typ )
2398
- dtypes .append (('c' + str (i ), stype ))
2399
- string = data [col ].str .encode (self ._encoding )
2400
- data_cols .append (string .values .astype (stype ))
2397
+ dtypes [col ] = stype
2398
+ data [col ] = data [col ].str .encode (self ._encoding ).astype (stype )
2401
2399
else :
2402
2400
values = data [col ].values
2403
2401
dtype = data [col ].dtype
2404
2402
if not native_byteorder :
2405
2403
dtype = dtype .newbyteorder (self ._byteorder )
2406
- dtypes .append (('c' + str (i ), dtype ))
2407
- data_cols .append (values )
2408
- dtypes = np .dtype (dtypes )
2404
+ dtypes [col ] = dtype
2409
2405
2410
- if has_strings or not native_byteorder :
2411
- self .data = np .fromiter (zip (* data_cols ), dtype = dtypes )
2412
- else :
2413
- self .data = data .to_records (index = False )
2406
+ self .data = data .to_records (index = False , column_dtypes = dtypes )
2414
2407
2415
2408
def _write_data (self ):
2416
2409
data = self .data
0 commit comments