File tree 1 file changed +5
-15
lines changed
1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change @@ -2385,32 +2385,22 @@ 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 = []
2390
- has_strings = False
2388
+ dtypes = {}
2391
2389
native_byteorder = self ._byteorder == _set_endianness (sys .byteorder )
2392
2390
for i , col in enumerate (data ):
2393
2391
typ = typlist [i ]
2394
2392
if typ <= self ._max_string_length :
2395
- has_strings = True
2396
2393
data [col ] = data [col ].fillna ('' ).apply (_pad_bytes , args = (typ ,))
2397
2394
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 ))
2395
+ dtypes [col ] = stype
2396
+ data [col ] = data [col ].str .encode (self ._encoding ).astype (stype )
2401
2397
else :
2402
- values = data [col ].values
2403
2398
dtype = data [col ].dtype
2404
2399
if not native_byteorder :
2405
2400
dtype = dtype .newbyteorder (self ._byteorder )
2406
- dtypes .append (('c' + str (i ), dtype ))
2407
- data_cols .append (values )
2408
- dtypes = np .dtype (dtypes )
2401
+ dtypes [col ] = dtype
2409
2402
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 )
2403
+ self .data = data .to_records (index = False , column_dtypes = dtypes )
2414
2404
2415
2405
def _write_data (self ):
2416
2406
data = self .data
You can’t perform that action at this time.
0 commit comments