Fix fetch_exomol rejecting string isotopes, add CO_p to EXOMOL_MOLECULES #1047
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 66.34%. Comparing base (
3f5c86b) to head (55905d6).:warning: Report is 28 commits behind head on develop.
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## develop #1047 +/- ##
===========================================
- Coverage 70.01% 66.34% -3.68%
===========================================
Files 99 92 -7
Lines 19467 18191 -1276
===========================================
- Hits 13630 12068 -1562
- Misses 5837 6123 +286
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Fix looks good, thanks! A few small non-blocking suggestions:
1. Accepting only ints and digit strings would be shorter and catch edge cases like Decimal("1.7") or Fraction(3, 2), which currently both become 1:
if isinstance(isotope, str) and isotope.strip().isdecimal():
isotope = int(isotope)
elif isinstance(isotope, (int, np.integer)) and not isinstance(isotope, bool):
isotope = int(isotope)
else:
raise ValueError(
f"In fetch_exomol, ``isotope`` must be an integer or a digit string such as '1'. "
f"Got {isotope!r}. Only one isotope can be queried at a time."
)
2. {isotope!r} in the error shows '1' instead of 1, and the message is missing a . before "Only one isotope".
3. pytest.mark.parametrize would show which input failed.
Thanks! All three applied in 55905d6:
1. The check now accepts only ints and digit strings, so Decimal("1.7") and Fraction(3, 2) are rejected; both are added to the tests.
2. The error message uses {isotope!r} and has the missing period.
3. The tests are parametrized: test_fetch_exomol_valid_isotope (4 cases) and test_fetch_exomol_invalid_isotope (8 cases), so each input shows up separately, e.g. test_fetch_exomol_invalid_isotope[Decimal('1.7')].
LGTM
Approved these changes.
prathamhole14
IshanAhu
Description
Fixes #1045
Since 0.17,
fetch_exomolrejects its own defaultisotope="1"and any string isotope: 75456cd (#949) replaced theint(isotope)conversion with anisinstancecheck.Fix: accept only integers (
int,np.integer, but notbool) and digit strings such as"1", converted to a plainint. Anything else ("1,2","all",None,1.7,True,Decimal("1.7")) raises aValueErrorthat shows the value it got.Tests:
test_fetch_exomol_valid_isotopeandtest_fetch_exomol_invalid_isotope(fast, offline, parametrized;monkeypatchstops the call before any download). The default call,1,"1"andnp.int64(1)must reach the lookup asint1;"1,2","abc",None,1.5,1.0,True,Decimal("1.7")andFraction(3, 2)must raise. Ondevelop, the default and"1"cases fail with the error from #1045.CO_p (second commit): ExoMol added CO⁺ (
CO_p), sotest_ExoMol_molecules_listfails ondevelopand in the fast CI job. This adds it toEXOMOL_MOLECULES; ExoMol marks its CO⁺ line list as provisional.Tested on Windows: the new test,
test_ExoMol_molecules_listand CI's fast test selection pass, andpre-commit run --all-filesis clean.I used Claude code while working on this