docstr: Signed integers are currently different in that they do not cast other
  NumPy scalar, but instead use scalar.__int__(). The hardcoded
  exception to this rule is `np.array(scalar, dtype=integer)`.
docstr_tok: ["Signed","integers","are","currently","different","in","that","they","do","not","cast","other","NumPy","scalar",",","but","instead","use","scalar.__int__","(",")",".","The","hardcoded","exception","to","this","rule","is","`","np.array","(","scalar",",","dtype=integer",")","`","."]
code: def test_scalar_to_int_coerce_does_not_cast(
      self, dtype, scalar, error
  ):
      """
      Signed integers are currently different in that they do not cast other
      NumPy scalar, but instead use scalar.__int__(). The hardcoded
      exception to this rule is `np.array(scalar, dtype=integer)`.
      """
      dtype = np.dtype(dtype)
  
      # This is a special case using casting logic. It warns for the NaN
      # but allows the cast (giving undefined behaviour).
      with np.errstate(invalid="ignore"):
          coerced = np.array(scalar, dtype=dtype)
          cast = np.array(scalar).astype(dtype)
      assert_array_equal(coerced, cast)
  
      # However these fail:
      with pytest.raises(error):
          np.array([scalar], dtype=dtype)
      with pytest.raises(error):
          cast[()] = scalar
  
imports: from itertools import permutations, product
  import pytest
  from pytest import param
  import numpy
  from numpy.core._rational_tests import rational
  from numpy.core._multiarray_umath import _discover_array_parameters
  from numpy.testing import assert_array_equal, assert_warns, IS_PYPY
label_desc: Use image node_id 11 for calling the TestScalarDiscovery obj's underlying member method code with example usage: obj.test_scalar_to_int_coerce_does_not_cast(dtype, scalar, error) without return types