diff --git a/fmtr/tools/datatype_tools.py b/fmtr/tools/datatype_tools.py index 90152f6..230599d 100644 --- a/fmtr/tools/datatype_tools.py +++ b/fmtr/tools/datatype_tools.py @@ -51,5 +51,36 @@ def to_bool(raw: Any, default=None) -> bool: return default +def is_nan(value: Any) -> bool: + """ + + Import-tolerant test if nan + + """ + try: + import pandas as pd + return pd.isna(value) + except ImportError: + return False + def is_none(value: Any) -> bool: + """ + + Test if none - or nan + + """ + if is_nan(value): + return True + return value is None + + +def none_else(value: Any, default: Any) -> Any: + """ + + Ternary "if none else" function + + """ + if is_none(value): + return default + return value diff --git a/fmtr/tools/version b/fmtr/tools/version index e4c0d46..a6a3a43 100644 --- a/fmtr/tools/version +++ b/fmtr/tools/version @@ -1 +1 @@ -1.0.3 \ No newline at end of file +1.0.4 \ No newline at end of file