Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[thermo] Throw IndexError for invalid species index #949

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Dec 8, 2020

Changes proposed in this pull request

  • raise IndexError for invalid species
  • use existing checkSpeciesIndex method
In [1]: import cantera as ct
   ...: gas = ct.Solution('gri30.yaml')
   ...: 

In [2]: gas.species(53)
---------------------------------------------------------------------------
CanteraError                              Traceback (most recent call last)
<ipython-input-2-1d8e247355bb> in <module>()
----> 1 gas.species(53)

/src/interfaces/cython/cantera/thermo.pyx in cantera._cantera.ThermoPhase.species()
    592             s._assign(self.thermo.species(stringify(k)))
    593         elif isinstance(k, (int, float)):
--> 594             s._assign(self.thermo.species(<int>k))
    595         else:
    596             raise TypeError("Argument must be a string or a number."

CanteraError: 
***********************************************************************
IndexError thrown by Phase::checkSpeciesIndex:
IndexError: species[53] outside valid range of 0 to 52.
***********************************************************************

If applicable, fill in the issue number this pull request is fixing

Fixes #948

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

@codecov
Copy link

codecov bot commented Dec 8, 2020

Codecov Report

Merging #949 (fe7789f) into main (d8e62ad) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #949   +/-   ##
=======================================
  Coverage   71.22%   71.22%           
=======================================
  Files         377      377           
  Lines       46272    46273    +1     
=======================================
+ Hits        32955    32957    +2     
+ Misses      13317    13316    -1     
Impacted Files Coverage Δ
src/thermo/Phase.cpp 82.84% <100.00%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8e62ad...fe7789f. Read the comment docs.

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Seems simple enough to me.

@speth speth merged commit 17b70eb into Cantera:main Jan 18, 2021
@ischoegl ischoegl deleted the species-index-error branch January 29, 2021 18:48
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.

Python crashes when using species function with large index
2 participants