code: def test_coercion_assignment_datetime(self, val, unit, dtype):
      # String from datetime64 assignment is currently special cased to
      # never use casting.  This is because casting will error in this
      # case, and traditionally in most cases the behaviour is maintained
      # like this.  (`np.array(scalar, dtype="U6")` would have failed before)
      # TODO: This discrepancy _should_ be resolved, either by relaxing the
      #       cast, or by deprecating the first part.
      scalar = np.datetime64(val, unit)
      dtype = np.dtype(dtype)
      cut_string = dtype.type(str(scalar)[:6])
  
      arr = np.array(scalar, dtype=dtype)
      assert arr[()] == cut_string
      ass = np.ones((), dtype=dtype)
      ass[()] = scalar
      assert ass[()] == cut_string
  
      with pytest.raises(RuntimeError):
          # However, unlike the above assignment using `str(scalar)[:6]`
          # due to being handled by the string DType and not be casting
          # the explicit cast fails:
          np.array(scalar).astype(dtype)
  
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 3 for calling the TestTimeScalars obj's underlying member method code with example usage: obj.test_coercion_assignment_datetime(val, unit, dtype) without return types