def maybe_upcast_for_op(obj):
if type(obj) is datetime.timedelta:<EOL><INDENT>return pd.Timedelta(obj)<EOL><DEDENT>elif isinstance(obj, np.timedelta64) and not isna(obj):<EOL><INDENT>return pd.Timedelta(obj)<EOL><DEDENT>elif isinstance(obj, np.ndarray) and is_timedelta64_dtype(obj):<EOL><INDENT>return pd.TimedeltaIndex(obj)<EOL><DEDENT>return obj<EOL>
Cast non-pandas objects to pandas types to unify behavior of arithmetic
and comparison operations.

Parameters
----------
obj: object

Returns
-------
out : object

Notes
-----
Be careful to call this *after* determining the `name` attribute to be
attached to the result of the arithmetic operation.