File tree Expand file tree Collapse file tree 2 files changed +3
-10
lines changed
Expand file tree Collapse file tree 2 files changed +3
-10
lines changed Original file line number Diff line number Diff line change 1919)
2020
2121import numpy as np
22+ import json
2223
2324from pandas ._libs import writers as libwriters
2425from pandas ._typing import SequenceNotStr
@@ -100,12 +101,7 @@ def __init__(
100101 self .cols = self ._initialize_columns (cols )
101102 self .chunksize = self ._initialize_chunksize (chunksize )
102103
103- print ("output preserve var: " , self .preserve_complex )
104104 if self .preserve_complex :
105- print ("here1" )
106- import json
107- import numpy as np
108-
109105 for col in self .obj .columns :
110106 if self .obj [col ].dtype == "O" :
111107 first_val = self .obj [col ].iloc [0 ]
Original file line number Diff line number Diff line change @@ -863,22 +863,19 @@ def read_csv(
863863
864864def _restore_complex_arrays (df : DataFrame ) -> None :
865865 """
866- Loop over each column of df, check if it contains bracketed JSON strings
867- like "[0.1, 0.2, 0.3]", and parse them back into NumPy arrays .
866+ Converted bracketed JSON strings in df back to NumPy arrays.
867+ eg. "[0.1, 0.2, 0.3]" --> parse into NumPy array .
868868 """
869869 def looks_like_json_array (x : str ) -> bool :
870870 return x .startswith ("[" ) and x .endswith ("]" )
871871
872872 for col in df .columns :
873- # Only parse object columns
874873 if df [col ].dtype == "object" :
875- # skip null
876874 nonnull = df [col ].dropna ()
877875 if (
878876 len (nonnull ) > 0
879877 and nonnull .apply (lambda x : isinstance (x , str ) and looks_like_json_array (x )).all ()
880878 ):
881- # parse
882879 df [col ] = df [col ].apply (lambda x : np .array (json .loads (x )) if pd .notnull (x ) else x )
883880
884881
You can’t perform that action at this time.
0 commit comments