Skip to content

Commit 9528161

Browse files
committed
Add categories arg to athena.read_sql_table #160
1 parent e373e7e commit 9528161

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

awswrangler/athena.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ def read_sql_table(
563563
table: str,
564564
database: str,
565565
ctas_approach: bool = True,
566+
categories: List[str] = None,
566567
chunksize: Optional[int] = None,
567568
s3_output: Optional[str] = None,
568569
workgroup: Optional[str] = None,
@@ -614,6 +615,9 @@ def read_sql_table(
614615
ctas_approach: bool
615616
Wraps the query using a CTAS, and read the resulted parquet data on S3.
616617
If false, read the regular CSV on S3.
618+
categories: List[str], optional
619+
List of columns names that should be returned as pandas.Categorical.
620+
Recommended for memory restricted environments.
617621
chunksize: int, optional
618622
If specified, return an generator where chunksize is the number of rows to include in each chunk.
619623
s3_output : str, optional
@@ -645,6 +649,7 @@ def read_sql_table(
645649
sql=f'SELECT * FROM "{table}"',
646650
database=database,
647651
ctas_approach=ctas_approach,
652+
categories=categories,
648653
chunksize=chunksize,
649654
s3_output=s3_output,
650655
workgroup=workgroup,

testing/test_awswrangler/test_data_lake.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ def test_category(bucket, database):
646646
ensure_data_types_category(df2)
647647
df2 = wr.athena.read_sql_query("SELECT * FROM test_category", database=database, categories=list(df.columns))
648648
ensure_data_types_category(df2)
649+
df2 = wr.athena.read_sql_table(table="test_category", database=database, categories=list(df.columns))
650+
ensure_data_types_category(df2)
649651
df2 = wr.athena.read_sql_query(
650652
"SELECT * FROM test_category", database=database, categories=list(df.columns), ctas_approach=False
651653
)

0 commit comments

Comments
 (0)