# Buggy code
def __getitem__(self, index_value):
    """
    Return copy NpTrace with sliced sample values if a slice is passed,
    or the array of samples if a varname is passed.
    """

    if isinstance(index_value, slice):
        sliced_trace = NpTrace(self.vars)
        sliced_trace.samples = dict(
            (name, vals[index_value]) for (name, vals) in self.samples.items()
        )

        return sliced_trace

    else:
        try:
            return self.point(index_value)
        except ValueError:
            pass
        except TypeError:
            pass

        return self.samples[str(index_value)].value


# Traceback (IndexError)
======================================================================
ERROR: pymc.tests.test_plots.test_plots
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/fonnescj/Code/pymc/pymc/tests/test_plots.py", line 20, in test_plots
forestplot(trace)
File "/Users/fonnescj/Code/pymc/pymc/plots.py", line 329, in forestplot
trace_quantiles = quantiles(tr, qlist)
File "/Users/fonnescj/Code/pymc/pymc/stats.py", line 41, in wrapped_f
return {v: f(pymc_obj[v][burn:], *args, **kwargs) for v in vars}
File "/Users/fonnescj/Code/pymc/pymc/stats.py", line 41, in <dictcomp>
return {v: f(pymc_obj[v][burn:], *args, **kwargs) for v in vars}
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 45, in __getitem__
return self.point(index_value)
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 57, in point
return dict((k, v.value[index]) for (k, v) in self.samples.items())
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 57, in <genexpr>
return dict((k, v.value[index]) for (k, v) in self.samples.items())
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
-------------------- >> begin captured stdout << ---------------------
[-----------------97%----------------- ] 2930 of 3000 complete in 0.5 sec
[-----------------100%-----------------] 3000 of 3000 complete in 0.5 sec

--------------------- >> end captured stdout << ----------------------

======================================================================
ERROR: pymc.tests.test_plots.test_multichain_plots
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.2.1-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/fonnescj/Code/pymc/pymc/tests/test_plots.py", line 36, in test_multichain_plots
forestplot(ptrace, vars=['early_mean', 'late_mean'])
File "/Users/fonnescj/Code/pymc/pymc/plots.py", line 290, in forestplot
R = gelman_rubin(trace_obj)
File "/Users/fonnescj/Code/pymc/pymc/diagnostics.py", line 163, in gelman_rubin
x = np.array([mtrace.traces[i][var] for i in range(m)])
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 45, in __getitem__
return self.point(index_value)
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 57, in point
return dict((k, v.value[index]) for (k, v) in self.samples.items())
File "/Users/fonnescj/Code/pymc/pymc/trace.py", line 57, in <genexpr>
return dict((k, v.value[index]) for (k, v) in self.samples.items())
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

----------------------------------------------------------------------
Ran 2 tests in 44.915s

FAILED (errors=2)

# Fixed code
def __getitem__(self, index_value):
    """
    Return copy NpTrace with sliced sample values if a slice is passed,
    or the array of samples if a varname is passed.
    """

    if isinstance(index_value, slice):
        sliced_trace = NpTrace(self.vars)
        sliced_trace.samples = dict(
            (name, vals[index_value]) for (name, vals) in self.samples.items()
        )

        return sliced_trace

    else:
        try:
            return self.point(index_value)
        except (ValueError, TypeError, IndexError):
            pass

        return self.samples[str(index_value)].value