Skip to content

[thermo] Throw IndexError for invalid species index#949

Merged
speth merged 1 commit into
Cantera:mainfrom
ischoegl:species-index-error
Jan 18, 2021
Merged

[thermo] Throw IndexError for invalid species index#949
speth merged 1 commit into
Cantera:mainfrom
ischoegl:species-index-error

Conversation

@ischoegl
Copy link
Copy Markdown
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
Copy Markdown

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.

@ischoegl ischoegl force-pushed the species-index-error branch from f0cc35b to 4b695c1 Compare December 8, 2020 14:29
@ischoegl ischoegl force-pushed the species-index-error branch from 4b695c1 to fe7789f Compare December 11, 2020 03:01
@ischoegl ischoegl mentioned this pull request Dec 11, 2020
4 tasks
Copy link
Copy Markdown
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