# Buggy code
def _set_with(self, key, value):
    # other: fancy integer or otherwise
    if isinstance(key, slice):
        indexer = self.index._convert_slice_indexer(key, kind="getitem")
        return self._set_values(indexer, value)
    else:
        if isinstance(key, tuple):
            try:
                self._set_values(key, value)
            except Exception:
                pass

        if is_scalar(key):
            key = [key]
        elif not isinstance(key, (list, Series, np.ndarray)):
            try:
                key = list(key)
            except Exception:
                key = [key]

        if isinstance(key, Index):
            key_type = key.inferred_type
        else:
            key_type = lib.infer_dtype(key, skipna=False)

        if key_type == "integer":
            if self.index.inferred_type == "integer":
                self._set_labels(key, value)
            else:
                return self._set_values(key, value)
        elif key_type == "boolean":
            self._set_values(key.astype(np.bool_), value)
        else:
            self._set_labels(key, value)


# Traceback (ValueError)
ValueError                                Traceback (most recent call last)
<ipython-input-24-cc1ab78086e5> in <module>()
1 x = pd.Series()
2 x['foo'] = pd.to_datetime(42).tz_localize('UTC')
----> 3 x['bar'] = pd.to_datetime(666).tz_localize('UTC')

/usr/lib/python3.5/site-packages/pandas/core/series.py in __setitem__(self, key, value)
726         # do the setitem
727         cacher_needs_updating = self._check_is_chained_assignment_possible()
--> 728         setitem(key, value)
729         if cacher_needs_updating:
730             self._maybe_update_cacher()

/usr/lib/python3.5/site-packages/pandas/core/series.py in setitem(key, value)
722                     pass
723
--> 724             self._set_with(key, value)
725
726         # do the setitem

/usr/lib/python3.5/site-packages/pandas/core/series.py in _set_with(self, key, value)
770                 self._set_values(key.astype(np.bool_), value)
771             else:
--> 772                 self._set_labels(key, value)
773
774     def _set_labels(self, key, value):

/usr/lib/python3.5/site-packages/pandas/core/series.py in _set_labels(self, key, value)
780         mask = indexer == -1
781         if mask.any():
--> 782             raise ValueError('%s not contained in the index' % str(key[mask]))
783         self._set_values(indexer, value)
784

ValueError: ['b' 'a' 'r'] not contained in the index

# Fixed code
def _set_with(self, key, value):
    # other: fancy integer or otherwise
    if isinstance(key, slice):
        indexer = self.index._convert_slice_indexer(key, kind="getitem")
        return self._set_values(indexer, value)
    else:
        if isinstance(key, tuple):
            try:
                self._set_values(key, value)
            except Exception:
                pass

        if is_scalar(key) and not is_integer(key) and key not in self.index:
            # GH#12862 adding an new key to the Series
            # Note: have to exclude integers because that is ambiguously
            #  position-based
            self.loc[key] = value
            return

        if is_scalar(key):
            key = [key]
        elif not isinstance(key, (list, Series, np.ndarray)):
            try:
                key = list(key)
            except Exception:
                key = [key]

        if isinstance(key, Index):
            key_type = key.inferred_type
        else:
            key_type = lib.infer_dtype(key, skipna=False)

        if key_type == "integer":
            if self.index.inferred_type == "integer":
                self._set_labels(key, value)
            else:
                return self._set_values(key, value)
        elif key_type == "boolean":
            self._set_values(key.astype(np.bool_), value)
        else:
            self._set_labels(key, value)