We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It seems that Pandas' boolean dtype has some bug -- comparison with strings fails.
Code to reproduce (version 1.3.4)
import pandas as pd s = pd.Series([True, False, pd.NA], dtype="boolean") s == "X"
The code above fails with this error:
TypeError Traceback (most recent call last) <ipython-input-41-f42702e3c612> in <module> ----> 1 a == "X" ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/ops/common.py in new_method(self, other) 67 other = item_from_zerodim(other) 68 ---> 69 return method(self, other) 70 71 return new_method ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/arraylike.py in __eq__(self, other) 30 @unpack_zerodim_and_defer("__eq__") 31 def __eq__(self, other): ---> 32 return self._cmp_method(other, operator.eq) 33 34 @unpack_zerodim_and_defer("__ne__") ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/series.py in _cmp_method(self, other, op) 5500 5501 with np.errstate(all="ignore"): -> 5502 res_values = ops.comparison_op(lvalues, rvalues, op) 5503 5504 return self._construct_result(res_values, name=res_name) ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/ops/array_ops.py in comparison_op(left, right, op) 268 ): 269 # Call the method on lvalues --> 270 res_values = op(lvalues, rvalues) 271 272 elif is_scalar(rvalues) and isna(rvalues): ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/ops/common.py in new_method(self, other) 67 other = item_from_zerodim(other) 68 ---> 69 return method(self, other) 70 71 return new_method ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/arraylike.py in __eq__(self, other) 30 @unpack_zerodim_and_defer("__eq__") 31 def __eq__(self, other): ---> 32 return self._cmp_method(other, operator.eq) 33 34 @unpack_zerodim_and_defer("__ne__") ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/arrays/boolean.py in _cmp_method(self, other, op) 671 mask = self._mask | mask 672 --> 673 return BooleanArray(result, mask, copy=False) 674 675 def _arith_method(self, other, op): ~/virtenvs/mkl/lib/python3.9/site-packages/pandas/core/arrays/boolean.py in __init__(self, values, mask, copy) 297 def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False): 298 if not (isinstance(values, np.ndarray) and values.dtype == np.bool_): --> 299 raise TypeError( 300 "values should be boolean numpy array. Use " 301 "the 'pd.array' function instead" TypeError: values should be boolean numpy array. Use the 'pd.array' function instead
The text was updated successfully, but these errors were encountered:
The same bug exists in 1.3.5
1.3.5
Sorry, something went wrong.
code sample for pandas-dev#44903
638cc68
Thanks @eli-osherovich for the report.
was fixed in commit: [0f81a63] BUG: BooleanArray raising on comparison to string (#44533)
the fix will be included in the 1.4 release early in the new year.
import pandas as pd print(pd.__version__) s = pd.Series([True, False, pd.NA], dtype="boolean") s == "X"
0 False 1 False 2 <NA> dtype: boolean
closing as the PR that fixed added tests explicitly for test_eq_mismatched_type and well as replace.
test_eq_mismatched_type
replace
No branches or pull requests
It seems that Pandas' boolean dtype has some bug -- comparison with strings fails.
Code to reproduce (version 1.3.4)
The code above fails with this error:
The text was updated successfully, but these errors were encountered: