test_io.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:Alfred 作者: jkachhadia 项目源码 文件源码
def test_auto_dtype_largeint(self):
        # Regression test for numpy/numpy#5635 whereby large integers could
        # cause OverflowErrors.

        # Test the automatic definition of the output dtype
        #
        # 2**66 = 73786976294838206464 => should convert to float
        # 2**34 = 17179869184 => should convert to int64
        # 2**10 = 1024 => should convert to int (int32 on 32-bit systems,
        #                 int64 on 64-bit systems)

        data = TextIO('73786976294838206464 17179869184 1024')

        test = np.ndfromtxt(data, dtype=None)

        assert_equal(test.dtype.names, ['f0', 'f1', 'f2'])

        assert_(test.dtype['f0'] == np.float)
        assert_(test.dtype['f1'] == np.int64)
        assert_(test.dtype['f2'] == np.integer)

        assert_allclose(test['f0'], 73786976294838206464.)
        assert_equal(test['f1'], 17179869184)
        assert_equal(test['f2'], 1024)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号