Skip to content

Instantly share code, notes, and snippets.

@bicycle1885
Created February 17, 2019 13:08
Show Gist options
  • Save bicycle1885/94485f68e2aed9961a777dc29eee4989 to your computer and use it in GitHub Desktop.
Save bicycle1885/94485f68e2aed9961a777dc29eee4989 to your computer and use it in GitHub Desktop.
safenan.py
import types
class SafeNaN(types.ModuleType):
def __setattr__(self, attr, value):
if attr == "nan":
raise RuntimeError("cannot reassign 'nan'")
super().__setattr__(attr, value)
import sys
import numpy
sys.modules["numpy"].__class__ = SafeNaN
numpy.nan = 1 # ERROR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment