File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 62
62
* Array.split_axes now raises an explicit error when some labels contain
63
63
more separators than others, instead of silently dropping part of those
64
64
labels, or even some data (closes :issue:`1089 `).
65
+
66
+ * a boolean condition including only X.axes_name and scalars (e.g. X.age == 0 )
67
+ raises an error when Python needs to know whether it is True or not (because
68
+ there is no array to extract the axis labels from) instead of always
69
+ evaluating to True. This was especially dangerous in the context of a
70
+ where() function, which always evaluated to its left side
71
+ (e.g. where(X.age > 0 , arr, 0 ) evaluated to 'arr' for all ages).
72
+ Closes :issue:`1083`.
Original file line number Diff line number Diff line change 1
1
class ExprNode :
2
+ def __bool__ (self ):
3
+ raise ValueError ("Cannot evaluate the truth value of an expression using X.axis_name" )
4
+
2
5
# method factory
3
6
def _binop (opname ):
4
7
def opmethod (self , other ):
Original file line number Diff line number Diff line change @@ -2945,6 +2945,11 @@ def test_unary_ops(small_array):
2945
2945
assert_nparray_equal ((~ small_array ).data , ~ raw )
2946
2946
2947
2947
2948
+ def test_binary_ops_expressions ():
2949
+ with must_raise (ValueError , "Cannot evaluate the truth value of an expression using X.axis_name" ):
2950
+ res = 0 if X .age == 3 else 1
2951
+
2952
+
2948
2953
def test_mean (small_array ):
2949
2954
raw = small_array .data
2950
2955
c , d = small_array .axes
You can’t perform that action at this time.
0 commit comments