def clean_series(series, *args, **kwargs):
if not series.dtype == np.dtype('<STR_LIT:O>'):<EOL><INDENT>return series<EOL><DEDENT>if any_generated((isinstance(v, datetime.datetime) for v in series)):<EOL><INDENT>series = series.apply(clip_datetime)<EOL><DEDENT>if any_generated((isinstance(v, basestring) for v in series)):<EOL><INDENT>series = series.apply(encode)<EOL><DEDENT>series = series.apply(try_float_int)<EOL>return series<EOL>
Ensure all datetimes are valid Timestamp objects and dtype is np.datetime64[ns]
    >>> from datetime import timedelta
    >>> clean_series(pd.Series([datetime.datetime(1, 1, 1), 9, '1942', datetime.datetime(1970, 10, 23)]))
    0    1677-09-22 00:12:44+00:00
    1                            9
    2                         1942
    3    1970-10-23 00:00:00+00:00
    dtype: object
    >>> clean_series(pd.Series([datetime.datetime(1, 1, 1), datetime.datetime(3000, 10, 23)]))
    0             1677-09-22 00:12:44+00:00
    1   2262-04-11 23:47:16.854775+00:00
    dtype: datetime64[ns, UTC]