# Buggy code
def write(
    self,
    df: DataFrame,
    path,
    compression="snappy",
    index: Optional[bool] = None,
    partition_cols=None,
    **kwargs,
):
    self.validate_dataframe(df)
    path, _, _, _ = get_filepath_or_buffer(path, mode="wb")

    from_pandas_kwargs: Dict[str, Any] = {"schema": kwargs.pop("schema", None)}
    if index is not None:
        from_pandas_kwargs["preserve_index"] = index

    table = self.api.Table.from_pandas(df, **from_pandas_kwargs)
    if partition_cols is not None:
        self.api.parquet.write_to_dataset(
            table,
            path,
            compression=compression,
            partition_cols=partition_cols,
            **kwargs,
        )
    else:
        self.api.parquet.write_table(table, path, compression=compression, **kwargs)


# Traceback (botocore.exceptions.NoCredentialsError)
Exception ignored in: <function AbstractBufferedFile.__del__ at 0x7fe0ae8db440>
Traceback (most recent call last):
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/fsspec/spec.py", line 1137, in __del__
self.close()
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/fsspec/spec.py", line 1114, in close
self.flush(force=True)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/fsspec/spec.py", line 986, in flush
self._initiate_upload()
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/s3fs/core.py", line 951, in _initiate_upload
Bucket=self.bucket, Key=self.key, ACL=self.acl)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/s3fs/core.py", line 939, in _call_s3
**kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/s3fs/core.py", line 182, in _call_s3
return method(**additional_kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/endpoint.py", line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/endpoint.py", line 116, in create_request
operation_name=operation_model.name)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/signers.py", line 90, in handler
return self.sign(operation_name, request)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/signers.py", line 157, in sign
auth.add_auth(request)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/auth.py", line 425, in add_auth
super(S3SigV4Auth, self).add_auth(request)
File "/home/languitar/.pyenv/versions/analytics-3.7/lib/python3.7/site-packages/botocore/auth.py", line 357, in add_auth
raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials

# Fixed code
def write(
    self,
    df: DataFrame,
    path,
    compression="snappy",
    index: Optional[bool] = None,
    partition_cols=None,
    **kwargs,
):
    self.validate_dataframe(df)
    path, _, _, should_close = get_filepath_or_buffer(path, mode="wb")

    from_pandas_kwargs: Dict[str, Any] = {"schema": kwargs.pop("schema", None)}
    if index is not None:
        from_pandas_kwargs["preserve_index"] = index

    table = self.api.Table.from_pandas(df, **from_pandas_kwargs)
    if partition_cols is not None:
        self.api.parquet.write_to_dataset(
            table,
            path,
            compression=compression,
            partition_cols=partition_cols,
            **kwargs,
        )
    else:
        self.api.parquet.write_table(table, path, compression=compression, **kwargs)
    if should_close:
        path.close()