Nully

PHOTO EMBED

Fri Apr 29 2022 12:18:01 GMT+0000 (UTC)

Saved by @cicada #python #null

import math
import numpy as np
import pandas as pd

def nully(obj: any) -> bool:
    """Checks for all kinds of NaN, NaT and None
    Args:
        obj[any]: Object to check
    Returns:
        bool: True if obj is nully
    """
    conditions: List[bool] = [
      obj is None, # python None
      obj is np.nan, # numpy NaN
      obj is pd.nan, # pandas NA,
      obj is pd.NaT # pandas NaT
    ]
    try:
        conditions.append(math.isnan(obj)) # python NaN
    except TypeError: # not a number type
        pass
    if any(conditions):
        return True
    return False
content_copyCOPY