# Buggy code
def upgrade_settings(
    self, setting_values, variable_revision_number, module_name, from_matlab
):
    if from_matlab and variable_revision_number == 2:
        setting_values = [
            setting_values[0],
            setting_values[1],
            setting_values[2],
            cellprofiler.setting.DO_NOT_USE,
            cellprofiler.setting.YES,
        ]

        variable_revision_number = 3

    if from_matlab and variable_revision_number == 3:
        setting_values = list(setting_values)

        setting_values[2] = (
            D_MINIMUM if setting_values[2] == cellprofiler.setting.YES else D_NONE
        )

        variable_revision_number = 4

    if from_matlab and variable_revision_number == 4:
        if setting_values[2] == cellprofiler.setting.DO_NOT_USE:
            setting_values = setting_values[:2] + [D_NONE] + setting_values[3:]

        from_matlab = False

        variable_revision_number = 1

    if (not from_matlab) and variable_revision_number == 1:
        #
        # Added other distance parents
        #
        if setting_values[2] == cellprofiler.setting.DO_NOT_USE:
            find_parent_distances = D_NONE
        else:
            find_parent_distances = setting_values[2]

        if setting_values[3].upper() == cellprofiler.setting.DO_NOT_USE.upper():
            wants_step_parent_distances = cellprofiler.setting.NO
        else:
            wants_step_parent_distances = cellprofiler.setting.YES

        setting_values = setting_values[:2] + [
            find_parent_distances,
            setting_values[4],
            wants_step_parent_distances,
            setting_values[3],
        ]

        variable_revision_number = 2

    return setting_values, variable_revision_number, from_matlab


# Traceback (ValueError)
Traceback (most recent call last):
File "C:\Users\brayma2\Desktop\GitHub\CellProfiler\cellprofiler\gui\pipelinecontroller.py", line 2844, in do_step
self.__pipeline.run_module(module, workspace)
File "C:\Users\brayma2\Desktop\GitHub\CellProfiler\cellprofiler\pipeline.py", line 2108, in run_module
module.run(workspace)
File "C:\Users\brayma2\Desktop\GitHub\CellProfiler\cellprofiler\modules\relateobjects.py", line 252, in run
self.calculate_centroid_distances(workspace, parent_name)
File "C:\Users\brayma2\Desktop\GitHub\CellProfiler\cellprofiler\modules\relateobjects.py", line 336, in calculate_centroid_distances
parents_of = self.get_parents_of(workspace, parent_name)
File "C:\Users\brayma2\Desktop\GitHub\CellProfiler\cellprofiler\modules\relateobjects.py", line 475, in get_parents_of
reverse_lookup_len = max(np.max(primary_parents_of) + 1,
File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 2263, in amax
out=out, keepdims=keepdims)
File "C:\Python27\lib\site-packages\numpy\core\_methods.py", line 26, in _amax
return umr_maximum(a, axis, None, out, keepdims)
ValueError: zero-size array to reduction operation maximum which has no identity

# Fixed code
def upgrade_settings(
    self, setting_values, variable_revision_number, module_name, from_matlab
):
    if variable_revision_number == 1:
        #
        # Added other distance parents
        #
        if setting_values[2] == cellprofiler.setting.DO_NOT_USE:
            find_parent_distances = D_NONE
        else:
            find_parent_distances = setting_values[2]

        if setting_values[3].upper() == cellprofiler.setting.DO_NOT_USE.upper():
            wants_step_parent_distances = cellprofiler.setting.NO
        else:
            wants_step_parent_distances = cellprofiler.setting.YES

        setting_values = setting_values[:2] + [
            find_parent_distances,
            setting_values[4],
            wants_step_parent_distances,
            setting_values[3],
        ]

        variable_revision_number = 2

    if variable_revision_number == 2:
        setting_values = [setting_values[1], setting_values[0]] + setting_values[2:]

        variable_revision_number = 3

    return setting_values, variable_revision_number, from_matlab