Is there a Numpy or Pandas setting to issue a warning whenever a NaN value is created

Viewed 515

I'm spending a lot of time working with Pandas, which uses numpy arrays to store numbers.

In my use-case, there should never be any NaN values - they are indicative that something has gone wrong (usually a Pandas-related screwup such as incorrectly joined dataframes, badly loaded data, etc)

It would be helpful if Pandas or Numpy had a setting that would immediately issue a warning if a NaN value appeared in any series in a dataframe. (This question is not about NaN replacement or imputation. Just warnings.)

Yes, one could write lots of local checks at each stage (do this thing. Now check whether you created NaNs. Do this other thing. Check again whether you created NaNs etc), but that's horribly verbose and inefficient. What I want to tell pandas is if you ever put a NaN value in a dataframe, immediately issue a warning - once, as a global setting at the top of my jupyter notebook.

Does anyone know whether a global setting to do this exists?

1 Answers
Related