Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
77 changes: 50 additions & 27 deletions examples/notebooks/robust_workflow.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/expected/linear_transient_to_plateau.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flux,metadata
"{'mean': 4.953589400293961, 'mean_uncertainty': 0.0033180530700721244, 'confidence_interval': (4.94708601627662, 4.960092784311302), 'pm_std': (4.950271347223889, 4.956907453364033), 'effective_sample_size': 897, 'window_size': 5, 'sss_start': np.float64(104.0), 'metadata': {'status': 'Regular', 'mitigation': 'None'}, 'start_time': 0.0}","[{'operation': 'effective_sample_size', 'options': {'column_names': 'flux', 'alpha': 0.05}}, {'operation': 'compute_statistics', 'options': {'column_name': 'flux', 'ddof': 1, 'method': 'non-overlapping', 'window_size': None}}]"
2 changes: 2 additions & 0 deletions tests/output/linear_transient_to_plateau.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flux,metadata
"{'mean': 4.953589400293961, 'mean_uncertainty': 0.0033180530700721244, 'confidence_interval': (4.94708601627662, 4.960092784311302), 'pm_std': (4.950271347223889, 4.956907453364033), 'effective_sample_size': 897, 'window_size': 5, 'sss_start': np.float64(104.0), 'metadata': {'status': 'Regular', 'mitigation': 'None'}, 'start_time': 0.0}","[{'operation': 'effective_sample_size', 'options': {'column_names': 'flux', 'alpha': 0.05}}, {'operation': 'compute_statistics', 'options': {'column_name': 'flux', 'ddof': 1, 'method': 'non-overlapping', 'window_size': None}}]"
53 changes: 50 additions & 3 deletions tests/test_robust_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,63 @@
import warnings
from pathlib import Path

import nbformat
import pandas as pd
import pandas.testing as pdt
import papermill as pm

os.chdir("examples/notebooks")


def test_linear_transient_to_plateau():
# Suppress warnings from Papermill
warnings.filterwarnings(
"ignore", category=UserWarning, module="papermill.translators"
)

# Define notebook paths
input_nb = Path("robust_workflow.ipynb")

# Create a temporary directory for the executed notebook
with tempfile.TemporaryDirectory() as tmpdirname:
output_nb = Path(tmpdirname) / "executed_notebook.ipynb"

# Execute the notebook with Papermill
pm.execute_notebook(str(input_nb), str(output_nb), kernel_name="python3")

# Verify the notebook file itself exists
assert output_nb.exists(), f"Executed notebook was not created at {output_nb}"

executed_nb = nbformat.read(output_nb, as_version=4)
assert (
"papermill" in executed_nb.metadata
), "Notebook metadata missing Papermill info."
assert any(
cell.get("execution_count") for cell in executed_nb.cells
), "No cells executed."

print("Papermill execution verified successfully.")

# Load the newly generated stats CSV from the notebook
current_csv_path = Path("../../tests/output/linear_transient_to_plateau.csv")
if not current_csv_path.exists():
raise ValueError(f"Output CSV not found at {current_csv_path}")

current = pd.read_csv(current_csv_path)

# Load the expected baseline CSV
expected_csv_path = Path("../../tests/expected/linear_transient_to_plateau.csv")
if not expected_csv_path.exists():
raise ValueError(f"Expected CSV not found at {expected_csv_path}")

expected = pd.read_csv(expected_csv_path)

# Compare the two DataFrames
pdt.assert_frame_equal(current, expected, atol=1e-8, check_dtype=False)

print("Regression test passed: current results match expected baseline.")


def test_slope_to_sine_regression():
"""
Runs the Robust Workflow notebook, generates output stats CSV,
Expand All @@ -33,9 +83,6 @@ def test_slope_to_sine_regression():
# Verify the notebook file itself exists
assert output_nb.exists(), f"Executed notebook was not created at {output_nb}"

# Load and verify Papermill metadata
import nbformat

executed_nb = nbformat.read(output_nb, as_version=4)
assert (
"papermill" in executed_nb.metadata
Expand Down