BUG: Dangerous inconsistency: ~
operator changes behavior based on context outside a target.
#61598
Open
3 tasks done
Labels
Uh oh!
There was an error while loading. Please reload this page.
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
This ia reprot about
~
opetarotr in pandas dataframe.Here is the example on python=3.10.12, pandas=2.2.3.
In the above example, the same
df.apply(lambda x: ~((x['B'] > 3) & (x['C'] < 8)), axis=1)
is executed in step 4, 5, and 7.However, the result of step 7 is ridiculous.
In spite of
~
,not
operator returns a correct answer.It seems that
~
operator in pandas dataframe quite dangerous and unreliable.In the environment of python 3.13.3, panads=2.2.3, only for the step 7, python returns warning that
<ipython-input-7-7d5677ff0f59>:1: DeprecationWarning: Bitwise inversion '~' on bool is deprecated and will be removed in Python 3.16. This returns the bitwise inversion of the underlying int object and is usually not what you expect from negating a bool. Use the 'not' operator for boolean negation or ~int(x) if you really want the bitwise inversion of the underlying int.
.However, I think this is a warning by python (not by pandas) from a different point of view.
Expected Behavior
The result of step 7 is same as step 4, 5.
Installed Versions
python = 3.10.12
pandas = 2.2.3
The text was updated successfully, but these errors were encountered: