Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] 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

import pandas as pd
def test_unary(val):
    df = pd.DataFrame({'x': np.array([0.11, 0], dtype=np.float32)})
    res = df.eval(f'x=x.fillna({val})')
test_unary(1)  # works
test_unary(-1)  # fails

Issue Description

.eval seems to be having some problems with negative values. A very similar issue has been reported, summarized and closed here: #16363

However, it clearly still persists in other instances.

Expected Behavior

test_unary(-1) # works

Installed Versions

INSTALLED VERSIONS ------------------ commit : 66e3805b8cabe977f40c05259cc3fcf7ead5687d python : 3.9.10.final.0 python-bits : 64 OS : Linux OS-release : 5.13.0-35-generic Version : #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.3.5 numpy : 1.21.2 pytz : 2021.3 dateutil : 2.8.2 pip : 21.3.1 setuptools : 58.2.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.0.2 IPython : 7.28.0 pandas_datareader: None bs4 : None bottleneck : None fsspec : 2021.11.1 fastparquet : None gcsfs : None matplotlib : 3.4.3 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 5.0.0 pyxlsb : None s3fs : 2021.11.1 scipy : 1.7.1 sqlalchemy : 1.4.25 tables : None tabulate : 0.8.9 xarray : None xlrd : None xlwt : None numba : 0.55.0

Comment From: rhshadrach

Thanks for the report! Further investigations and PRs to fix are most welcome.

Comment From: Saxeman

take

Comment From: shyamsantoki

take

Comment From: PierXuY

It can be implemented in the following ways:

import pandas as pd
import numpy as np
df = pd.DataFrame([np.nan,1,1], columns=['A'])
result = df.eval('A.fillna(@negative(1))',local_dict={'negative':lambda x:-x})