ckaus / EpiPy

A tool for fitting epidemic models.
MIT License
3 stars 0 forks source link

IndexError: index out of bounds in data range text field #15

Closed ckaus closed 8 years ago

ckaus commented 8 years ago

image

Stacktrace christian@debian:~/Documents/workspace/EpiPy$ epipy Traceback (most recent call last): File "/home/christian/Documents/workspace/EpiPy/epipy/ui/controller/sidebarviewcontroller.py", line 93, in fit_data fitted_data = model_class.fit(x_data_fit, y_data_fit, N=population) File "/home/christian/Documents/workspace/EpiPy/epipy/model/basemodel.py", line 54, in fit self.N0 = self.init_param(y_data[0]) IndexError: index out of bounds

Problem: a data range of x:y where x > y or x==y returns an empty list which occurs an IndexError: index out of bounds in basemodel.py, line 54

ckaus commented 8 years ago

image

Test cases for x:y 1:0, -1:0, 1, :0, 1:, 1:1

Solution: File: inputgroupbox.py Line: 52 - 70

Check validity of data range values

        # check validity of data range
        _value = self.current_data_range
        try:
            from_value, to_value = _value.split(":")
            # check if values contains minus, because
            # a cast of a value -1 to an integer returns 1
            if from_value.contains('-') or to_value.contains('-'):
                raise ValueError

            from_value = int(from_value)
            to_value = int(to_value)

            if from_value < 0 or from_value >= to_value or to_value > self.data_input_length:
                raise ValueError
            else:
                self.model.input_model.data_range = self.current_data_range
        except ValueError:
            self.notify(Event.INVALID_DATA_RANGE)
            return

Some problem is also fixed for population input field.