From 137184c6c2f10094817b625930e5c169485c3e81 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 29 Sep 2025 10:50:08 -0700 Subject: [PATCH 1/2] TST: Avoid time.sleep in tests --- pandas/tests/io/excel/test_style.py | 17 ++++------------- pandas/tests/io/json/test_pandas.py | 13 ++++--------- pandas/tests/io/pytables/test_store.py | 2 +- pandas/tests/io/test_compression.py | 3 --- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pandas/tests/io/excel/test_style.py b/pandas/tests/io/excel/test_style.py index 8c70e5eed3c97..12f14589365ff 100644 --- a/pandas/tests/io/excel/test_style.py +++ b/pandas/tests/io/excel/test_style.py @@ -1,5 +1,4 @@ import contextlib -import time import uuid import numpy as np @@ -324,18 +323,10 @@ def test_styler_to_s3(s3_bucket_public, s3so): target_file = f"{uuid.uuid4()}.xlsx" df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]}) styler = df.style.set_sticky(axis="index") - styler.to_excel(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so) - timeout = 5 - while True: - if target_file in (obj.key for obj in s3_bucket_public.objects.all()): - break - time.sleep(0.1) - timeout -= 0.1 - assert timeout > 0, "Timed out waiting for file to appear on moto" - result = read_excel( - f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so - ) - tm.assert_frame_equal(result, df) + uri = f"s3://{mock_bucket_name}/{target_file}" + styler.to_excel(uri, storage_options=s3so) + result = read_excel(uri, index_col=0, storage_options=s3so) + tm.assert_frame_equal(result, df) @pytest.mark.parametrize("merge_cells", [True, False, "columns"]) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 9c47fcaf3375c..2aa1e9fd9ac3b 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -7,7 +7,6 @@ import json import os import sys -import time import uuid import numpy as np @@ -2019,14 +2018,10 @@ def test_to_s3(self, s3_bucket_public, s3so): mock_bucket_name = s3_bucket_public.name target_file = f"{uuid.uuid4()}.json" df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]}) - df.to_json(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so) - timeout = 5 - while True: - if target_file in (obj.key for obj in s3_bucket_public.objects.all()): - break - time.sleep(0.1) - timeout -= 0.1 - assert timeout > 0, "Timed out waiting for file to appear on moto" + uri = f"s3://{mock_bucket_name}/{target_file}" + df.to_json(uri, storage_options=s3so) + result = read_json(uri, storage_options=s3so) + tm.assert_frame_equal(result, df) def test_json_pandas_nulls(self, nulls_fixture): # GH 31615 diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 5cfefeb469e8a..0ce04082d5361 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -90,7 +90,7 @@ def create_h5_and_return_checksum(tmp_path, track_times): checksum_0_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True) # sleep is necessary to create h5 with different creation time - time.sleep(1) + time.sleep(0.5) checksum_1_tt_false = create_h5_and_return_checksum(tmp_path, track_times=False) checksum_1_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True) diff --git a/pandas/tests/io/test_compression.py b/pandas/tests/io/test_compression.py index fd1e9b4fdf211..7cec570389fd3 100644 --- a/pandas/tests/io/test_compression.py +++ b/pandas/tests/io/test_compression.py @@ -6,7 +6,6 @@ import sys import tarfile import textwrap -import time import zipfile import numpy as np @@ -186,7 +185,6 @@ def test_gzip_reproducibility_file_name(): with tm.ensure_clean() as path: path = Path(path) df.to_csv(path, compression=compression_options) - time.sleep(0.1) output = path.read_bytes() df.to_csv(path, compression=compression_options) assert output == path.read_bytes() @@ -209,7 +207,6 @@ def test_gzip_reproducibility_file_object(): buffer = io.BytesIO() df.to_csv(buffer, compression=compression_options, mode="wb") output = buffer.getvalue() - time.sleep(0.1) buffer = io.BytesIO() df.to_csv(buffer, compression=compression_options, mode="wb") assert output == buffer.getvalue() From b2f48390cf039fb08183440b92169e79e923f924 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 29 Sep 2025 14:16:00 -0700 Subject: [PATCH 2/2] Bump back to 1 --- pandas/tests/io/pytables/test_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 0ce04082d5361..5cfefeb469e8a 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -90,7 +90,7 @@ def create_h5_and_return_checksum(tmp_path, track_times): checksum_0_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True) # sleep is necessary to create h5 with different creation time - time.sleep(0.5) + time.sleep(1) checksum_1_tt_false = create_h5_and_return_checksum(tmp_path, track_times=False) checksum_1_tt_true = create_h5_and_return_checksum(tmp_path, track_times=True)