@@ -85,37 +85,38 @@ def fix_columns_with_query(
8585):
8686 """Use a query object to suggest how to convert columns imported from csv to correct types."""
8787
88- if len (df ) > 0 :
89- n_tables = len (query .column_descriptions )
88+
89+ n_tables = len (query .column_descriptions )
90+ if n_tables == 1 :
91+ schema_model = query .column_descriptions [0 ]["type" ]
92+ for colname in df .columns :
9093 if n_tables == 1 :
91- schema_model = query .column_descriptions [0 ]["type" ]
92- for colname in df .columns :
93- if n_tables == 1 :
94- coltype = type (getattr (schema_model , colname ).type )
95- else :
96- coltype = type (
97- next (
98- col ["type" ]
99- for col in query .column_descriptions
100- if col ["name" ] == colname
101- )
102- )
103- if coltype is Boolean :
104- pass
105- # df[colname] = _fix_boolean_column(df[colname])
106- elif coltype is DateTime :
107- # if the first entry for this column has a decimal point,
108- # then it is one format and we want to convert it using that format
109- df [colname ] = pd .to_datetime (
110- df [colname ], utc = True , format = 'ISO8601'
111- )
112-
113- elif coltype is Geometry and fix_wkb is True :
114- df [colname ] = fix_wkb_column (
115- df [colname ],
116- wkb_data_start_ind = wkb_data_start_ind ,
117- n_threads = n_threads ,
94+ coltype = type (getattr (schema_model , colname ).type )
95+ else :
96+ coltype = type (
97+ next (
98+ col ["type" ]
99+ for col in query .column_descriptions
100+ if col ["name" ] == colname
118101 )
102+ )
103+ if coltype is Boolean :
104+ pass
105+ # df[colname] = _fix_boolean_column(df[colname])
106+ elif coltype is DateTime :
107+ # if the first entry for this column has a decimal point,
108+ # then it is one format and we want to convert it using that format
109+ df [colname ] = pd .to_datetime (
110+ df [colname ], utc = True , format = 'ISO8601'
111+ )
112+ if len (df ) > 0 :
113+ if coltype is Geometry and fix_wkb is True :
114+
115+ df [colname ] = fix_wkb_column (
116+ df [colname ],
117+ wkb_data_start_ind = wkb_data_start_ind ,
118+ n_threads = n_threads ,
119+ )
119120 elif isinstance (df [colname ].loc [0 ], Decimal ) and fix_decimal is True :
120121 df [colname ] = _fix_decimal_column (df [colname ])
121122 return df
0 commit comments