@@ -128,6 +128,7 @@ def _records2df(
128128 index : Optional [Union [str , List [str ]]],
129129 safe : bool ,
130130 dtype : Optional [Dict [str , pa .DataType ]],
131+ timestamp_as_object : bool ,
131132) -> pd .DataFrame :
132133 arrays : List [pa .Array ] = []
133134 for col_values , col_name in zip (tuple (zip (* records )), cols_names ): # Transposing
@@ -155,6 +156,7 @@ def _records2df(
155156 date_as_object = True ,
156157 types_mapper = _data_types .pyarrow2pandas_extension ,
157158 safe = safe ,
159+ timestamp_as_object = timestamp_as_object ,
158160 )
159161 if index is not None :
160162 df .set_index (index , inplace = True )
@@ -175,6 +177,7 @@ def _iterate_results(
175177 index_col : Optional [Union [str , List [str ]]],
176178 safe : bool ,
177179 dtype : Optional [Dict [str , pa .DataType ]],
180+ timestamp_as_object : bool ,
178181) -> Iterator [pd .DataFrame ]:
179182 with con .cursor () as cursor :
180183 cursor .execute (* cursor_args )
@@ -183,7 +186,14 @@ def _iterate_results(
183186 records = cursor .fetchmany (chunksize )
184187 if not records :
185188 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+ )
187197
188198
189199def _fetch_all_results (
@@ -192,6 +202,7 @@ def _fetch_all_results(
192202 index_col : Optional [Union [str , List [str ]]] = None ,
193203 dtype : Optional [Dict [str , pa .DataType ]] = None ,
194204 safe : bool = True ,
205+ timestamp_as_object : bool = False ,
195206) -> pd .DataFrame :
196207 with con .cursor () as cursor :
197208 cursor .execute (* cursor_args )
@@ -202,6 +213,7 @@ def _fetch_all_results(
202213 index = index_col ,
203214 dtype = dtype ,
204215 safe = safe ,
216+ timestamp_as_object = timestamp_as_object ,
205217 )
206218
207219
@@ -213,6 +225,7 @@ def read_sql_query(
213225 chunksize : Optional [int ] = None ,
214226 dtype : Optional [Dict [str , pa .DataType ]] = None ,
215227 safe : bool = True ,
228+ timestamp_as_object : bool = False ,
216229) -> Union [pd .DataFrame , Iterator [pd .DataFrame ]]:
217230 """Read SQL Query (generic)."""
218231 args = _convert_params (sql , params )
@@ -224,6 +237,7 @@ def read_sql_query(
224237 index_col = index_col ,
225238 dtype = dtype ,
226239 safe = safe ,
240+ timestamp_as_object = timestamp_as_object ,
227241 )
228242
229243 return _iterate_results (
@@ -233,6 +247,7 @@ def read_sql_query(
233247 index_col = index_col ,
234248 dtype = dtype ,
235249 safe = safe ,
250+ timestamp_as_object = timestamp_as_object ,
236251 )
237252 except Exception as ex :
238253 con .rollback ()
0 commit comments