Skip to content

Overwriting parquet dataset on S3 doesn't create a new bucket #8056

Closed

Description

@jrbourbeau

When iterating on workflows, I find it useful to specify overwrite=True when writing out parquet datasets. Previously I had always been writing to an S3 bucket which already existed and everything worked as expected. Today I tried writing to a bucket which did not exist and hoped that to_parquet would create the bucket for me, however when I run this snippet:

import dask

df = dask.datasets.timeseries()

storage_options={
    "config_kwargs": {"region_name": "us-east-1"},
}

df.to_parquet(
    "s3://james-foo/timeseries.parquet",
    # "james-foo/timeseries.parquet",  # When using a local path, the necessary directories are created
    engine="pyarrow-dataset",
    storage_options=storage_options,
    overwrite=True,
)

I get the following FileNotFoundError: The specified bucket does not exist exception:

Traceback (most recent call last):
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/s3fs/core.py", line 574, in _lsdir
    async for i in it:
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/aiobotocore/paginate.py", line 32, in __anext__
    response = await self._make_request(current_kwargs)
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/aiobotocore/client.py", line 155, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/james/projects/dask/dask/test.py", line 10, in <module>
    df.to_parquet(
  File "/Users/james/projects/dask/dask/dask/dataframe/core.py", line 4440, in to_parquet
    return to_parquet(self, path, *args, **kwargs)
  File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/core.py", line 572, in to_parquet
    if fs.isdir(path):
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/fsspec/asyn.py", line 88, in wrapper
    return sync(self.loop, func, *args, **kwargs)
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/fsspec/asyn.py", line 69, in sync
    raise result[0]
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/fsspec/asyn.py", line 25, in _runner
    result[0] = await coro
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/s3fs/core.py", line 1161, in _isdir
    return bool(await self._lsdir(path))
  File "/Users/james/mambaforge/envs/dask/lib/python3.9/site-packages/s3fs/core.py", line 597, in _lsdir
    raise translate_boto_error(e)
FileNotFoundError: The specified bucket does not exist

A couple of relevant things to note:

  1. If I set overwrite=False, then the bucket is created and the above snippet runs successfully
  2. If I use a local path, instead of on S3, then the appropriate local directories are also created

This makes me think there's a mismatch between how fsspec filesystems behave. cc @martindurant

Activity

  1. martindurant commented on Aug 19, 2021

    @martindurant
    Member

    Coming back to this, I wonder if it's possible to write a test with s3fs methods alone, which produces contradictory outputs for isdir and exists? I have not been able to do it yet.

  2. jrbourbeau commented on Aug 20, 2021

    @jrbourbeau
    MemberAuthor

    That's a fair point, here's what I've been able to come up with

    import s3fs
    
    fs = s3fs.S3FileSystem(anon=True)
    # This directory exists
    good_path = "s3://nyc-tlc/trip data/"
    print(f"{fs.exists(good_path) = }")
    print(f"{fs.isdir(good_path) = }")
    
    # This bucket doesn't exist
    bad_path = "s3://nyc-tlc-asdfasdf/trip data/"
    print(f"{fs.exists(bad_path) = }")
    print(f"{fs.isdir(bad_path) = }")

    when I run this locally I get the following

    fs.exists(good_path) = True
    fs.isdir(good_path) = True
    fs.exists(bad_path) = False
    Traceback (most recent call last):
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 574, in _lsdir
        async for i in it:
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/aiobotocore/paginate.py", line 32, in __anext__
        response = await self._make_request(current_kwargs)
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/aiobotocore/client.py", line 155, in _make_api_call
        raise error_class(parsed_response, operation_name)
    botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/Users/james/projects/dask/dask/s3test.py", line 13, in <module>
        print(f"{fs.isdir(bad_path) = }")
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 88, in wrapper
        return sync(self.loop, func, *args, **kwargs)
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 69, in sync
        raise result[0]
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fsspec/asyn.py", line 25, in _runner
        result[0] = await coro
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 1161, in _isdir
        return bool(await self._lsdir(path))
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/s3fs/core.py", line 597, in _lsdir
        raise translate_boto_error(e)
    FileNotFoundError: The specified bucket does not exist
    

    Note that fs.exists(bad_path) returns False, while fs.isdir(bad_path) raises a FileNotFoundError: The specified bucket does not exist error. This is the type of discrepancy I was running into earlier with to_parquet + overwrite=True and what motivated me proposing the fs.exists check in #8057.

  3. martindurant commented on Aug 24, 2021

    @martindurant
    Member

    Close this?

  4. jrbourbeau commented on Aug 24, 2021

    @jrbourbeau
    MemberAuthor

    Yep, let's close via #8057 and continue to track over in fsspec/s3fs#519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions