Created
February 17, 2019 13:08
-
-
Save bicycle1885/94485f68e2aed9961a777dc29eee4989 to your computer and use it in GitHub Desktop.
safenan.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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