def _generic_binary_op(self, other, op):
output = {}<EOL>if isinstance(other, TimeSeries):<EOL><INDENT>for key, value in self.items():<EOL><INDENT>if key in other:<EOL><INDENT>try:<EOL><INDENT>result = op(value, other[key])<EOL>if result is NotImplemented:<EOL><INDENT>other_type = type(other[key])<EOL>other_op = vars(other_type).get(op.__name__)<EOL>if other_op:<EOL><INDENT>output[key] = other_op(other_type(value), other[key])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[key] = result<EOL><DEDENT><DEDENT>except ZeroDivisionError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for key, value in self.items():<EOL><INDENT>try:<EOL><INDENT>result = op(value, other)<EOL>if result is NotImplemented:<EOL><INDENT>other_type = type(other)<EOL>other_op = vars(other_type).get(op.__name__)<EOL>if other_op:<EOL><INDENT>output[key] = other_op(other_type(value), other)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output[key] = result<EOL><DEDENT><DEDENT>except ZeroDivisionError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT>if output:<EOL><INDENT>return TimeSeries(output)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>
Perform the method operation specified in the op parameter on the values
within the instance's time series values and either another time series
or a constant number value.

:param other: Time series of values or a constant number to use in calculations with instance's time series.
:param func op: The method to perform the calculation between the values.
:return: :class:`TimeSeries` object.