Repository: numpy/numpy
File: numpy/_core/tests/test_multiarray.py (Python)

Code before:
        assert_c(a.copy())
        assert_c(a.copy('C'))
        assert_fortran(a.copy('F'))
        assert_fortran(a.copy('A'))

        # Now test starting with a C array.
        a = np.empty((2, 2), order='C')
        assert_c(a.copy())
        assert_c(a.copy('C'))
        assert_fortran(a.copy('F'))
        assert_c(a.copy('A'))

    @pytest.mark.parametrize("dtype", ['O', np.int32, 'i,O'])
    def test__deepcopy__(self, dtype):
        # Force the entry of NULLs into array
        a = np.empty(4, dtype=dtype)
        ctypes.memset(a.ctypes.data, 0, a.nbytes)

        # Ensure no error is raised, see gh-21833
        b = a.__deepcopy__({})

        a[0] = 42
        with pytest.raises(AssertionError):
            assert_array_equal(a, b)

    def test__deepcopy___void_scalar(self, dtype):
        # see comments in gh-29643
        value = np.void('Rex', dtype=[('name', 'U10')])
        value_deepcopy = value.__deepcopy__(None)
        value[0] = None
        assert value_deepcopy[0] == 'Rex'

    @pytest.mark.parametrize("sctype", [np.int64, np.float32, np.float64])
    def test__deepcopy__scalar(self, sctype):
        # test optimization from gh-29656
        value = sctype(1.1)
        value_deepcopy = value.__deepcopy__(None)
        assert value is value_deepcopy

    def test__deepcopy__catches_failure(self):
        class MyObj:
            def __deepcopy__(self, *args, **kwargs):
                raise RuntimeError

        arr = np.array([1, MyObj(), 3], dtype='O')
        with pytest.raises(RuntimeError):
            arr.__deepcopy__({})

    def test_sort_order(self):
        # Test sorting an array with fields
        x1 = np.array([21, 32, 14])

Review comment (suggestion):
```suggestion
    def test__deepcopy___void_scalar(self):
```

Code after:
        assert_c(a.copy())
        assert_c(a.copy('C'))
        assert_fortran(a.copy('F'))
        assert_fortran(a.copy('A'))

        # Now test starting with a C array.
        a = np.empty((2, 2), order='C')
        assert_c(a.copy())
        assert_c(a.copy('C'))
        assert_fortran(a.copy('F'))
        assert_c(a.copy('A'))

    @pytest.mark.parametrize("dtype", ['O', np.int32, 'i,O'])
    def test__deepcopy__(self, dtype):
        # Force the entry of NULLs into array
        a = np.empty(4, dtype=dtype)
        ctypes.memset(a.ctypes.data, 0, a.nbytes)

        # Ensure no error is raised, see gh-21833
        b = a.__deepcopy__({})

        a[0] = 42
        with pytest.raises(AssertionError):
            assert_array_equal(a, b)

    def test__deepcopy___void_scalar(self):
        # see comments in gh-29643
        value = np.void('Rex', dtype=[('name', 'U10')])
        value_deepcopy = value.__deepcopy__(None)
        value[0] = None
        assert value_deepcopy[0] == 'Rex'

    @pytest.mark.parametrize("sctype", [np.int64, np.float32, np.float64])
    def test__deepcopy__scalar(self, sctype):
        # test optimization from gh-29656
        value = sctype(1.1)
        value_deepcopy = value.__deepcopy__(None)
        assert value is value_deepcopy

    def test__deepcopy__catches_failure(self):
        class MyObj:
            def __deepcopy__(self, *args, **kwargs):
                raise RuntimeError

        arr = np.array([1, MyObj(), 3], dtype='O')
        with pytest.raises(RuntimeError):
            arr.__deepcopy__({})

    def test_sort_order(self):
        # Test sorting an array with fields
        x1 = np.array([21, 32, 14])