I've found that if we import PandasCursor this interfers with pandas using s3fs/fsspec to write to s3.
Minimal viable example:
import pandas as pd
from pyathena.pandas.cursor import PandasCursor
my_df = pd.DataFrame(dict(a=[1], b=[1]))
s3_bucket = "" # add a valid s3 bucket
output_path = f"s3://{s3_bucket}/my_prefix/file.csv"
my_df.to_csv(output_path)
and I get the following error:
Traceback (most recent call last):
File "/app/pipelines/bug_example.py", line 12, in <module>
my_df.to_csv(output_path)
File "/usr/local/lib/python3.10/site-packages/pandas/core/generic.py", line 3772, in to_csv
return DataFrameRenderer(formatter).to_csv(
File "/usr/local/lib/python3.10/site-packages/pandas/io/formats/format.py", line 1186, in to_csv
csv_formatter.save()
File "/usr/local/lib/python3.10/site-packages/pandas/io/formats/csvs.py", line 240, in save
with get_handle(
File "/usr/local/lib/python3.10/site-packages/pandas/io/common.py", line 138, in __exit__
self.close()
File "/usr/local/lib/python3.10/site-packages/pandas/io/common.py", line 130, in close
handle.close()
File "/usr/local/lib/python3.10/site-packages/pyathena/filesystem/s3.py", line 518, in close
super(S3File, self).close()
File "/usr/local/lib/python3.10/site-packages/fsspec/spec.py", line 1876, in close
self.flush(force=True)
File "/usr/local/lib/python3.10/site-packages/fsspec/spec.py", line 1742, in flush
self._initiate_upload()
File "/usr/local/lib/python3.10/site-packages/pyathena/filesystem/s3.py", line 522, in _initiate_upload
raise NotImplementedError # pragma: no cover
If you remove the pandascursor import, this works fine:
import pandas as pd
# from pyathena.pandas.cursor import PandasCursor
my_df = pd.DataFrame(dict(a=[1], b=[1]))
s3_bucket = "" # add a valid s3 bucket
output_path = f"s3://{s3_bucket}/my_prefix/file.csv"
my_df.to_csv(output_path)
I've found that if we import PandasCursor this interfers with pandas using s3fs/fsspec to write to s3.
Minimal viable example:
and I get the following error:
If you remove the pandascursor import, this works fine: