# Buggy code
def get_vertex_centered_data(self, fields, smoothed=True, no_ghost=False):
    _old_api = isinstance(fields, (string_types, tuple))
    if _old_api:
        message = (
            "get_vertex_centered_data() requires list of fields, rather than "
            "a single field as an argument."
        )
        warnings.warn(message, DeprecationWarning, stacklevel=2)
        fields = [fields]

    # Make sure the field list has only unique entries
    fields = list(set(fields))
    new_fields = {}
    for field in fields:
        finfo = self.ds._get_field_info(field)
        new_fields[field] = self.ds.arr(
            np.zeros(self.ActiveDimensions + 1), finfo.units
        )
    if no_ghost:
        for field in fields:
            # Ensure we have the native endianness in this array.  Avoid making
            # a copy if possible.
            old_field = np.asarray(self[field], dtype="=f8")
            # We'll use the ghost zone routine, which will naturally
            # extrapolate here.
            input_left = np.array([0.5, 0.5, 0.5], dtype="float64")
            output_left = np.array([0.0, 0.0, 0.0], dtype="float64")
            # rf = 1 here
            ghost_zone_interpolate(
                1, old_field, input_left, new_fields[field], output_left
            )
    else:
        cg = self.retrieve_ghost_zones(1, fields, smoothed=smoothed)
        for field in fields:
            np.add(new_fields[field], cg[field][1:, 1:, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, 1:, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][1:, :-1, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][1:, 1:, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, 1:, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][1:, :-1, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, :-1, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, :-1, :-1], new_fields[field])
            np.multiply(new_fields[field], 0.125, new_fields[field])

    if _old_api:
        return new_fields[fields[0]]
    return new_fields


# Traceback (yt.utilities.exceptions.YTUfuncUnitError)
Traceback (most recent call last):
File "test.py", line 9, in <module>
print(sur['x'][0])
File "/Users/goldbaum/Documents/yt-git/yt/data_objects/data_containers.py", line 281, in __getitem__
self.get_data(f)
File "/Users/goldbaum/Documents/yt-git/yt/data_objects/construction_data_containers.py", line 1144, in get_data
mask, fields, sample_type, no_ghost=no_ghost)
File "/Users/goldbaum/Documents/yt-git/yt/data_objects/construction_data_containers.py", line 1171, in _extract_isocontours_from_grid
svals = grid.get_vertex_centered_data([sample_values])[sample_values]
File "/Users/goldbaum/Documents/yt-git/yt/data_objects/grid_patch.py", line 293, in get_vertex_centered_data
np.add(new_fields[field], cg[field][1: ,1: ,1: ], new_fields[field])
File "/Users/goldbaum/Documents/yt-git/yt/units/yt_array.py", line 1225, in __array_wrap__
raise YTUfuncUnitError(context[0], unit1, unit2)
yt.utilities.exceptions.YTUfuncUnitError: The NumPy <ufunc 'add'> operation is only allowed on objects with identical units. Convert one of the arrays to the other's units first. Received units (code_length) and (cm).

# Fixed code
def get_vertex_centered_data(self, fields, smoothed=True, no_ghost=False):
    _old_api = isinstance(fields, (string_types, tuple))
    if _old_api:
        message = (
            "get_vertex_centered_data() requires list of fields, rather than "
            "a single field as an argument."
        )
        warnings.warn(message, DeprecationWarning, stacklevel=2)
        fields = [fields]

    # Make sure the field list has only unique entries
    fields = list(set(fields))
    new_fields = {}
    for field in fields:
        finfo = self.ds._get_field_info(field)
        new_fields[field] = self.ds.arr(
            np.zeros(self.ActiveDimensions + 1), finfo.output_units
        )
    if no_ghost:
        for field in fields:
            # Ensure we have the native endianness in this array.  Avoid making
            # a copy if possible.
            old_field = np.asarray(self[field], dtype="=f8")
            # We'll use the ghost zone routine, which will naturally
            # extrapolate here.
            input_left = np.array([0.5, 0.5, 0.5], dtype="float64")
            output_left = np.array([0.0, 0.0, 0.0], dtype="float64")
            # rf = 1 here
            ghost_zone_interpolate(
                1, old_field, input_left, new_fields[field], output_left
            )
    else:
        cg = self.retrieve_ghost_zones(1, fields, smoothed=smoothed)
        for field in fields:
            np.add(new_fields[field], cg[field][1:, 1:, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, 1:, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][1:, :-1, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][1:, 1:, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, 1:, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][1:, :-1, :-1], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, :-1, 1:], new_fields[field])
            np.add(new_fields[field], cg[field][:-1, :-1, :-1], new_fields[field])
            np.multiply(new_fields[field], 0.125, new_fields[field])

    if _old_api:
        return new_fields[fields[0]]
    return new_fields