From a91126cfe4617234c89d7c7902fd6d502bc67de5 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Tue, 16 Jun 2026 15:34:14 +0200 Subject: [PATCH] test: de-flake test_heatmap_reshape irregular-data case `test_with_irregular_data` randomly dropped 30% of timestamps using the module-level `np.random` state. Under pytest-xdist the global RNG state at this test's execution depends on test ordering, so ~0.7% of runs dropped all four timestamps in the final hour, yielding 24 reshaped hours instead of 25 and failing the `== 25` assert. Use a local `np.random.default_rng(42)` and always retain the final timestamp, so the 25-hour span is deterministic regardless of test order. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/plotting/test_heatmap_reshape.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/plotting/test_heatmap_reshape.py b/tests/plotting/test_heatmap_reshape.py index 092adff4e..636731130 100644 --- a/tests/plotting/test_heatmap_reshape.py +++ b/tests/plotting/test_heatmap_reshape.py @@ -45,9 +45,12 @@ def test_weekly_daily_pattern(hourly_week_data): def test_with_irregular_data(): """Real-world use case: data with missing timestamps needs filling.""" time = pd.date_range('2024-01-01', periods=100, freq='15min') - data = np.random.rand(100) - # Randomly drop 30% to simulate real data gaps - keep = np.sort(np.random.choice(100, 70, replace=False)) # Must be sorted + # Local generator + retained endpoint: keeps the 25h span deterministic + # regardless of test order under pytest-xdist (global np.random state varies). + rng = np.random.default_rng(42) + data = rng.random(100) + # Drop 30% to simulate gaps, but keep the final timestamp so the span stays 25h + keep = np.sort(np.append(rng.choice(99, 69, replace=False), 99)) da = xr.DataArray(data[keep], dims=['time'], coords={'time': time[keep]}) result = reshape_data_for_heatmap(da, reshape_time=('h', 'min'), fill='ffill')