Skip to content

Commit f2709a0

Browse files
committed
Improving tests for ctas_approach
1 parent eac8362 commit f2709a0

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

awswrangler/pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def read_sql_athena(self,
528528
:param max_result_size: Max number of bytes on each request to S3 (VALID ONLY FOR ctas_approach=False)
529529
:return: Pandas Dataframe or Iterator of Pandas Dataframes if max_result_size was passed
530530
"""
531-
ctas_approach = ctas_approach if ctas_approach is not None else self._session.ctas_approach if self._session.ctas_approach is not None else False
531+
ctas_approach = ctas_approach if ctas_approach is not None else self._session.athena_ctas_approach if self._session.athena_ctas_approach is not None else False
532532
if ctas_approach is True and max_result_size is not None:
533533
raise InvalidParameters("ctas_approach can't use max_result_size!")
534534
if s3_output is None:

testing/test_awswrangler/test_pandas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ def test_read_table(session, bucket, database):
14421442
preserve_index=False,
14431443
procs_cpu_bound=1)
14441444
df2 = session.pandas.read_table(database=database, table="test")
1445+
session.s3.delete_objects(path=path)
14451446
assert len(list(df.columns)) == len(list(df2.columns))
14461447
assert len(df.index) == len(df2.index)
14471448

@@ -1465,7 +1466,7 @@ def test_read_table2(session, bucket, database):
14651466
3)]],
14661467
"partition": [0, 0, 1]
14671468
})
1468-
path = f"s3://{bucket}/test_read_table/"
1469+
path = f"s3://{bucket}/test_read_table2/"
14691470
session.pandas.to_parquet(dataframe=df,
14701471
database=database,
14711472
table="test",
@@ -1474,8 +1475,9 @@ def test_read_table2(session, bucket, database):
14741475
preserve_index=False,
14751476
procs_cpu_bound=4,
14761477
partition_cols=["partition"])
1477-
sleep(5)
1478+
sleep(15)
14781479
df2 = session.pandas.read_table(database=database, table="test")
1480+
session.s3.delete_objects(path=path)
14791481
assert len(list(df.columns)) == len(list(df2.columns))
14801482
assert len(df.index) == len(df2.index)
14811483

testing/test_awswrangler/test_redshift.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ def test_to_redshift_spark_decimal(session, bucket, redshift_parameters):
510510
assert row[2] == Decimal((0, (1, 9, 0, 0, 0, 0), -5))
511511

512512

513-
def test_to_parquet(bucket, redshift_parameters):
513+
def test_to_parquet(session, bucket, redshift_parameters):
514+
n: int = 1_000_000
515+
df = pd.DataFrame({"id": list((range(n))), "name": list(["foo" if i % 2 == 0 else "boo" for i in range(n)])})
514516
con = Redshift.generate_connection(
515517
database="test",
516518
host=redshift_parameters.get("RedshiftAddress"),
@@ -519,12 +521,23 @@ def test_to_parquet(bucket, redshift_parameters):
519521
password=redshift_parameters.get("RedshiftPassword"),
520522
)
521523
path = f"s3://{bucket}/test_to_parquet/"
524+
session.pandas.to_redshift(
525+
dataframe=df,
526+
path=path,
527+
schema="public",
528+
table="test",
529+
connection=con,
530+
iam_role=redshift_parameters.get("RedshiftRole"),
531+
mode="overwrite",
532+
preserve_index=True,
533+
)
534+
path = f"s3://{bucket}/test_to_parquet2/"
522535
paths = Redshift.to_parquet(sql="SELECT * FROM public.test",
523536
path=path,
524537
iam_role=redshift_parameters.get("RedshiftRole"),
525538
connection=con,
526539
partition_cols=["name"])
527-
assert len(paths) == 20
540+
assert len(paths) == 4
528541

529542

530543
@pytest.mark.parametrize("sample_name", ["micro", "small", "nano"])

0 commit comments

Comments
 (0)