aws-sdk-pandas: `wr.s3.to_deltalake` throwing TypeError about storage_options

Describe the bug

Calling we.s3.to_deltalake() throws the following error:

self._table = RawDeltaTable(
                  ^^^^^^^^^^^^^^
TypeError: argument 'storage_options': 'NoneType' object cannot be converted to 'PyString'

How to Reproduce

wr.s3.to_deltalake(
            df=data,
            path="s3://bucket/delta",
            index=False,
            partition_cols=["a", "b"],
            overwrite_schema=True,
            s3_additional_kwargs={
                "AWS_ACCESS_KEY_ID": "...",
                "AWS_SECRET_ACCESS_KEY": "...",
                "AWS_REGION": "eu-west-1",
            },
            s3_allow_unsafe_rename=True,
        )

Expected behavior

I’d expect awswrangler to connect to S3 and write the delta table.

Your project

No response

Screenshots

No response

OS

Mac

Python version

3.11.4

AWS SDK for pandas version

3.2.1

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Most upvoted comments

I just set the unused AWS_SESSION_TOKEN to an empty string to override it from being set to None when calling to_deltalake to fix the issue:

boto3_session = boto3.Session(region_name="us-east-1")
df = pd.DataFrame({"c0": [1, 2, 3], "c1": [True, False, True], "par0": ["foo", "foo", "bar"], "par1": [1, 2, 2]})
wr.s3.to_deltalake(
    path=path,
    df=df,
    index=False,
    boto3_session=boto3_session,
    partition_cols=["par0", "par1"],
    overwrite_schema=True,
    s3_allow_unsafe_rename=True,
    s3_additional_kwargs={
        'AWS_SESSION_TOKEN': ''
    }
)

The s3_additional_kwargs argument is for passing S3 specific arguments like ServerSideEncryption, not your AWS credentials. The boto3 session is used to extract the credentials and the region. So as long as that is correctly configured and passed, it should be enough:

boto3_session = boto3.Session(region_name="eu-west-1")
wr.s3.to_deltalake(path=path, df=df, boto3_session=boto3_session, s3_additional_kwargs={"ServerSideEncryption": "AES256"})