MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_numpy_int_convert

Function test_numpy_int_convert

tests/test_builtin_casters.py:363–384  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

361
362
363def test_numpy_int_convert():
364 np = pytest.importorskip("numpy")
365
366 convert, noconvert = m.int_passthrough, m.int_passthrough_noconvert
367
368 def require_implicit(v):
369 pytest.raises(TypeError, noconvert, v)
370
371 # `np.intc` is an alias that corresponds to a C++ `int`
372 assert convert(np.intc(42)) == 42
373 assert noconvert(np.intc(42)) == 42
374
375 # The implicit conversion from np.float32 is undesirable but currently accepted.
376 # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
377 # TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7)
378 # https://github.com/pybind/pybind11/issues/3408
379 if (3, 8) <= sys.version_info < (3, 10) and env.CPYTHON:
380 with pytest.deprecated_call():
381 assert convert(np.float32(3.14159)) == 3
382 else:
383 assert convert(np.float32(3.14159)) == 3
384 require_implicit(np.float32(3.14159))
385
386
387def test_tuple(doc):

Callers

nothing calls this directly

Calls 1

require_implicitFunction · 0.85

Tested by

no test coverage detected