def spmatrix(self, D, **kwargs):
        construct = super(_NonCanonicalMixin, self).spmatrix
        M = construct(D, **kwargs)

        zero_pos = (M.A == 0).nonzero()
        has_zeros = (zero_pos[0].size > 0)
        if has_zeros:
            k = zero_pos[0].size//2
            M = self._insert_explicit_zero(M,
                                           zero_pos[0][k],
                                           zero_pos[1][k])

        arg1 = self._arg1_for_noncanonical(M)
        if 'shape' not in kwargs:
            kwargs['shape'] = M.shape
        NC = construct(arg1, **kwargs)

        # check that result is valid
        if NC.dtype in [np.float32, np.complex64]:
            # For single-precision floats, the differences between M and NC
            # that are introduced by the extra operations involved in the
            # construction of NC necessitate a more lenient tolerance level
            # than the default.
            rtol = 1e-05
        else:
            rtol = 1e-07
        assert_allclose(NC.A, M.A, rtol=rtol)

        # check that at least one explicit zero
        if has_zeros:
            assert_((NC.data == 0).any())

        return NC
Replace D with a non-canonical equivalent: containing
dataset/ETHPy150Open scipy/scipy/scipy/sparse/tests/test_base.py/_NonCanonicalMixin.spmatrix