def infer_freq(index, warn=True):
import pandas as pd<EOL>if isinstance(index, ABCSeries):<EOL><INDENT>values = index._values<EOL>if not (is_datetime64_dtype(values) or<EOL>is_timedelta64_dtype(values) or<EOL>values.dtype == object):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>".format(dtype=index.dtype))<EOL><DEDENT>index = values<EOL><DEDENT>if is_period_arraylike(index):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>elif is_timedelta64_dtype(index):<EOL><INDENT>inferer = _TimedeltaFrequencyInferer(index, warn=warn)<EOL>return inferer.get_freq()<EOL><DEDENT>if isinstance(index, pd.Index) and not isinstance(index, pd.DatetimeIndex):<EOL><INDENT>if isinstance(index, (pd.Int64Index, pd.Float64Index)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>".format(type=type(index)))<EOL><DEDENT>index = index.values<EOL><DEDENT>if not isinstance(index, pd.DatetimeIndex):<EOL><INDENT>try:<EOL><INDENT>index = pd.DatetimeIndex(index)<EOL><DEDENT>except AmbiguousTimeError:<EOL><INDENT>index = pd.DatetimeIndex(index.asi8)<EOL><DEDENT><DEDENT>inferer = _FrequencyInferer(index, warn=warn)<EOL>return inferer.get_freq()<EOL>
Infer the most likely frequency given the input index. If the frequency is
uncertain, a warning will be printed.

Parameters
----------
index : DatetimeIndex or TimedeltaIndex
  if passed a Series will use the values of the series (NOT THE INDEX)
warn : boolean, default True

Returns
-------
str or None
    None if no discernible frequency
    TypeError if the index is not datetime-like
    ValueError if there are less than three values.