Arithmetic operation between Series and bool
fails · Issue #7011 · pandas-dev/pandas (original) (raw)
In the current master, I am no longer able to add or subtract bool
scalars from Series. For example:
In [63]: (covariates.isnull().sum(axis=1).astype(bool))
Out[63]:
case_id
A0001 False
A0002 False
A0003 False
A0004 False
A0005 False
A0006 False
A0007 False
A0008 False
A0009 False
A0010 False
A0011 False
A0012 False
A0013 False
A0014 False
A0015 False
...
D3760 True
D3761 False
D3762 False
D3763 False
D3764 False
D3765 False
D3766 False
D3767 False
D3768 False
D3769 False
D3770 False
D3771 False
D3772 False
D3773 False
D3774 False
Length: 3169, dtype: bool
In [65]: (covariates.isnull().sum(axis=1).astype(bool)).value_counts()
Out[65]:
False 2677
True 492
dtype: int64
In [66]: (covariates.isnull().sum(axis=1).astype(bool)) - True
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-66-6db12b7f95bf> in <module>()
----> 1 (covariates.isnull().sum(axis=1).astype(bool)) - True
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.13.1_780_gdc098d8-py2.7-macosx-10.9-x86_64.egg/pandas/core/ops.pyc in wrapper(left, right, name)
501 if hasattr(lvalues, 'values'):
502 lvalues = lvalues.values
--> 503 return left._constructor(wrap_results(na_op(lvalues, rvalues)),
504 index=left.index, name=left.name,
505 dtype=dtype)
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.13.1_780_gdc098d8-py2.7-macosx-10.9-x86_64.egg/pandas/core/ops.pyc in na_op(x, y)
441 try:
442 result = expressions.evaluate(op, str_rep, x, y,
--> 443 raise_on_error=True, **eval_kwargs)
444 except TypeError:
445 if isinstance(y, (pa.Array, pd.Series)):
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.13.1_780_gdc098d8-py2.7-macosx-10.9-x86_64.egg/pandas/computation/expressions.pyc in evaluate(op, op_str, a, b, raise_on_error, use_numexpr, **eval_kwargs)
185 use_numexpr : whether to try to use numexpr (default True)
186 """
--> 187 _bool_arith_check(op_str, a, b)
188 if use_numexpr:
189 return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.13.1_780_gdc098d8-py2.7-macosx-10.9-x86_64.egg/pandas/computation/expressions.pyc in _bool_arith_check(op_str, a, b, not_allowed)
164 def _bool_arith_check(op_str, a, b, not_allowed=frozenset(('+', '*', '-', '/',
165 '//', '**'))):
--> 166 if op_str in not_allowed and _has_bool_dtype(a) and _has_bool_dtype(b):
167 raise NotImplementedError("operator %r not implemented for bool "
168 "dtypes" % op_str)
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.13.1_780_gdc098d8-py2.7-macosx-10.9-x86_64.egg/pandas/computation/expressions.pyc in _has_bool_dtype(x)
159 return x.dtype == bool
160 except AttributeError:
--> 161 return 'bool' in x.blocks
162
163
AttributeError: 'bool' object has no attribute 'blocks'
Running current master on Python 2.7.5 (OS X 10.9.2).