@@ -128,6 +128,7 @@ def _records2df(
128
128
index : Optional [Union [str , List [str ]]],
129
129
safe : bool ,
130
130
dtype : Optional [Dict [str , pa .DataType ]],
131
+ timestamp_as_object : bool ,
131
132
) -> pd .DataFrame :
132
133
arrays : List [pa .Array ] = []
133
134
for col_values , col_name in zip (tuple (zip (* records )), cols_names ): # Transposing
@@ -155,6 +156,7 @@ def _records2df(
155
156
date_as_object = True ,
156
157
types_mapper = _data_types .pyarrow2pandas_extension ,
157
158
safe = safe ,
159
+ timestamp_as_object = timestamp_as_object ,
158
160
)
159
161
if index is not None :
160
162
df .set_index (index , inplace = True )
@@ -175,6 +177,7 @@ def _iterate_results(
175
177
index_col : Optional [Union [str , List [str ]]],
176
178
safe : bool ,
177
179
dtype : Optional [Dict [str , pa .DataType ]],
180
+ timestamp_as_object : bool ,
178
181
) -> Iterator [pd .DataFrame ]:
179
182
with con .cursor () as cursor :
180
183
cursor .execute (* cursor_args )
@@ -183,7 +186,14 @@ def _iterate_results(
183
186
records = cursor .fetchmany (chunksize )
184
187
if not records :
185
188
break
186
- yield _records2df (records = records , cols_names = cols_names , index = index_col , safe = safe , dtype = dtype )
189
+ yield _records2df (
190
+ records = records ,
191
+ cols_names = cols_names ,
192
+ index = index_col ,
193
+ safe = safe ,
194
+ dtype = dtype ,
195
+ timestamp_as_object = timestamp_as_object ,
196
+ )
187
197
188
198
189
199
def _fetch_all_results (
@@ -192,6 +202,7 @@ def _fetch_all_results(
192
202
index_col : Optional [Union [str , List [str ]]] = None ,
193
203
dtype : Optional [Dict [str , pa .DataType ]] = None ,
194
204
safe : bool = True ,
205
+ timestamp_as_object : bool = False ,
195
206
) -> pd .DataFrame :
196
207
with con .cursor () as cursor :
197
208
cursor .execute (* cursor_args )
@@ -202,6 +213,7 @@ def _fetch_all_results(
202
213
index = index_col ,
203
214
dtype = dtype ,
204
215
safe = safe ,
216
+ timestamp_as_object = timestamp_as_object ,
205
217
)
206
218
207
219
@@ -213,6 +225,7 @@ def read_sql_query(
213
225
chunksize : Optional [int ] = None ,
214
226
dtype : Optional [Dict [str , pa .DataType ]] = None ,
215
227
safe : bool = True ,
228
+ timestamp_as_object : bool = False ,
216
229
) -> Union [pd .DataFrame , Iterator [pd .DataFrame ]]:
217
230
"""Read SQL Query (generic)."""
218
231
args = _convert_params (sql , params )
@@ -224,6 +237,7 @@ def read_sql_query(
224
237
index_col = index_col ,
225
238
dtype = dtype ,
226
239
safe = safe ,
240
+ timestamp_as_object = timestamp_as_object ,
227
241
)
228
242
229
243
return _iterate_results (
@@ -233,6 +247,7 @@ def read_sql_query(
233
247
index_col = index_col ,
234
248
dtype = dtype ,
235
249
safe = safe ,
250
+ timestamp_as_object = timestamp_as_object ,
236
251
)
237
252
except Exception as ex :
238
253
con .rollback ()
0 commit comments