Skip to content

Pyth 3.8.0a3 DeprecationWarning: an integer is required (got type float) #13412

@hroncok

Description

@hroncok

Hi, when I build numpy 1.16.3 in Fedora with Python 3.8.0a3,
I get the following test failures with DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

On

ln = PyInt_AsLong(n)

And

lngood = PyInt_AsLong(ngood)
lnbad = PyInt_AsLong(nbad)
lnsample = PyInt_AsLong(nsample)

Reproducing code example:

$ python3.8 -m pytest -v --pyargs numpy -k 'not big_arrays and not large_archive and not test_highest_available_pickle_protocol'
# the deselects are not important, just having them here for completeness 
Details

Error message:

=================================== FAILURES ===================================
_________________________ TestRandomDist.test_binomial _________________________

self = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7bc2df0>

    def test_binomial(self):
        np.random.seed(self.seed)
>       actual = np.random.binomial(100.123, .456, size=(3, 2))

self       = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7bc2df0>

../../../BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/tests/test_random.py:518: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

Lock       = <built-in function allocate_lock>
RandomState = <class 'mtrand.RandomState'>
__builtins__ = <builtins>
__doc__    = None
__file__   = '/builddir/build/BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/mtrand.cpython-38m-x86_64-linux-gnu.so'
__loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fc7c4486760>
__name__   = 'numpy.random.mtrand'
__package__ = 'numpy.random'
__path__   = None
__spec__   = ModuleSpec(name='numpy.random.mtrand', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fc7c4486760...ROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/mtrand.cpython-38m-x86_64-linux-gnu.so')
__test__   = {'RandomState.binomial (line 3706)': '\n        binomial(n, p, size=None)\n\n        Draw samples from a binomial dist...0.3])\n        array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],\n              dtype='|S11')\n\n        ", ...}
_rand      = <mtrand.RandomState object at 0x7fc7c4415400>
_rand_bool = <built-in function _rand_bool>
_rand_int16 = <built-in function _rand_int16>
_rand_int32 = <built-in function _rand_int32>
_rand_int64 = <built-in function _rand_int64>
_rand_int8 = <built-in function _rand_int8>
_rand_uint16 = <built-in function _rand_uint16>
_rand_uint32 = <built-in function _rand_uint32>
_rand_uint64 = <built-in function _rand_uint64>
_rand_uint8 = <built-in function _rand_uint8>
_randint_type = {dtype('bool'): (0, 2, <built-in function _rand_bool>), dtype('int8'): (-128, 128, <built-in function _rand_int8>), dt...t8'): (0, 256, <built-in function _rand_uint8>), dtype('int16'): (-32768, 32768, <built-in function _rand_int16>), ...}
_shape_from_size = <built-in function _shape_from_size>
beta       = <built-in method beta of mtrand.RandomState object at 0x7fc7c4415400>
binomial   = <built-in method binomial of mtrand.RandomState object at 0x7fc7c4415400>
bytes      = <built-in method bytes of mtrand.RandomState object at 0x7fc7c4415400>
chisquare  = <built-in method chisquare of mtrand.RandomState object at 0x7fc7c4415400>
choice     = <built-in method choice of mtrand.RandomState object at 0x7fc7c4415400>
dirichlet  = <built-in method dirichlet of mtrand.RandomState object at 0x7fc7c4415400>
exponential = <built-in method exponential of mtrand.RandomState object at 0x7fc7c4415400>
f          = <built-in method f of mtrand.RandomState object at 0x7fc7c4415400>
gamma      = <built-in method gamma of mtrand.RandomState object at 0x7fc7c4415400>
geometric  = <built-in method geometric of mtrand.RandomState object at 0x7fc7c4415400>
get_state  = <built-in method get_state of mtrand.RandomState object at 0x7fc7c4415400>
gumbel     = <built-in method gumbel of mtrand.RandomState object at 0x7fc7c4415400>
hypergeometric = <built-in method hypergeometric of mtrand.RandomState object at 0x7fc7c4415400>
laplace    = <built-in method laplace of mtrand.RandomState object at 0x7fc7c4415400>
logistic   = <built-in method logistic of mtrand.RandomState object at 0x7fc7c4415400>
lognormal  = <built-in method lognormal of mtrand.RandomState object at 0x7fc7c4415400>
logseries  = <built-in method logseries of mtrand.RandomState object at 0x7fc7c4415400>
multinomial = <built-in method multinomial of mtrand.RandomState object at 0x7fc7c4415400>
multivariate_normal = <built-in method multivariate_normal of mtrand.RandomState object at 0x7fc7c4415400>
negative_binomial = <built-in method negative_binomial of mtrand.RandomState object at 0x7fc7c4415400>
noncentral_chisquare = <built-in method noncentral_chisquare of mtrand.RandomState object at 0x7fc7c4415400>
noncentral_f = <built-in method noncentral_f of mtrand.RandomState object at 0x7fc7c4415400>
normal     = <built-in method normal of mtrand.RandomState object at 0x7fc7c4415400>
np         = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/__init__.py'>
operator   = <module 'operator' from '/usr/lib64/python3.8/operator.py'>
pareto     = <built-in method pareto of mtrand.RandomState object at 0x7fc7c4415400>
permutation = <built-in method permutation of mtrand.RandomState object at 0x7fc7c4415400>
poisson    = <built-in method poisson of mtrand.RandomState object at 0x7fc7c4415400>
power      = <built-in method power of mtrand.RandomState object at 0x7fc7c4415400>
rand       = <built-in method rand of mtrand.RandomState object at 0x7fc7c4415400>
randint    = <built-in method randint of mtrand.RandomState object at 0x7fc7c4415400>
randn      = <built-in method randn of mtrand.RandomState object at 0x7fc7c4415400>
random_integers = <built-in method random_integers of mtrand.RandomState object at 0x7fc7c4415400>
random_sample = <built-in method random_sample of mtrand.RandomState object at 0x7fc7c4415400>
rayleigh   = <built-in method rayleigh of mtrand.RandomState object at 0x7fc7c4415400>
seed       = <built-in method seed of mtrand.RandomState object at 0x7fc7c4415400>
set_state  = <built-in method set_state of mtrand.RandomState object at 0x7fc7c4415400>
shuffle    = <built-in method shuffle of mtrand.RandomState object at 0x7fc7c4415400>
standard_cauchy = <built-in method standard_cauchy of mtrand.RandomState object at 0x7fc7c4415400>
standard_exponential = <built-in method standard_exponential of mtrand.RandomState object at 0x7fc7c4415400>
standard_gamma = <built-in method standard_gamma of mtrand.RandomState object at 0x7fc7c4415400>
standard_normal = <built-in method standard_normal of mtrand.RandomState object at 0x7fc7c4415400>
standard_t = <built-in method standard_t of mtrand.RandomState object at 0x7fc7c4415400>
triangular = <built-in method triangular of mtrand.RandomState object at 0x7fc7c4415400>
uniform    = <built-in method uniform of mtrand.RandomState object at 0x7fc7c4415400>
vonmises   = <built-in method vonmises of mtrand.RandomState object at 0x7fc7c4415400>
wald       = <built-in method wald of mtrand.RandomState object at 0x7fc7c4415400>
warnings   = <module 'warnings' from '/usr/lib64/python3.8/warnings.py'>
weibull    = <built-in method weibull of mtrand.RandomState object at 0x7fc7c4415400>
zipf       = <built-in method zipf of mtrand.RandomState object at 0x7fc7c4415400>

mtrand.pyx:3800: DeprecationWarning
______________________ TestRandomDist.test_hypergeometric ______________________

self = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7bd8250>

    def test_hypergeometric(self):
        np.random.seed(self.seed)
>       actual = np.random.hypergeometric(10.1, 5.5, 14, size=(3, 2))

self       = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7bd8250>

../../../BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/tests/test_random.py:615: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.

Lock       = <built-in function allocate_lock>
RandomState = <class 'mtrand.RandomState'>
__builtins__ = <builtins>
__doc__    = None
__file__   = '/builddir/build/BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/mtrand.cpython-38m-x86_64-linux-gnu.so'
__loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fc7c4486760>
__name__   = 'numpy.random.mtrand'
__package__ = 'numpy.random'
__path__   = None
__spec__   = ModuleSpec(name='numpy.random.mtrand', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fc7c4486760...ROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/mtrand.cpython-38m-x86_64-linux-gnu.so')
__test__   = {'RandomState.binomial (line 3706)': '\n        binomial(n, p, size=None)\n\n        Draw samples from a binomial dist...0.3])\n        array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'],\n              dtype='|S11')\n\n        ", ...}
_rand      = <mtrand.RandomState object at 0x7fc7c4415400>
_rand_bool = <built-in function _rand_bool>
_rand_int16 = <built-in function _rand_int16>
_rand_int32 = <built-in function _rand_int32>
_rand_int64 = <built-in function _rand_int64>
_rand_int8 = <built-in function _rand_int8>
_rand_uint16 = <built-in function _rand_uint16>
_rand_uint32 = <built-in function _rand_uint32>
_rand_uint64 = <built-in function _rand_uint64>
_rand_uint8 = <built-in function _rand_uint8>
_randint_type = {dtype('bool'): (0, 2, <built-in function _rand_bool>), dtype('int8'): (-128, 128, <built-in function _rand_int8>), dt...t8'): (0, 256, <built-in function _rand_uint8>), dtype('int16'): (-32768, 32768, <built-in function _rand_int16>), ...}
_shape_from_size = <built-in function _shape_from_size>
beta       = <built-in method beta of mtrand.RandomState object at 0x7fc7c4415400>
binomial   = <built-in method binomial of mtrand.RandomState object at 0x7fc7c4415400>
bytes      = <built-in method bytes of mtrand.RandomState object at 0x7fc7c4415400>
chisquare  = <built-in method chisquare of mtrand.RandomState object at 0x7fc7c4415400>
choice     = <built-in method choice of mtrand.RandomState object at 0x7fc7c4415400>
dirichlet  = <built-in method dirichlet of mtrand.RandomState object at 0x7fc7c4415400>
exponential = <built-in method exponential of mtrand.RandomState object at 0x7fc7c4415400>
f          = <built-in method f of mtrand.RandomState object at 0x7fc7c4415400>
gamma      = <built-in method gamma of mtrand.RandomState object at 0x7fc7c4415400>
geometric  = <built-in method geometric of mtrand.RandomState object at 0x7fc7c4415400>
get_state  = <built-in method get_state of mtrand.RandomState object at 0x7fc7c4415400>
gumbel     = <built-in method gumbel of mtrand.RandomState object at 0x7fc7c4415400>
hypergeometric = <built-in method hypergeometric of mtrand.RandomState object at 0x7fc7c4415400>
laplace    = <built-in method laplace of mtrand.RandomState object at 0x7fc7c4415400>
logistic   = <built-in method logistic of mtrand.RandomState object at 0x7fc7c4415400>
lognormal  = <built-in method lognormal of mtrand.RandomState object at 0x7fc7c4415400>
logseries  = <built-in method logseries of mtrand.RandomState object at 0x7fc7c4415400>
multinomial = <built-in method multinomial of mtrand.RandomState object at 0x7fc7c4415400>
multivariate_normal = <built-in method multivariate_normal of mtrand.RandomState object at 0x7fc7c4415400>
negative_binomial = <built-in method negative_binomial of mtrand.RandomState object at 0x7fc7c4415400>
noncentral_chisquare = <built-in method noncentral_chisquare of mtrand.RandomState object at 0x7fc7c4415400>
noncentral_f = <built-in method noncentral_f of mtrand.RandomState object at 0x7fc7c4415400>
normal     = <built-in method normal of mtrand.RandomState object at 0x7fc7c4415400>
np         = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/__init__.py'>
operator   = <module 'operator' from '/usr/lib64/python3.8/operator.py'>
pareto     = <built-in method pareto of mtrand.RandomState object at 0x7fc7c4415400>
permutation = <built-in method permutation of mtrand.RandomState object at 0x7fc7c4415400>
poisson    = <built-in method poisson of mtrand.RandomState object at 0x7fc7c4415400>
power      = <built-in method power of mtrand.RandomState object at 0x7fc7c4415400>
rand       = <built-in method rand of mtrand.RandomState object at 0x7fc7c4415400>
randint    = <built-in method randint of mtrand.RandomState object at 0x7fc7c4415400>
randn      = <built-in method randn of mtrand.RandomState object at 0x7fc7c4415400>
random_integers = <built-in method random_integers of mtrand.RandomState object at 0x7fc7c4415400>
random_sample = <built-in method random_sample of mtrand.RandomState object at 0x7fc7c4415400>
rayleigh   = <built-in method rayleigh of mtrand.RandomState object at 0x7fc7c4415400>
seed       = <built-in method seed of mtrand.RandomState object at 0x7fc7c4415400>
set_state  = <built-in method set_state of mtrand.RandomState object at 0x7fc7c4415400>
shuffle    = <built-in method shuffle of mtrand.RandomState object at 0x7fc7c4415400>
standard_cauchy = <built-in method standard_cauchy of mtrand.RandomState object at 0x7fc7c4415400>
standard_exponential = <built-in method standard_exponential of mtrand.RandomState object at 0x7fc7c4415400>
standard_gamma = <built-in method standard_gamma of mtrand.RandomState object at 0x7fc7c4415400>
standard_normal = <built-in method standard_normal of mtrand.RandomState object at 0x7fc7c4415400>
standard_t = <built-in method standard_t of mtrand.RandomState object at 0x7fc7c4415400>
triangular = <built-in method triangular of mtrand.RandomState object at 0x7fc7c4415400>
uniform    = <built-in method uniform of mtrand.RandomState object at 0x7fc7c4415400>
vonmises   = <built-in method vonmises of mtrand.RandomState object at 0x7fc7c4415400>
wald       = <built-in method wald of mtrand.RandomState object at 0x7fc7c4415400>
warnings   = <module 'warnings' from '/usr/lib64/python3.8/warnings.py'>
weibull    = <built-in method weibull of mtrand.RandomState object at 0x7fc7c4415400>
zipf       = <built-in method zipf of mtrand.RandomState object at 0x7fc7c4415400>

mtrand.pyx:4267: DeprecationWarning
_______________ TestRandomDist.test_scalar_exception_propagation _______________

self = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7a48b20>

    def test_scalar_exception_propagation(self):
        # Tests that exceptions are correctly propagated in distributions
        # when called with objects that throw exceptions when converted to
        # scalars.
        #
        # Regression test for gh: 8865
    
        class ThrowingFloat(np.ndarray):
            def __float__(self):
                raise TypeError
    
        throwing_float = np.array(1.0).view(ThrowingFloat)
        assert_raises(TypeError, np.random.uniform, throwing_float, throwing_float)
    
        class ThrowingInteger(np.ndarray):
            def __int__(self):
                raise TypeError
    
        throwing_int = np.array(1).view(ThrowingInteger)
>       assert_raises(TypeError, np.random.hypergeometric, throwing_int, 1, 1)

ThrowingFloat = <class 'numpy.random.tests.test_random.TestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingFloat'>
ThrowingInteger = <class 'numpy.random.tests.test_random.TestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingInteger'>
self       = <numpy.random.tests.test_random.TestRandomDist object at 0x7fc7b7a48b20>
throwing_float = ThrowingFloat(1.)
throwing_int = ThrowingInteger(1)

../../../BUILDROOT/numpy-1.16.3-1.fc31.x86_64/usr/lib64/python3.8/site-packages/numpy/random/tests/test_random.py:927: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.8/unittest/case.py:799: in assertRaises
    return context.handle('assertRaises', args, kwargs)
/usr/lib64/python3.8/unittest/case.py:214: in handle
    callable_obj(*args, **kwargs)
/usr/lib64/python3.8/unittest/case.py:236: in __exit__
    self._raiseFailure("{} not raised by {}".format(exc_name,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <unittest.case._AssertRaisesContext object at 0x7fc7b7a48c70>
standardMsg = 'TypeError not raised by hypergeometric'

    def _raiseFailure(self, standardMsg):
        msg = self.test_case._formatMessage(self.msg, standardMsg)
>       raise self.test_case.failureException(msg)
E       AssertionError: TypeError not raised by hypergeometric

msg        = 'TypeError not raised by hypergeometric'
self       = <unittest.case._AssertRaisesContext object at 0x7fc7b7a48c70>
standardMsg = 'TypeError not raised by hypergeometric'

/usr/lib64/python3.8/unittest/case.py:160: AssertionError
= 3 failed, 7418 passed, 84 skipped, 3 deselected, 11 xfailed, 2 xpassed in 387.48 seconds =

Numpy/Python version information:

Numpy 1.16.3

Python 3.8.0a3 (default, Apr 3 2019, 16:31:49)
[GCC 9.0.1 20190312 (Red Hat 9.0.1-0.10)]


Summary 2019-04-25 by @seberg

  • Python switches behaviour when converting to integer in the C-API (e.g. of floats). This is good news, but means we have to update some tests.

Actions needed:

  • Find tests which need fixing.
  • Update tests: For python versions newer or equal 3.8 raise DeprecationWarnings and check
    that the tests fail.
  • If the test checks anything else, fix up the test instead and create a new error path test (previous point).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions