# Buggy code
def _part_ind(self, ptype):
    if self._particle_mask.get(ptype) is None:
        # If scipy is installed, use the fast KD tree
        # implementation. Else, fall back onto the direct
        # brute-force algorithm.
        try:
            _scipy.spatial.KDTree
            mask = self._part_ind_KDTree(ptype)
        except ImportError:
            mask = self._part_ind_brute_force(ptype)

        self._particle_mask[ptype] = mask
    return self._particle_mask[ptype]


# Traceback (IndexError)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-83-3704089812fe> in <module>
5 sp = ds.sphere((0.5, 0.5, 0.5), (5, "kpc"))
6 dense_sp = sp.cut_region(['obj["H_p0_number_density"]>= 1e-2'])
----> 7 dense_sp.quantities.angular_momentum_vector()

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/data_objects/derived_quantities.py in __call__(self, *args, **kwargs)
67         storage = {}
68         for sto, ds in parallel_objects(chunks, -1, storage = storage):
---> 69             sto.result = self.process_chunk(ds, *args, **kwargs)
70         # Now storage will have everything, and will be done via pickling, so
71         # the units will be preserved.  (Credit to Nathan for this

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/data_objects/derived_quantities.py in process_chunk(self, data, use_gas, use_particles, particle_type)
493             rvals.extend([(data[self.particle_type, "particle_specific_angular_momentum_%s" % axis] *
494                            data[self.particle_type, "particle_mass"]).sum(dtype=np.float64) \
--> 495                           for axis in "xyz"])
496             rvals.append(data[self.particle_type, "particle_mass"].sum(dtype=np.float64))
497         return rvals

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/data_objects/derived_quantities.py in <listcomp>(.0)
493             rvals.extend([(data[self.particle_type, "particle_specific_angular_momentum_%s" % axis] *
494                            data[self.particle_type, "particle_mass"]).sum(dtype=np.float64) \
--> 495                           for axis in "xyz"])
496             rvals.append(data[self.particle_type, "particle_mass"].sum(dtype=np.float64))
497         return rvals

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/data_objects/data_containers.py in __getitem__(self, key)
253                 return self.field_data[f]
254             else:
--> 255                 self.get_data(f)
256         # fi.units is the unit expression string. We depend on the registry
257         # hanging off the dataset to define this unit object.

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/data_objects/selection_data_containers.py in get_data(self, fields)
901                 parent = getattr(self, "parent", self.base_object)
902                 self.field_data[field] = \
--> 903                   parent[field][self._part_ind(field[0])]
904             else:
905                 self.field_data[field] = self.base_object[field][ind]

~/.local/lib/python3.6/site-packages/yt-3.6.dev0-py3.6-macosx-10.9-x86_64.egg/yt/units/yt_array.py in __getitem__(self, item)
1056
1057     def __getitem__(self, item):
-> 1058         ret = super(YTArray, self).__getitem__(item)
1059         if ret.shape == ():
1060             return YTQuantity(ret, self.units, bypass_validation=True)

IndexError: boolean index did not match indexed array along dimension 0; dimension is 44461 but corresponding boolean dimension is 3218

# Fixed code
def _part_ind(self, ptype):
    # If scipy is installed, use the fast KD tree
    # implementation. Else, fall back onto the direct
    # brute-force algorithm.
    try:
        _scipy.spatial.KDTree
        return self._part_ind_KDTree(ptype)
    except ImportError:
        return self._part_ind_brute_force(ptype)