8000 TST: Refactor S3 tests by fangchenli · Pull Request #61703 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

TST: Refactor S3 tests #61703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update signatures
  • Loading branch information
fangchenli committed Jun 24, 2025
commit 894775002855114914e18a35c5e5612b814484f1
24 changes: 16 additions & 8 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,29 +934,37 @@ def test_read_from_http_url(self, httpserver, read_ext):

@td.skip_if_not_us_locale
@pytest.mark.single_cpu
def test_read_from_s3_url(self, read_ext, s3_public_bucket, s3so):
# Bucket created in tests/io/conftest.py
def test_read_from_s3_url(self, read_ext, s3_bucket_public):
s3so = {
"client_kwargs": {
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url,
}
}
with open("test1" + read_ext, "rb") as f:
s3_public_bucket.put_object(Key="test1" + read_ext, Body=f)
s3_bucket_public.put_object(Key="test1" + read_ext, Body=f)

url = f"s3://{s3_public_bucket.name}/test1" + read_ext
url = f"s3://{s3_bucket_public.name}/test1" + read_ext

url_table = pd.read_excel(url, storage_options=s3so)
local_table = pd.read_excel("test1" + read_ext)
tm.assert_frame_equal(url_table, local_table)

@pytest.mark.single_cpu
def test_read_from_s3_object(self, read_ext, s3_public_bucket, s3so):
def test_read_from_s3_object(self, read_ext, s3_bucket_public):
# GH 38788
# Bucket created in tests/io/conftest.py
s3so = {
"client_kwargs": {
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url,
}
}
with open("test1" + read_ext, "rb") as f:
s3_public_bucket.put_object(Key="test1" + read_ext, Body=f)
s3_bucket_public.put_object(Key="test1" + read_ext, Body=f)

import s3fs

s3 = s3fs.S3FileSystem(**s3so)

with s3.open(f"s3://{s3_public_bucket.name}/test1" + read_ext) as f:
with s3.open(f"s3://{s3_bucket_public.name}/test1" + read_ext) as f:
url_table = pd.read_excel(f)

local_table = pd.read_excel("test1" + read_ext)
Expand Down
18 changes: 9 additions & 9 deletions pandas/tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ def test_fastparquet_options(fsspectest):

@pytest.mark.single_cpu
@pytest.mark.parametrize("compression_suffix", ["", ".gz", ".bz2"])
def test_from_s3_csv(s3_public_bucket_with_data, tips_file, compression_suffix):
def test_from_s3_csv(s3_bucket_public_with_data, tips_file, compression_suffix):
pytest.importorskip("s3fs")

s3so = {
"client_kwargs": {
"endpoint_url": s3_public_bucket_with_data.meta.client.meta.endpoint_url
"endpoint_url": s3_bucket_public_with_data.meta.client.meta.endpoint_url
}
}
df_from_s3 = read_csv(
f"s3://{s3_public_bucket_with_data.name}/tips.csv{compression_suffix}",
f"s3://{s3_bucket_public_with_data.name}/tips.csv{compression_suffix}",
storage_options=s3so,
)
df_from_local = read_csv(tips_file)
Expand All @@ -249,16 +249,16 @@ def test_from_s3_csv(s3_public_bucket_with_data, tips_file, compression_suffix):

@pytest.mark.single_cpu
@pytest.mark.parametrize("protocol", ["s3", "s3a", "s3n"])
def test_s3_protocols(s3_public_bucket_with_data, tips_file, protocol):
def test_s3_protocols(s3_bucket_public_with_data, tips_file, protocol):
pytest.importorskip("s3fs")

s3so = {
"client_kwargs": {
"endpoint_url": s3_public_bucket_with_data.meta.client.meta.endpoint_url
"endpoint_url": s3_bucket_public_with_data.meta.client.meta.endpoint_url
}
}
df_from_s3 = read_csv(
f"{protocol}://{s3_public_bucket_with_data.name}/tips.csv",
f"{protocol}://{s3_bucket_public_with_data.name}/tips.csv",
storage_options=s3so,
)
df_from_local = read_csv(tips_file)
Expand All @@ -267,14 +267,14 @@ def test_s3_protocols(s3_public_bucket_with_data, tips_file, protocol):

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string) fastparquet")
@pytest.mark.single_cpu
def test_s3_parquet(s3_public_bucket, df1):
def test_s3_parquet(s3_bucket_public, df1):
pytest.importorskip("fastparquet")
pytest.importorskip("s3fs")

