Skip to content

Commit 55b1226

Browse files
committed
Support for empty dataframe for Pandas.read_sql_athena(ctas_approach=True)
1 parent bf54802 commit 55b1226

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

awswrangler/pandas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ def _read_sql_athena_ctas(self,
582582
self._session.glue.delete_table_if_exists(database=database, table=name)
583583
manifest_path: str = f"{s3_output}/tables/{query_id}-manifest.csv"
584584
paths: List[str] = self._session.athena.extract_manifest_paths(path=manifest_path)
585+
if not paths:
586+
return pd.DataFrame()
585587
logger.debug(f"paths: {paths}")
586588
return self.read_parquet(path=paths,
587589
procs_cpu_bound=procs_cpu_bound,

testing/test_awswrangler/test_pandas.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,3 +2020,17 @@ def test_read_csv_prefix_iterator(bucket, sample, row_num):
20202020
total_count += count
20212021
wr.s3.delete_listed_objects(objects_paths=paths)
20222022
assert total_count == row_num * n
2023+
2024+
2025+
@pytest.mark.parametrize("ctas_approach", [False, True])
2026+
def test_read_sql_athena_empty(ctas_approach):
2027+
sql = """
2028+
WITH dataset AS (
2029+
SELECT 0 AS id
2030+
)
2031+
SELECT id
2032+
FROM dataset
2033+
WHERE id != 0
2034+
"""
2035+
df = wr.pandas.read_sql_athena(sql=sql, ctas_approach=ctas_approach)
2036+
print(df)

0 commit comments

Comments
 (0)