def maybe_infer_to_datetimelike(value, convert_dates=False):
<EOL>if isinstance(value, (ABCDatetimeIndex, ABCPeriodIndex,<EOL>ABCDatetimeArray, ABCPeriodArray)):<EOL><INDENT>return value<EOL><DEDENT>elif isinstance(value, ABCSeries):<EOL><INDENT>if isinstance(value._values, ABCDatetimeIndex):<EOL><INDENT>return value._values<EOL><DEDENT><DEDENT>v = value<EOL>if not is_list_like(v):<EOL><INDENT>v = [v]<EOL><DEDENT>v = np.array(v, copy=False)<EOL>if not is_object_dtype(v):<EOL><INDENT>return value<EOL><DEDENT>shape = v.shape<EOL>if not v.ndim == <NUM_LIT:1>:<EOL><INDENT>v = v.ravel()<EOL><DEDENT>if not len(v):<EOL><INDENT>return value<EOL><DEDENT>def try_datetime(v):<EOL><INDENT>try:<EOL><INDENT>v = tslib.array_to_datetime(v,<EOL>require_iso8601=True,<EOL>errors='<STR_LIT>')[<NUM_LIT:0>]<EOL><DEDENT>except ValueError:<EOL><INDENT>try:<EOL><INDENT>from pandas._libs.tslibs import conversion<EOL>from pandas import DatetimeIndex<EOL>values, tz = conversion.datetime_to_datetime64(v)<EOL>return DatetimeIndex(values).tz_localize(<EOL>'<STR_LIT>').tz_convert(tz=tz)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>return v.reshape(shape)<EOL><DEDENT>def try_timedelta(v):<EOL><INDENT>from pandas import to_timedelta<EOL>try:<EOL><INDENT>return to_timedelta(v)._ndarray_values.reshape(shape)<EOL><DEDENT>except Exception:<EOL><INDENT>return v.reshape(shape)<EOL><DEDENT><DEDENT>inferred_type = lib.infer_datetimelike_array(ensure_object(v))<EOL>if inferred_type == '<STR_LIT:date>' and convert_dates:<EOL><INDENT>value = try_datetime(v)<EOL><DEDENT>elif inferred_type == '<STR_LIT>':<EOL><INDENT>value = try_datetime(v)<EOL><DEDENT>elif inferred_type == '<STR_LIT>':<EOL><INDENT>value = try_timedelta(v)<EOL><DEDENT>elif inferred_type == '<STR_LIT>':<EOL><INDENT>if isna(v).all():<EOL><INDENT>value = try_datetime(v)<EOL><DEDENT>else:<EOL><INDENT>value = try_timedelta(v)<EOL>if lib.infer_dtype(value, skipna=False) in ['<STR_LIT>']:<EOL><INDENT>value = try_datetime(v)<EOL><DEDENT><DEDENT><DEDENT>return value<EOL>
we might have a array (or single object) that is datetime like,
and no dtype is passed don't change the value unless we find a
datetime/timedelta set

this is pretty strict in that a datetime/timedelta is REQUIRED
in addition to possible nulls/string likes

Parameters
----------
value : np.array / Series / Index / list-like
convert_dates : boolean, default False
   if True try really hard to convert dates (such as datetime.date), other
   leave inferred dtype 'date' alone