Skip to content

Commit e4f8436

Browse files
fix: athena.read_sql_query failing for time columns (#2895)
1 parent ec1d7d6 commit e4f8436

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

awswrangler/_data_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ def athena2pandas(dtype: str, dtype_backend: str | None = None) -> str: # noqa:
372372
return "datetime64" if dtype_backend != "pyarrow" else "timestamp[ns][pyarrow]"
373373
if dtype == "date":
374374
return "date" if dtype_backend != "pyarrow" else "date32[pyarrow]"
375+
if dtype == "time":
376+
# Pandas does not have a type for time of day, so we are returning a string.
377+
# However, if the backend is pyarrow, we can return time32[ms]
378+
return "string" if dtype_backend != "pyarrow" else "time32[ms][pyarrow]"
375379
if dtype.startswith("decimal"):
376380
return "decimal" if dtype_backend != "pyarrow" else "double[pyarrow]"
377381
if dtype in ("binary", "varbinary"):

tests/unit/test_athena.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,17 @@ def test_athena_time_zone(glue_database):
705705
assert df["value"][0].year == datetime.datetime.utcnow().year
706706

707707

708+
@pytest.mark.parametrize("dtype_backend", ["numpy_nullable", "pyarrow"])
709+
def test_athena_time_type(glue_database: str, dtype_backend: str) -> None:
710+
df = wr.athena.read_sql_query(
711+
"SELECT time '13:24:11' as col", glue_database, ctas_approach=False, dtype_backend=dtype_backend
712+
)
713+
if dtype_backend == "pyarrow":
714+
assert df["col"].iloc[0] == datetime.time(13, 24, 11)
715+
else:
716+
assert df["col"].iloc[0] == "13:24:11"
717+
718+
708719
@pytest.mark.parametrize(
709720
"ctas_approach",
710721
[

0 commit comments

Comments
 (0)