'Test that setitem changes the unit if needed (or ignores it for
values where that is allowed; viz., #2695)'

def test_slice(self):

    q2 = ((np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) * u.km) / u.m)
    q1 = q2.copy()
    q2[(0, 0)] = 10000.0
    assert (q2.unit == q1.unit)
    assert (q2[(0, 0)].value == 10.0)
    q2[0] = ((9.0 * u.Mm) / u.km)
    assert all((q2.flatten()[:3].value == np.array([9.0, 9.0, 9.0])))
    q2[0, :(-1)] = 8000.0
    assert all((q2.flatten()[:3].value == np.array([8.0, 8.0, 9.0])))
    with pytest.raises(u.UnitsError):
        q2[(1, 1)] = (10 * u.s)
    q3 = u.Quantity(np.arange(10.0), 'm/s')
    q3[5] = ((100.0 * u.cm) / u.s)
    assert (q3[5].value == 1.0)
    q3[5] = 0.0
    assert (q3[5] == 0.0)
    q3[5] = np.inf
    assert np.isinf(q3[5])
    q3[5] = np.nan
    assert np.isnan(q3[5])
