def maybe_convert_objects(values, convert_dates=True, convert_numeric=True,<EOL>convert_timedeltas=True, copy=True):
<EOL>if isinstance(values, (list, tuple)):<EOL><INDENT>values = np.array(values, dtype=np.object_)<EOL><DEDENT>if not hasattr(values, '<STR_LIT>'):<EOL><INDENT>values = np.array([values], dtype=np.object_)<EOL><DEDENT>if convert_dates and values.dtype == np.object_:<EOL><INDENT>if convert_dates == '<STR_LIT>':<EOL><INDENT>new_values = maybe_cast_to_datetime(<EOL>values, '<STR_LIT>', errors='<STR_LIT>')<EOL>if not isna(new_values).all():<EOL><INDENT>values = new_values<EOL><DEDENT><DEDENT>else:<EOL><INDENT>values = lib.maybe_convert_objects(values,<EOL>convert_datetime=convert_dates)<EOL><DEDENT><DEDENT>if convert_timedeltas and values.dtype == np.object_:<EOL><INDENT>if convert_timedeltas == '<STR_LIT>':<EOL><INDENT>from pandas.core.tools.timedeltas import to_timedelta<EOL>new_values = to_timedelta(values, errors='<STR_LIT>')<EOL>if not isna(new_values).all():<EOL><INDENT>values = new_values<EOL><DEDENT><DEDENT>else:<EOL><INDENT>values = lib.maybe_convert_objects(<EOL>values, convert_timedelta=convert_timedeltas)<EOL><DEDENT><DEDENT>if values.dtype == np.object_:<EOL><INDENT>if convert_numeric:<EOL><INDENT>try:<EOL><INDENT>new_values = lib.maybe_convert_numeric(values, set(),<EOL>coerce_numeric=True)<EOL>if not isna(new_values).all():<EOL><INDENT>values = new_values<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>else:<EOL><INDENT>values = lib.maybe_convert_objects(values)<EOL><DEDENT><DEDENT>values = values.copy() if copy else values<EOL>return values<EOL>
if we have an object dtype, try to coerce dates and/or numbers