|
28 | 28 |
|
29 | 29 | import datetime |
30 | 30 |
|
| 31 | +import oracledb |
31 | 32 | import pyarrow |
32 | 33 | import pytest |
33 | 34 |
|
@@ -298,28 +299,34 @@ async def test_9410(dtype, value_is_date, async_conn): |
298 | 299 |
|
299 | 300 |
|
300 | 301 | @pytest.mark.parametrize( |
301 | | - "dtype,value_is_date", |
| 302 | + "dtype", |
302 | 303 | [ |
303 | | - (pyarrow.date32(), True), |
304 | | - (pyarrow.date64(), True), |
305 | | - (pyarrow.timestamp("s"), False), |
306 | | - (pyarrow.timestamp("us"), False), |
307 | | - (pyarrow.timestamp("ms"), False), |
308 | | - (pyarrow.timestamp("ns"), False), |
| 304 | + pyarrow.date32(), |
| 305 | + pyarrow.date64(), |
| 306 | + pyarrow.timestamp("s"), |
| 307 | + pyarrow.timestamp("us"), |
| 308 | + pyarrow.timestamp("ms"), |
| 309 | + pyarrow.timestamp("ns"), |
309 | 310 | ], |
310 | 311 | ) |
311 | | -async def test_9411(dtype, value_is_date, async_conn): |
| 312 | +async def test_9411(dtype, async_conn): |
312 | 313 | "9411 - fetch_df_all() for TIMESTAMP" |
313 | 314 | requested_schema = pyarrow.schema([("TIMESTAMP_COL", dtype)]) |
314 | | - value = datetime.datetime(2025, 1, 15) |
315 | | - statement = "select cast(:1 as timestamp) from dual" |
| 315 | + value = datetime.datetime(1974, 4, 4, 0, 57, 54, 15079) |
| 316 | + var = async_conn.cursor().var(oracledb.DB_TYPE_TIMESTAMP) |
| 317 | + var.setvalue(0, value) |
| 318 | + statement = "select :1 from dual" |
316 | 319 | ora_df = await async_conn.fetch_df_all( |
317 | | - statement, [value], requested_schema=requested_schema |
| 320 | + statement, [var], requested_schema=requested_schema |
318 | 321 | ) |
319 | 322 | tab = pyarrow.table(ora_df) |
320 | 323 | assert tab.field("TIMESTAMP_COL").type == dtype |
321 | | - if value_is_date: |
| 324 | + if not isinstance(dtype, pyarrow.TimestampType): |
322 | 325 | value = value.date() |
| 326 | + elif dtype.unit == "s": |
| 327 | + value = value.replace(microsecond=0) |
| 328 | + elif dtype.unit == "ms": |
| 329 | + value = value.replace(microsecond=(value.microsecond // 1000) * 1000) |
323 | 330 | assert tab["TIMESTAMP_COL"][0].as_py() == value |
324 | 331 |
|
325 | 332 |
|
|
0 commit comments