# Buggy code
def save(self) -> None:
    """
    Create the writer & save.
    """
    # GH21227 internal compression is not used when file-like passed.
    if self.compression and hasattr(self.path_or_buf, "write"):
        warnings.warn(
            "compression has no effect when passing file-like object as input.",
            RuntimeWarning,
            stacklevel=2,
        )

    # when zip compression is called.
    is_zip = isinstance(self.path_or_buf, ZipFile) or (
        not hasattr(self.path_or_buf, "write") and self.compression == "zip"
    )

    if is_zip:
        # zipfile doesn't support writing string to archive. uses string
        # buffer to receive csv writing and dump into zip compression
        # file handle. GH21241, GH21118
        f = StringIO()
        close = False
    elif hasattr(self.path_or_buf, "write"):
        f = self.path_or_buf
        close = False
    else:
        f, handles = get_handle(
            self.path_or_buf,
            self.mode,
            encoding=self.encoding,
            compression=dict(self.compression_args, method=self.compression),
        )
        close = True

    try:
        # Note: self.encoding is irrelevant here
        self.writer = csvlib.writer(
            f,
            lineterminator=self.line_terminator,
            delimiter=self.sep,
            quoting=self.quoting,
            doublequote=self.doublequote,
            escapechar=self.escapechar,
            quotechar=self.quotechar,
        )

        self._save()

    finally:
        if is_zip:
            # GH17778 handles zip compression separately.
            buf = f.getvalue()
            if hasattr(self.path_or_buf, "write"):
                self.path_or_buf.write(buf)
            else:
                compression = dict(self.compression_args, method=self.compression)

                f, handles = get_handle(
                    self.path_or_buf,
                    self.mode,
                    encoding=self.encoding,
                    compression=compression,
                )
                f.write(buf)
                close = True
        if close:
            f.close()
            for _fh in handles:
                _fh.close()


# 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 save(self) -> None:
    """
    Create the writer & save.
    """
    # GH21227 internal compression is not used when file-like passed.
    if self.compression and hasattr(self.path_or_buf, "write"):
        warnings.warn(
            "compression has no effect when passing file-like object as input.",
            RuntimeWarning,
            stacklevel=2,
        )

    # when zip compression is called.
    is_zip = isinstance(self.path_or_buf, ZipFile) or (
        not hasattr(self.path_or_buf, "write") and self.compression == "zip"
    )

    if is_zip:
        # zipfile doesn't support writing string to archive. uses string
        # buffer to receive csv writing and dump into zip compression
        # file handle. GH21241, GH21118
        f = StringIO()
        close = False
    elif hasattr(self.path_or_buf, "write"):
        f = self.path_or_buf
        close = False
    else:
        f, handles = get_handle(
            self.path_or_buf,
            self.mode,
            encoding=self.encoding,
            compression=dict(self.compression_args, method=self.compression),
        )
        close = True

    try:
        # Note: self.encoding is irrelevant here
        self.writer = csvlib.writer(
            f,
            lineterminator=self.line_terminator,
            delimiter=self.sep,
            quoting=self.quoting,
            doublequote=self.doublequote,
            escapechar=self.escapechar,
            quotechar=self.quotechar,
        )

        self._save()

    finally:
        if is_zip:
            # GH17778 handles zip compression separately.
            buf = f.getvalue()
            if hasattr(self.path_or_buf, "write"):
                self.path_or_buf.write(buf)
            else:
                compression = dict(self.compression_args, method=self.compression)

                f, handles = get_handle(
                    self.path_or_buf,
                    self.mode,
                    encoding=self.encoding,
                    compression=compression,
                )
                f.write(buf)
                close = True
        if close:
            f.close()
            for _fh in handles:
                _fh.close()
        elif self.should_close:
            f.close()