Skip to content

Fix: handle np.nan#417

Merged
rkingsbury merged 3 commits into
KingsburyLab:mainfrom
SuixiongTay:shaun/get_ppm
May 29, 2026
Merged

Fix: handle np.nan#417
rkingsbury merged 3 commits into
KingsburyLab:mainfrom
SuixiongTay:shaun/get_ppm

Conversation

@SuixiongTay
Copy link
Copy Markdown
Collaborator

Summary

This PR addresses a small edge case, exemplified by the input below:

s1.add_amount("Mg+2", f"{np.nan} mg/L")

Output:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[16], line 1
----> 1 s1.add_amount("Mg+2", f"{np.nan} mg/L")

File ~/miniforge3/envs/feynman/code/pyEQL/src/pyEQL/solution.py:1433, in Solution.add_amount(self, solute, amount)
   1415 def add_amount(self, solute: str, amount: str):
   1416     """
   1417     Add the amount of 'solute' to the parent solution.
   1418
   (...)
   1431         Nothing. The concentration of solute is modified.
   1432     """
-> 1433     Q = ureg.Quantity(*_translate_pint_quantity(amount))
   1434     # Get the current amount of the solute
   1435     current_amt = self.get_amount(solute, amount.split(" ")[1])

File ~/miniforge3/envs/feynman/code/pyEQL/src/pyEQL/utils.py:57, in _translate_pint_quantity(amount)
     54     return amount.magnitude, str(amount.units)
     56 match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount)
---> 57 _value, _unit = match.groups()
     58 unit = translate_units(_unit)
     59 return (float(_value), unit)

AttributeError: 'NoneType' object has no attribute 'groups'

@SuixiongTay
Copy link
Copy Markdown
Collaborator Author

This should address #395 CI's issue.

@SuixiongTay SuixiongTay marked this pull request as draft May 29, 2026 18:09
@SuixiongTay SuixiongTay changed the title Fix: handle np.nan WIP - Fix: handle np.nan May 29, 2026
@SuixiongTay SuixiongTay marked this pull request as ready for review May 29, 2026 18:23
@SuixiongTay SuixiongTay changed the title WIP - Fix: handle np.nan Fix: handle np.nan May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.26%. Comparing base (6a2279c) to head (a929b5e).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
src/pyEQL/utils.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #417      +/-   ##
==========================================
- Coverage   86.32%   86.26%   -0.07%     
==========================================
  Files          14       14              
  Lines        1865     1871       +6     
  Branches      328      326       -2     
==========================================
+ Hits         1610     1614       +4     
- Misses        209      210       +1     
- Partials       46       47       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rkingsbury rkingsbury added the fix Bug Fixes label May 29, 2026
@rkingsbury
Copy link
Copy Markdown
Member

Thank you @SuixiongTay

@rkingsbury rkingsbury merged commit e8715d4 into KingsburyLab:main May 29, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants