# Buggy code
def _convert_to_array(self, values, name=None, other=None):
    """converts values to ndarray"""
    from pandas.tseries.timedeltas import to_timedelta

    ovalues = values
    supplied_dtype = None
    if not is_list_like(values):
        values = np.array([values])
    # if this is a Series that contains relevant dtype info, then use this
    # instead of the inferred type; this avoids coercing Series([NaT],
    # dtype='datetime64[ns]') to Series([NaT], dtype='timedelta64[ns]')
    elif isinstance(values, pd.Series) and (
        is_timedelta64_dtype(values) or is_datetime64_dtype(values)
    ):
        supplied_dtype = values.dtype
    inferred_type = supplied_dtype or lib.infer_dtype(values)
    if inferred_type in ("datetime64", "datetime", "date", "time") or is_datetimetz(
        inferred_type
    ):
        # if we have a other of timedelta, but use pd.NaT here we
        # we are in the wrong path
        if (
            supplied_dtype is None
            and other is not None
            and (other.dtype in ("timedelta64[ns]", "datetime64[ns]"))
            and isnull(values).all()
        ):
            values = np.empty(values.shape, dtype="timedelta64[ns]")
            values[:] = iNaT

        # a datelike
        elif isinstance(values, pd.DatetimeIndex):
            values = values.to_series()
        # datetime with tz
        elif isinstance(ovalues, datetime.datetime) and hasattr(ovalues, "tz"):
            values = pd.DatetimeIndex(values)
        # datetime array with tz
        elif is_datetimetz(values):
            if isinstance(values, ABCSeries):
                values = values._values
        elif not (
            isinstance(values, (np.ndarray, ABCSeries)) and is_datetime64_dtype(values)
        ):
            values = tslib.array_to_datetime(values)
    elif inferred_type in ("timedelta", "timedelta64"):
        # have a timedelta, convert to to ns here
        values = to_timedelta(values, errors="coerce", box=False)
    elif inferred_type == "integer":
        # py3 compat where dtype is 'm' but is an integer
        if values.dtype.kind == "m":
            values = values.astype("timedelta64[ns]")
        elif isinstance(values, pd.PeriodIndex):
            values = values.to_timestamp().to_series()
        elif name not in ("__truediv__", "__div__", "__mul__", "__rmul__"):
            raise TypeError(
                "incompatible type for a datetime/timedelta operation [{0}]".format(
                    name
                )
            )
    elif inferred_type == "floating":
        if isnull(values).all() and name in (
            "__add__",
            "__radd__",
            "__sub__",
            "__rsub__",
        ):
            values = np.empty(values.shape, dtype=other.dtype)
            values[:] = iNaT
        return values
    elif self._is_offset(values):
        return values
    else:
        raise TypeError(
            "incompatible type [{0}] for a datetime/timedelta operation".format(
                np.array(values).dtype
            )
        )

    return values


# Traceback (ValueError)
import pytz
import datetime
import pandas as pd

foo = pd.Series(datetime.datetime(2016, 8, 23, 12, tzinfo=pytz.utc))
foo - datetime.datetime(2016, 8, 22, 12, tzinfo=pytz.utc)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-52-0639980e7d31> in <module>()
----> 1 foo - datetime.datetime(2016, 8, 1, 12, tzinfo=pytz.utc)

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/core/ops.pyc in wrapper(left, right, name, na_op)
607
608         time_converted = _TimeOp.maybe_convert_for_time_op(left, right, name,
--> 609                                                            na_op)
610
611         if time_converted is None:

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/core/ops.pyc in maybe_convert_for_time_op(cls, left, right, name, na_op)
567             return None
568
--> 569         return cls(left, right, name, na_op)
570
571

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/core/ops.pyc in __init__(self, left, right, name, na_op)
281
282         lvalues = self._convert_to_array(left, name=name)
--> 283         rvalues = self._convert_to_array(right, name=name, other=lvalues)
284
285         self.name = name

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/core/ops.pyc in _convert_to_array(self, values, name, other)
419             elif not (isinstance(values, (np.ndarray, ABCSeries)) and
420                       is_datetime64_dtype(values)):
--> 421                 values = tslib.array_to_datetime(values)
422         elif inferred_type in ('timedelta', 'timedelta64'):
423             # have a timedelta, convert to to ns here

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/tslib.so in pandas.tslib.array_to_datetime (pandas/tslib.c:41972)()

/Users/charon/.virtualenvs/iwoca-django/lib/python2.7/site-packages/pandas/tslib.so in pandas.tslib.array_to_datetime (pandas/tslib.c:38943)()

ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True

# Fixed code
def _convert_to_array(self, values, name=None, other=None):
    """converts values to ndarray"""
    from pandas.tseries.timedeltas import to_timedelta

    ovalues = values
    supplied_dtype = None
    if not is_list_like(values):
        values = np.array([values])
    # if this is a Series that contains relevant dtype info, then use this
    # instead of the inferred type; this avoids coercing Series([NaT],
    # dtype='datetime64[ns]') to Series([NaT], dtype='timedelta64[ns]')
    elif isinstance(values, pd.Series) and (
        is_timedelta64_dtype(values) or is_datetime64_dtype(values)
    ):
        supplied_dtype = values.dtype
    inferred_type = supplied_dtype or lib.infer_dtype(values)
    if inferred_type in ("datetime64", "datetime", "date", "time") or is_datetimetz(
        inferred_type
    ):
        # if we have a other of timedelta, but use pd.NaT here we
        # we are in the wrong path
        if (
            supplied_dtype is None
            and other is not None
            and (other.dtype in ("timedelta64[ns]", "datetime64[ns]"))
            and isnull(values).all()
        ):
            values = np.empty(values.shape, dtype="timedelta64[ns]")
            values[:] = iNaT

        # a datelike
        elif isinstance(values, pd.DatetimeIndex):
            values = values.to_series()
        # datetime with tz
        elif isinstance(ovalues, datetime.datetime) and hasattr(ovalues, "tzinfo"):
            values = pd.DatetimeIndex(values)
        # datetime array with tz
        elif is_datetimetz(values):
            if isinstance(values, ABCSeries):
                values = values._values
        elif not (
            isinstance(values, (np.ndarray, ABCSeries)) and is_datetime64_dtype(values)
        ):
            values = tslib.array_to_datetime(values)
    elif inferred_type in ("timedelta", "timedelta64"):
        # have a timedelta, convert to to ns here
        values = to_timedelta(values, errors="coerce", box=False)
    elif inferred_type == "integer":
        # py3 compat where dtype is 'm' but is an integer
        if values.dtype.kind == "m":
            values = values.astype("timedelta64[ns]")
        elif isinstance(values, pd.PeriodIndex):
            values = values.to_timestamp().to_series()
        elif name not in ("__truediv__", "__div__", "__mul__", "__rmul__"):
            raise TypeError(
                "incompatible type for a datetime/timedelta operation [{0}]".format(
                    name
                )
            )
    elif inferred_type == "floating":
        if isnull(values).all() and name in (
            "__add__",
            "__radd__",
            "__sub__",
            "__rsub__",
        ):
            values = np.empty(values.shape, dtype=other.dtype)
            values[:] = iNaT
        return values
    elif self._is_offset(values):
        return values
    else:
        raise TypeError(
            "incompatible type [{0}] for a datetime/timedelta operation".format(
                np.array(values).dtype
            )
        )

    return values