def _try_cast(self, result, obj, numeric_only=False):
if obj.ndim > <NUM_LIT:1>:<EOL><INDENT>dtype = obj._values.dtype<EOL><DEDENT>else:<EOL><INDENT>dtype = obj.dtype<EOL><DEDENT>if not is_scalar(result):<EOL><INDENT>if is_datetime64tz_dtype(dtype):<EOL><INDENT>try:<EOL><INDENT>result = obj._values._from_sequence(<EOL>result, dtype='<STR_LIT>'<EOL>)<EOL>result = result.astype(dtype)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif is_extension_array_dtype(dtype):<EOL><INDENT>try:<EOL><INDENT>result = obj._values._from_sequence(result, dtype=dtype)<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif numeric_only and is_numeric_dtype(dtype) or not numeric_only:<EOL><INDENT>result = maybe_downcast_to_dtype(result, dtype)<EOL><DEDENT><DEDENT>return result<EOL>
Try to cast the result to our obj original type,
we may have roundtripped through object in the mean-time.

If numeric_only is True, then only try to cast numerics
and not datetimelikes.