Skip to content

Fix CSA_motor_efficiency UnboundLocalError for unsupported pole counts - #98

Merged
CalebBell merged 3 commits into
CalebBell:masterfrom
yuhuavit-hash:fix-csa-motor-efficiency-poles
Sep 15, 2026
Merged

CalebBell merged 3 commits into
CalebBell:masterfrom
yuhuavit-hash:fix-csa-motor-efficiency-poles

Conversation

@yuhuavit-hash

Copy link
Copy Markdown
Contributor

CSA_motor_efficiency raises an UnboundLocalError (instead of a clear error) when the requested pole count has no standard table: 8-pole motors have no high-efficiency values, and pole counts other than 2/4/6/8 are not in any table.

>>> from fluids.pump import CSA_motor_efficiency
>>> from fluids.constants import hp
>>> CSA_motor_efficiency(100*hp, poles=8, high_efficiency=True)
UnboundLocalError: cannot access local variable 'efficiency'

This adds input validation up front, raising a ValueError with a clear message for unsupported pole counts (matching the style of current_ideal's phase validation), and documents the supported pole counts in the docstring.

Changes

  • fluids/pump.py: validate poles before table lookup
  • tests/test_pump.py: add boundary cases (poles=8 + high_efficiency, poles=3)

Verification

  • python -m pytest tests/test_pump.py — 12 passed
  • python -m pytest -m "not slow" — 1764 passed

@CalebBell CalebBell left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! One bit of feedback.

Comment thread fluids/pump.py Outdated
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence makes it sound like the low-standard efficiency table doesn't have 2, 4, or 6 pole motors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've reworded the note in the latest commit to make clear that the minimum efficiency standard also covers 2, 4, and 6 pole motors.

@CalebBell

Copy link
Copy Markdown
Owner

Thank you! This will be in the next release

@CalebBell
CalebBell merged commit 652a013 into CalebBell:master Sep 15, 2026
57 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants