Skip to content

systematic treatment of floating point warnings from numpy #482

@sergpolly

Description

@sergpolly

it would be worth considering a systematic treatment of floating-point related warnings - division by zero and invalid operation pollute output too much - esp whenever obs/exp is involved - classification of float-point errors https://docs.oracle.com/cd/E19957-01/806-3568/ncg_handle.html

  1. consider using (on a per module basis ... or in __init__ or wherever)
# set new err-stated, to hide division by zero warnings
_err_state = np.seterr(divide="ignore", over="raise", under="warn", invalid="ignore")
  1. or use a conext manager https://numpy.org/devdocs/reference/generated/numpy.errstate.html for every obs/exp (and other relevant operations) - not sure if there is a big performance penalty associated with it ...
with np.errstate(divide="ignore", invalid="ignore"):
    snippet / e
  1. or use np.dividehttps://numpy.org/doc/stable/reference/generated/numpy.divide.html with the where filter engaged - to pre-emptively fill those anything/0.0 with np.nan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions