This would be best encapsulated as a context manager actually, so that we can write it simply as

with boost.python.trapping(division_by_zero=False):
   <here you make the call to the library that has issues with NaN and Inf>

I have just committed the code making it possible to use that terser syntax. In your case, again, you want instead to pass overflow=False and invalid=False to which you can still add division_by_zero=False just in case future versions of pyyaml cause problem with that too!

Best wishes,

Luc