From ae231d980b6e4967256a45a6f5db87615dc34f13 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 23 Nov 2026 03:07:02 +0000 Subject: [PATCH 1/4] ENH: warn when a drag CSV does not form a regular grid Fall back from regular-grid interpolation still loads the table, but now emits a UserWarning so a missing combination, duplicate row, or split float does not silently change drag between tabulated points. Co-authored-by: Charles --- rocketpy/rocket/rocket.py | 7 +++++ tests/unit/rocket/test_rocket.py | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 75369af50..b28592cb6 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -2612,6 +2612,13 @@ def mach_wrapper( extrapolation="constant", ) if csv_func is None: + warnings.warn( + f"{coeff_name} CSV does not form a full regular grid; " + "using scattered interpolation. Drag coefficient values may " + "differ both between and outside the tabulated points.", + UserWarning, + stacklevel=2, + ) csv_func = Function( file_path, interpolation="linear", diff --git a/tests/unit/rocket/test_rocket.py b/tests/unit/rocket/test_rocket.py index b713226a6..6af1d0b82 100644 --- a/tests/unit/rocket/test_rocket.py +++ b/tests/unit/rocket/test_rocket.py @@ -887,6 +887,50 @@ def test_drag_csv_header_order_independent_for_multivariable_input(tmp_path): assert swapped_csv_function.get_interpolation_method() == "regular_grid" +def test_load_rocket_drag_csv_missing_combination_warns_and_uses_scattered_interpolation( + tmp_path, +): + """Non-grid drag CSVs must warn and still load with scattered interpolation. + + A multi-variable CSV missing one input combination cannot form a regular + grid, so ``Rocket.__load_rocket_drag_csv`` falls back to interpolating + scattered points. The rocket must still construct and evaluate the table. + """ + irregular_csv = tmp_path / "drag_missing_combination.csv" + irregular_csv.write_text( + "alpha,mach,cd\n0.0,0.5,0.30\n0.0,1.0,0.45\n0.1,0.5,0.32\n", + encoding="utf-8", + ) + + with pytest.warns( + UserWarning, + match="does not form a full regular grid.*scattered interpolation", + ): + rocket = Rocket( + radius=0.05, + mass=1.0, + inertia=(1.0, 1.0, 1.0), + power_off_drag=str(irregular_csv), + power_on_drag=0.3, + center_of_mass_without_motor=0.0, + ) + + closure = rocket.power_off_drag_7d.source.__closure__ + csv_function = next( + cell.cell_contents + for cell in closure + if isinstance(cell.cell_contents, Function) + ) + + assert csv_function.get_interpolation_method() != "regular_grid" + assert rocket.power_off_drag_7d(0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0) == pytest.approx( + 0.30 + ) + assert rocket.power_off_drag_7d(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0) == pytest.approx( + 0.45 + ) + + def test_drag_input_types_supported_for_power_on_and_power_off(tmp_path): """Ensure drag input processing accepts all supported input types. From a79a93134e1e9ef0584d0660bd1502de52289a2d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 24 Nov 2026 02:21:25 +0000 Subject: [PATCH 2/4] DOC: say RocketPy warns on irregular drag CSVs PR #1232 documented that a non-grid table still loads and no warning is given. This branch now warns, so the note matches that behavior. Co-authored-by: Charles --- docs/user/rocket/rocket_usage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/user/rocket/rocket_usage.rst b/docs/user/rocket/rocket_usage.rst index efaccfb96..3adf35fe6 100644 --- a/docs/user/rocket/rocket_usage.rst +++ b/docs/user/rocket/rocket_usage.rst @@ -165,9 +165,9 @@ defines drag as a function of angle of attack and Mach number: Fill in every combination of the values in the table, and write each value the same way in every row. If a combination is missing, a row is repeated or a value differs in any digit (0.3 and 0.30000000000000004), the file - still loads and no warning is given, but RocketPy interpolates between - scattered points instead of along the grid, and the drag coefficient - changes both between and outside the points. + still loads, but RocketPy warns and interpolates between scattered points + instead of along the grid, and the drag coefficient changes both between + and outside the points. For backward compatibility, ``rocket.power_off_drag`` and ``rocket.power_on_drag`` expose the Mach-only slice of each model, with the From 7938818ab131eaff1cf7bf5d8495da4146454dad Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 24 Nov 2026 02:21:25 +0000 Subject: [PATCH 3/4] ENH: point the irregular drag CSV warning at Rocket() Raise stacklevel from 2 to 4 so the warning names the caller's Rocket(...) line, and include the drag file path in the message. Co-authored-by: Charles --- rocketpy/rocket/rocket.py | 8 ++++---- tests/unit/rocket/test_rocket.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index b28592cb6..a7e790813 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -2613,11 +2613,11 @@ def mach_wrapper( ) if csv_func is None: warnings.warn( - f"{coeff_name} CSV does not form a full regular grid; " - "using scattered interpolation. Drag coefficient values may " - "differ both between and outside the tabulated points.", + f"{coeff_name} CSV {file_path!r} does not form a full regular " + "grid; using scattered interpolation. Drag coefficient values " + "may differ both between and outside the tabulated points.", UserWarning, - stacklevel=2, + stacklevel=4, ) csv_func = Function( file_path, diff --git a/tests/unit/rocket/test_rocket.py b/tests/unit/rocket/test_rocket.py index 6af1d0b82..2c80e49c7 100644 --- a/tests/unit/rocket/test_rocket.py +++ b/tests/unit/rocket/test_rocket.py @@ -894,7 +894,9 @@ def test_load_rocket_drag_csv_missing_combination_warns_and_uses_scattered_inter A multi-variable CSV missing one input combination cannot form a regular grid, so ``Rocket.__load_rocket_drag_csv`` falls back to interpolating - scattered points. The rocket must still construct and evaluate the table. + scattered points. The warning names the drag file and points at the + caller's ``Rocket(...)`` line. The rocket must still construct and + evaluate the table. """ irregular_csv = tmp_path / "drag_missing_combination.csv" irregular_csv.write_text( @@ -905,7 +907,7 @@ def test_load_rocket_drag_csv_missing_combination_warns_and_uses_scattered_inter with pytest.warns( UserWarning, match="does not form a full regular grid.*scattered interpolation", - ): + ) as caught: rocket = Rocket( radius=0.05, mass=1.0, @@ -915,6 +917,10 @@ def test_load_rocket_drag_csv_missing_combination_warns_and_uses_scattered_inter center_of_mass_without_motor=0.0, ) + warning = caught[0] + assert warning.filename == __file__ + assert str(irregular_csv) in str(warning.message) + closure = rocket.power_off_drag_7d.source.__closure__ csv_function = next( cell.cell_contents From c4365a60eabfe7a353be60bab556afbd8673eaba Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 25 Nov 2026 03:01:35 +0000 Subject: [PATCH 4/4] fix(tests): platform-safe drag CSV warning path assertion for Windows CI Rocket warns with file_path!r, so backslashes differ from str(Path) on Windows. Check filename plus native or repr path in the warning message. Unblocks PR 1239. Co-authored-by: Charles --- tests/unit/rocket/test_rocket.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/rocket/test_rocket.py b/tests/unit/rocket/test_rocket.py index 2c80e49c7..b14d086e3 100644 --- a/tests/unit/rocket/test_rocket.py +++ b/tests/unit/rocket/test_rocket.py @@ -919,7 +919,10 @@ def test_load_rocket_drag_csv_missing_combination_warns_and_uses_scattered_inter warning = caught[0] assert warning.filename == __file__ - assert str(irregular_csv) in str(warning.message) + warning_text = str(warning.message) + assert irregular_csv.name in warning_text + path_str = str(irregular_csv) + assert path_str in warning_text or repr(path_str) in warning_text closure = rocket.power_off_drag_7d.source.__closure__ csv_function = next(