-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
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
BUG: Incorrect float32/float64 comparison result #59524
Comments
Update:
passes. |
When we do ser = pd.Series(np.float32(0))
scalar = np.float64(3.503246160812043 * (10**-46))
print((ser - scalar).dtype)
# float32
print((scalar - ser).dtype)
# float32 Given this, it seems consistent to coerce |
There is some inconsistency with integers: ser = pd.Series(np.uint8(0))
scalar = np.int8(1)
print((ser - scalar).dtype)
# uint8
print((scalar - ser).dtype)
# uint8
print(ser - scalar)
# 0 255
# dtype: uint8
scalar = np.int8(-1)
print(ser + scalar)
# 0 -1
# dtype: int16 |
It's not clear to me if this is inconsistent or a special rule for dealing with negative integers. What would a proposal be? |
Yes my assumption was that there was an pd.Series(np.uint8(0)) - np.int8(1) != pd.Series(np.uint8(0)) + np.int8(-1) It would make more sense if both gave the same result (that of the RHS). For context, I work on similar processing operations in ArcticDB, and I was using hypothesis+Pandas to declaratively test ArcticDB when I noticed this. |
No disagreement that this is thorny - as mentioned above I think we would need a concrete proposal on how to handle promotion across operations and dtypes to move forward. |
Fair. As the ArcticDB code I linked shows, you can do this manually for the standard numeric types for a small number of supported binary operations, but you need to work out this logic for every operation you support, which I assume would be a bit of a mammoth task with Pandas. |
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
Comparing the two floating point values (of different widths) using
<
correctly returnsTrue
.Placing one of the floating point values into a Pandas Series and then running the same comparison incorrectly returns
False
. i.e. the second assertion fails.Note that the installed versions below use numpy 1.26.4. The issue is not reproducible with numpy 2.X
Expected Behavior
Both assertions should pass
Installed Versions
Released version:
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.10.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.153.1-microsoft-standard-WSL2
Version : #1 SMP Fri Mar 29 23:14:13 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
Dev version:
INSTALLED VERSIONS
commit : 0851ac3
python : 3.10.12
python-bits : 64
OS : Linux
OS-release : 5.15.153.1-microsoft-standard-WSL2
Version : #1 SMP Fri Mar 29 23:14:13 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 3.0.0.dev0+1344.g0851ac3b00
numpy : 1.26.4
dateutil : 2.9.0.post0
pip : 22.0.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: