From 274c7f43ea06a7fe1f21e7a372d15042a3535c83 Mon Sep 17 00:00:00 2001 From: yuhuavit-hash <282928525+yuhuavit-hash@users.noreply.github.com> Date: Wed, 9 Sep 2026 13:01:05 +0800 Subject: [PATCH 1/2] Fix CSA_motor_efficiency UnboundLocalError for unsupported pole counts --- fluids/pump.py | 9 +++++++++ tests/test_pump.py | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/fluids/pump.py b/fluids/pump.py index d3a4134e..f3285cc5 100644 --- a/fluids/pump.py +++ b/fluids/pump.py @@ -375,6 +375,10 @@ def CSA_motor_efficiency(P: float, closed: bool=False, poles: int=2, high_effici Several low-efficiency standard high power values were added to allow for easy programming; values are the last listed efficiency in the table. + Only 2, 4, and 6 pole motors have high-efficiency standard values; 8 pole + values are available for the minimum efficiency standard only. A + ValueError is raised for unsupported pole counts. + Examples -------- >>> CSA_motor_efficiency(100*hp) @@ -388,6 +392,11 @@ def CSA_motor_efficiency(P: float, closed: bool=False, poles: int=2, high_effici 375 kW). As modified 2015-12-17. https://www.nrcan.gc.ca/energy/regulations-codes-standards/products/6885 """ + if high_efficiency: + if poles not in (2, 4, 6): + raise ValueError("Only 2, 4, and 6 pole motors have high-efficiency standard values") + elif poles not in (2, 4, 6, 8): + raise ValueError("Only 2, 4, 6, and 8 pole motors have standard efficiency values") P = P/hp # This could be replaced by a dict and a jump list if high_efficiency: diff --git a/tests/test_pump.py b/tests/test_pump.py index cac96029..7583fa18 100644 --- a/tests/test_pump.py +++ b/tests/test_pump.py @@ -92,6 +92,11 @@ def test_CSA_motor_efficiency(): nema_min_Ps = [0.755, 0.825, 0.84, 0.855, 0.855, 0.875, 0.875, 0.885, 0.895, 0.902, 0.902, 0.91, 0.91, 0.917, 0.924, 0.93, 0.93, 0.936, 0.945, 0.945, 0.95, 0.95, 0.954, 0.954, 0.954, 0.954, 0.954, 0.954, 0.825, 0.84, 0.84, 0.875, 0.875, 0.875, 0.875, 0.895, 0.895, 0.91, 0.91, 0.924, 0.924, 0.93, 0.93, 0.936, 0.941, 0.945, 0.945, 0.95, 0.95, 0.95, 0.95, 0.954, 0.954, 0.954, 0.954, 0.958, 0.8, 0.855, 0.865, 0.875, 0.875, 0.875, 0.875, 0.895, 0.895, 0.902, 0.902, 0.917, 0.917, 0.93, 0.93, 0.936, 0.936, 0.941, 0.941, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.95, 0.74, 0.77, 0.825, 0.84, 0.84, 0.855, 0.855, 0.855, 0.885, 0.885, 0.895, 0.895, 0.91, 0.91, 0.917, 0.917, 0.93, 0.93, 0.936, 0.936, 0.941, 0.941, 0.945, 0.945, 0.945, 0.945, 0.945, 0.945, 0.755, 0.825, 0.84, 0.84, 0.84, 0.855, 0.855, 0.875, 0.885, 0.895, 0.902, 0.91, 0.91, 0.917, 0.924, 0.93, 0.93, 0.93, 0.936, 0.936, 0.945, 0.945, 0.945, 0.95, 0.95, 0.954, 0.958, 0.958, 0.825, 0.84, 0.84, 0.865, 0.865, 0.875, 0.875, 0.885, 0.895, 0.91, 0.91, 0.917, 0.924, 0.93, 0.93, 0.936, 0.941, 0.941, 0.945, 0.95, 0.95, 0.95, 0.954, 0.954, 0.954, 0.954, 0.958, 0.958, 0.8, 0.84, 0.855, 0.865, 0.865, 0.875, 0.875, 0.885, 0.902, 0.902, 0.91, 0.917, 0.924, 0.93, 0.93, 0.936, 0.936, 0.941, 0.941, 0.945, 0.945, 0.945, 0.954, 0.954, 0.954, 0.954, 0.954, 0.954, 0.74, 0.755, 0.855, 0.865, 0.865, 0.875, 0.875, 0.885, 0.895, 0.895, 0.902, 0.902, 0.91, 0.91, 0.917, 0.924, 0.936, 0.936, 0.936, 0.936, 0.936, 0.936, 0.945, 0.945, 0.945, 0.945, 0.945, 0.945] assert_close1d(nema_min_P_calcs, nema_min_Ps) + with pytest.raises(Exception): + CSA_motor_efficiency(100*hp, poles=8, high_efficiency=True) + with pytest.raises(Exception): + CSA_motor_efficiency(100*hp, poles=3) + def test_motor_efficiency_underloaded(): full_efficiencies = [motor_efficiency_underloaded(P*hp, .99) for P in (0.5, 2.5, 7, 12, 42, 90)] assert_close1d(full_efficiencies, [1, 1, 1, 1, 1, 1]) From 302889b89f9b820ab03f1ce8920c308bc5cd6b45 Mon Sep 17 00:00:00 2001 From: yuhuavit-hash <282928525+yuhuavit-hash@users.noreply.github.com> Date: Tue, 15 Sep 2026 09:49:55 +0800 Subject: [PATCH 2/2] Reword pole coverage note in CSA_motor_efficiency docstring --- fluids/pump.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluids/pump.py b/fluids/pump.py index 64d9abca..9ce1f28a 100644 --- a/fluids/pump.py +++ b/fluids/pump.py @@ -375,8 +375,8 @@ def CSA_motor_efficiency(P: float, closed: bool=False, poles: int=2, high_effici Several low-efficiency standard high power values were added to allow for easy programming; values are the last listed efficiency in the table. - Only 2, 4, and 6 pole motors have high-efficiency standard values; 8 pole - values are available for the minimum efficiency standard only. A + The high-efficiency standard covers 2, 4, and 6 pole motors only; the + minimum efficiency standard additionally covers 8 pole motors. A ValueError is raised for unsupported pole counts. Examples