fn = f"s3://{s3_public_bucket.name}/test.parquet"
fn = f"s3://{s3_bucket_public.name}/test.parquet"
s3so = {
"client_kwargs": {
"endpoint_url": s3_public_bucket.meta.client.meta.endpoint_url
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url
}
}
df1.to_parquet(
Expand Down
31 changes: 23 additions & 8 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,34 +809,44 @@ def test_categorical(self, pa):
check_round_trip(df, pa)

@pytest.mark.single_cpu
def test_s3_roundtrip_explicit_fs(self, df_compat, s3_public_bucket, pa, s3so):
def test_s3_roundtrip_explicit_fs(self, df_compat, s3_bucket_public, pa):
s3fs = pytest.importorskip("s3fs")
s3so = {
"client_kwargs": {
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url,
}
}
s3 = s3fs.S3FileSystem(**s3so)
kw = {"filesystem": s3}
check_round_trip(
df_compat,
pa,
path=f"{s3_public_bucket.name}/pyarrow.parquet",
path=f"{s3_bucket_public.name}/pyarrow.parquet",
read_kwargs=kw,
write_kwargs=kw,
)

@pytest.mark.single_cpu
def test_s3_roundtrip(self, df_compat, s3_public_bucket, pa, s3so):
def test_s3_roundtrip(self, df_compat, s3_bucket_public, pa):
# GH #19134
s3so = {
"client_kwargs": {
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url,
}
}
s3so = {"storage_options": s3so}
check_round_trip(
df_compat,
pa,
path=f"s3://{s3_public_bucket.name}/pyarrow.parquet",
path=f"s3://{s3_bucket_public.name}/pyarrow.parquet",
read_kwargs=s3so,
write_kwargs=s3so,
)

@pytest.mark.single_cpu
@pytest.mark.parametrize("partition_col", [["A"], []])
def test_s3_roundtrip_for_dir(
self, df_compat, s3_public_bucket, pa, partition_col, s3so
self, df_compat, s3_bucket_public, pa, partition_col, s3so
):
pytest.importorskip("s3fs")
# GH #26388
Expand All @@ -855,7 +865,7 @@ def test_s3_roundtrip_for_dir(
df_compat,
pa,
expected=expected_df,
path=f"s3://{s3_public_bucket.name}/parquet_dir",
path=f"s3://{s3_bucket_public.name}/parquet_dir",
read_kwargs={"storage_options": s3so},
write_kwargs={
"partition_cols": partition_col,
Expand Down Expand Up @@ -1306,12 +1316,17 @@ def test_filter_row_groups(self, fp):
assert len(result) == 1

@pytest.mark.single_cpu
def test_s3_roundtrip(self, df_compat, s3_public_bucket, fp, s3so):
def test_s3_roundtrip(self, df_compat, s3_bucket_public, fp):
# GH #19134
s3so = {
"client_kwargs": {
"endpoint_url": s3_bucket_public.meta.client.meta.endpoint_url,
}
}
check_round_trip(
df_compat,
fp,
path=f"s3://{s3_public_bucket.name}/fastparquet.parquet",
path=f"s3://{s3_bucket_public.name}/fastparquet.parquet",
read_kwargs={"storage_options": s3so},
write_kwargs={"compression": None, "storage_options": s3so},
)
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/xml/test_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,14 +1355,14 @@ def test_unsuported_compression(parser, geom_df):


@pytest.mark.single_cpu
def test_s3_permission_output(parser, s3_public_bucket, geom_df):
def test_s3_permission_output(parser, s3_bucket_public, geom_df):
s3fs = pytest.importorskip("s3fs")
pytest.importorskip("lxml")

with tm.external_error_raised((PermissionError, FileNotFoundError)):
fs = s3fs.S3FileSystem(anon=True)
fs.ls(s3_public_bucket.name)
fs.ls(s3_bucket_public.name)

geom_df.to_xml(
f"s3://{s3_public_bucket.name}/geom.xml", compression="zip", parser=parser
f"s3://{s3_bucket_public.name}/geom.xml", compression="zip", parser=parser
)
Loading
0