diff --git a/awswrangler/s3.py b/awswrangler/s3.py index b13ccff63..8f0bb5f10 100644 --- a/awswrangler/s3.py +++ b/awswrangler/s3.py @@ -677,6 +677,8 @@ def to_csv( # pylint: disable=too-many-arguments raise exceptions.InvalidArgumentCombination("Please, pass dataset=True to be able to use partition_cols.") if mode is not None: raise exceptions.InvalidArgumentCombination("Please pass dataset=True to be able to use mode.") + if columns_comments: + raise exceptions.InvalidArgumentCombination("Please pass dataset=True to be able to use columns_comments.") if any(arg is not None for arg in (database, table, description, parameters)): raise exceptions.InvalidArgumentCombination( "Please pass dataset=True to be able to use any one of these " diff --git a/testing/test_awswrangler/test_moto.py b/testing/test_awswrangler/test_moto.py index 01bde208f..e1b9e4fbf 100644 --- a/testing/test_awswrangler/test_moto.py +++ b/testing/test_awswrangler/test_moto.py @@ -2,11 +2,12 @@ import botocore import mock import moto +import pandas as pd import pytest from botocore.exceptions import ClientError import awswrangler as wr - +from awswrangler.exceptions import InvalidArgumentCombination, EmptyDataFrame from ._utils import ensure_data_types, get_df_csv, get_df_list @@ -217,6 +218,105 @@ def test_csv(s3): assert len(df.columns) == 10 +def test_to_csv_invalid_argument_combination_raise_when_dataset_false_succeed(s3): + path = "s3://bucket/test.csv" + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), path=path, index=False, database='foo') + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), path=path, index=False, table='foo') + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + partition_cols=["par0", "par1"]) + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + mode='append') + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + partition_cols=["par0", "par1"]) + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + database='default', + table='test') + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + description='raise exception') + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + parameters={'key': 'value'}) + + with pytest.raises(InvalidArgumentCombination): + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=False, + columns_comments={'col0': 'test'}) + + +def test_to_csv_valid_argument_combination_when_dataset_true_succeed(s3): + path = "s3://bucket/test.csv" + wr.s3.to_csv(df=get_df_csv(), path=path, index=False) + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=True, + partition_cols=["par0", "par1"]) + + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=True, + mode='append') + + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=True, + description='raise exception') + + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=True, + parameters={'key': 'value'}) + + wr.s3.to_csv(df=get_df_csv(), + path=path, + index=False, + dataset=True, + columns_comments={'col0': 'test'}) + + +def test_to_csv_data_empty_raise_succeed(s3): + path = "s3://bucket/test.csv" + with pytest.raises(EmptyDataFrame): + wr.s3.to_csv(df=pd.DataFrame(), path=path, index=False) + + def test_parquet(s3): path = "s3://bucket/test.parquet" wr.s3.to_parquet(df=get_df_list(), path=path, index=False, dataset=True, partition_cols=["par0", "par1"])