# Buggy code
def __init__(self, mesh_id, filename, connectivity_indices, connectivity_coords, index):
    self.field_data = YTFieldData()
    self.filename = filename
    self.field_parameters = {}
    self.mesh_id = mesh_id
    # This is where we set up the connectivity information
    self.connectivity_indices = connectivity_indices
    if connectivity_indices.shape[1] != self._connectivity_length:
        if self._connectivity_length == -1:
            self._connectivity_length = connectivity_indices.shape[1]
        else:
            raise RuntimeError
    self.connectivity_coords = connectivity_coords
    self.ds = index.dataset
    self._index = index
    self._last_mask = None
    self._last_count = -1
    self._last_selector_id = None
    self._current_particle_type = "all"
    self._current_fluid_type = self.ds.default_fluid_type


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-ea26250246dd> in <module>()
----> 1 grid['particle_velocity_magnitude']

/home/ychen/src/yt-git/yt/data_objects/grid_patch.py in __getitem__(self, key)
93
94     def __getitem__(self, key):
---> 95         tr = super(AMRGridPatch, self).__getitem__(key)
96         try:
97             fields = self._determine_fields(key)

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in __getitem__(self, key)
279                 return self.field_data[f]
280             else:
--> 281                 self.get_data(f)
282         # fi.units is the unit expression string. We depend on the registry
283         # hanging off the dataset to define this unit object.

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in get_data(self, fields)
1334
1335         fields_to_generate += gen_fluids + gen_particles
-> 1336         self._generate_fields(fields_to_generate)
1337         for field in list(self.field_data.keys()):
1338             if field not in ofields:

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_fields(self, fields_to_generate)
1354                 fi = self.ds._get_field_info(*field)
1355                 try:
-> 1356                     fd = self._generate_field(field)
1357                     if fd is None:
1358                         raise RuntimeError

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_field(self, field)
314                 tr = self._generate_container_field(field)
315             if finfo.particle_type: # This is a property now
--> 316                 tr = self._generate_particle_field(field)
317             else:
318                 tr = self._generate_fluid_field(field)

/home/ychen/src/yt-git/yt/data_objects/data_containers.py in _generate_particle_field(self, field)
399         else:
400             with self._field_type_state(ftype, finfo, gen_obj):
--> 401                 rv = self.ds._get_field_info(*field)(gen_obj)
402         return rv
403

/home/ychen/src/yt-git/yt/fields/derived_field.py in __call__(self, data)
235                 "for %s" % (self.name,))
236         with self.unit_registry(data):
--> 237             dd = self._function(self, data)
238         for field_name in data.keys():
239             if field_name not in original_fields:

/home/ychen/src/yt-git/yt/fields/particle_fields.py in _particle_velocity_magnitude(field, data)
282         return np.sqrt((data[ptype, svel % 'x'] - bulk_velocity[0])**2
283                      + (data[ptype, svel % 'y'] - bulk_velocity[1])**2
--> 284                      + (data[ptype, svel % 'z'] - bulk_velocity[2])**2 )
285
286     registry.add_field((ptype, "particle_velocity_magnitude"),

TypeError: 'NoneType' object is not subscriptable

# Fixed code
def __init__(self, mesh_id, filename, connectivity_indices, connectivity_coords, index):
    super(UnstructuredMesh, self).__init__(index.dataset, None)
    self.filename = filename
    self.mesh_id = mesh_id
    # This is where we set up the connectivity information
    self.connectivity_indices = connectivity_indices
    if connectivity_indices.shape[1] != self._connectivity_length:
        if self._connectivity_length == -1:
            self._connectivity_length = connectivity_indices.shape[1]
        else:
            raise RuntimeError
    self.connectivity_coords = connectivity_coords
    self.ds = index.dataset
    self._index = index
    self._last_mask = None
    self._last_count = -1
    self._last_selector_id = None