I love that the ZeroDivisionError for _calculate_gain_and_offset causes the raw digital data to be returned—this is exactly the behavior one would expect (the data is still there, who cares if the digital or physical min/max values were set by the user incorrectly?!).
The warning message needs an additional condition, because there are two different division by zero conditions that are possible—one for each line in _calculate_gain_and_offset.
gain = (physical_max - physical_min) / (digital_max - digital_min) A division by zero happens here when digital max and min are the same. And is the situation that the warning is written to address.
However, offset = physical_max / gain - digital_max can also produce a division by zero (when gain=0). This happens when the physical max and min are the same).
Adding a test inside the except block to check if self.digital_max == self.digital_min: to decide which warning to produce will solve this.
I love that the
ZeroDivisionError
for_calculate_gain_and_offset
causes the raw digital data to be returned—this is exactly the behavior one would expect (the data is still there, who cares if the digital or physical min/max values were set by the user incorrectly?!).The warning message needs an additional condition, because there are two different division by zero conditions that are possible—one for each line in
_calculate_gain_and_offset
.gain = (physical_max - physical_min) / (digital_max - digital_min)
A division by zero happens here when digital max and min are the same. And is the situation that the warning is written to address.offset = physical_max / gain - digital_max
can also produce a division by zero (whengain=0
). This happens when the physical max and min are the same).Adding a test inside the
except
block to checkif self.digital_max == self.digital_min:
to decide which warning to produce will solve this.