简体   繁体   English

pandas / numpy int64(python 3.6)中出现意外的32位整数溢出

[英]Unexpected 32-bit integer overflow in pandas/numpy int64 (python 3.6)

Let me start with the example code: 让我从示例代码开始:

import numpy
from pandas import DataFrame

a = DataFrame({"nums": [2233, -23160, -43608]})

a.nums = numpy.int64(a.nums)

print(a.nums ** 2)
print((a.nums ** 2).sum())

On my local machine, and other devs' machines, this works as expected and prints out: 在我的本地计算机和其他开发人员的计算机上,这可以按预期工作并打印出来:

0       4986289
1     536385600
2    1901657664
Name: nums, dtype: int64
2443029553

However, on our production server, we get: 但是,在我们的生产服务器上,我们得到:

0       4986289
1     536385600
2    1901657664
Name: nums, dtype: int64
-1851937743

Which is 32-bit integer overflow, despite it being an int64. 这是32位整数溢出,尽管它是一个int64。

The production server is using the same versions of python, numpy, pandas, etc. It's a 64-bit Windows Server 2012 OS and everything reports 64-bit (eg python --version , sys.maxsize , plastform.architecture ). 生产服务器使用相同版本的python,numpy,pandas等。它是64-bit Windows Server 2012操作系统,所有内容都报告64位(例如python --versionsys.maxsizeplastform.architecture )。

What could possibly be causing this? 什么可能导致这个?

This is a bug in the bottleneck library, which Pandas uses if it's installed. 这是bottleneck库中的一个错误,Pandas在安装时会使用它。 In some circumstances, bottleneck.nansum incorrectly has 32-bit overflow behavior when called on 64-bit input. 在某些情况下,当在64位输入上调用时, bottleneck.nansum错误地具有32位溢出行为。

I believe this is due to bottleneck using PyInt_FromLong even when long is 32-bit. 我相信这是由于使用PyInt_FromLong bottleneck即使long是32位。 I'm not sure why that even compiles, actually. 实际上,我不确定为什么甚至会编译。 There's an issue report on the bottleneck issue tracker , not yet fixed, as well as an issue report on the Pandas issue tracker , where they tried to compensate for Bottleneck's issue (but I think they turned off Bottleneck when it does work instead of when it doesn't). 有一个关于瓶颈问题跟踪器的问题报告,尚未修复,以及关于Pandas问题跟踪器的问题报告,他们试图弥补瓶颈的问题(但我认为他们在工作时关闭了瓶颈而不是它没有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM