Accepts a string, Pandas Timestamp, or long, and returns nanos since the epoch.

def datetime_to_nanos(dt):
    """
    Accepts a string, Pandas Timestamp, or long, and returns nanos since the epoch.
    """
    if isinstance(dt, pd.Timestamp):
        return dt.value
    elif isinstance(dt, str):
        return pd.Timestamp(dt).value
    elif isinstance(dt, long):
        return dt
    elif isinstance(dt, datetime):
	return long(dt.strftime("%s%f")) * 1000

    raise ValueError