In contrast, the following expression makes no problem and returns a Series of _SumExpression :
stocks.decisions.decision + 1000
It looks like the inequality expression is cast on a boolean, when I hoped to get just a _InequalityExpression .
Is there a specific reason that the ad-hoc overload does work for "+" (__add__) operator and not for the "<=" (__le__) operator ?
Or would that be a Pyomo issue?
Or a Pandas issue?
Would there be some nice workaround?
I will need a lot of similar expressions, involving joins over several Pandas Dataframes.
Thanks for you suggestions,
Michel
log of this exception
TypeError: Attempting to form a compound inequality with two lower bounds
The inequality expression:
stocks.decisions[0] <= 1000.0
contains non-constant terms (variables) that were evaluated in an
unexpected Boolean context at
File 'C:\Users\mjtoys\Anaconda3\lib\site-packages\pandas\core\ops.py', line 763:
result = lib.scalar_compare(x, y, op)
Evaluating Pyomo variables in a Boolean context, e.g.
if expression <= 5:
is generally invalid. If you want to obtain the Boolean value of the
expression based on the current variable values, explicitly evaluate the
expression using the value() function:
if value(expression) <= 5:
or
if value(expression <= 5):
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-27-a0255d0d7ceb> in <module>()
----> 1 (stocks.decisions.decision <= 1000)
~\Anaconda3\lib\site-packages\pandas\core\ops.py in wrapper(self, other, axis)
877
878 with np.errstate(all='ignore'):
--> 879 res = na_op(values, other)
880 if is_scalar(res):
881 raise TypeError('Could not compare {typ} type with Series'
~\Anaconda3\lib\site-packages\pandas\core\ops.py in na_op(x, y)
781
782 if is_object_dtype(x.dtype):
--> 783 result = _comp_method_OBJECT_ARRAY(op, x, y)
784 else:
785
~\Anaconda3\lib\site-packages\pandas\core\ops.py in _comp_method_OBJECT_ARRAY(op, x, y)
761 result = lib.vec_compare(x, y, op)
762 else:
--> 763 result = lib.scalar_compare(x, y, op)
764 return result
765
pandas/_libs/lib.pyx in pandas._libs.lib.scalar_compare()
~\Anaconda3\lib\site-packages\pyomo\core\kernel\numvalue.py in __le__(self, other)
441 (Called in response to 'self <= other' or 'other >= self'.)
442 """
--> 443 return generate_relational_expression(_le, self, other)
444
445 def __ge__(self,other):
~\Anaconda3\lib\site-packages\pyomo\core\kernel\expr_coopr3.py in generate_relational_expression(etype, lhs, rhs)
1486 raise TypeError(chainedInequalityErrorMessage(
1487 "Attempting to form a compound inequality with two "
-> 1488 "%s bounds" % ('lower' if match[0][0] else 'upper',)))
1489 if not match[0][1]:
1490 cloned_from = prevExpr._cloned_from + (cloned_from[1],)
TypeError: Attempting to form a compound inequality with two lower bounds
The inequality expression:
stocks.decisions[0] <= 1000.0
contains non-constant terms (variables) that were evaluated in an
unexpected Boolean context at
File 'C:\Users\mjtoys\Anaconda3\lib\site-packages\pandas\core\ops.py', line 763:
result = lib.scalar_compare(x, y, op)
Evaluating Pyomo variables in a Boolean context, e.g.
if expression <= 5:
is generally invalid. If you want to obtain the Boolean value of the
expression based on the current variable values, explicitly evaluate the
expression using the value() function:
if value(expression) <= 5:
or
if value(expression <= 5):