MCPcopy Index your code
hub / github.com/pydata/xarray / test_getitem_basic

Method test_getitem_basic

xarray/tests/test_variable.py:1400–1447  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1398 assert_array_equal(v.values, np.ones((10, 11)))
1399
1400 def test_getitem_basic(self):
1401 v = self.cls(["x", "y"], [[0, 1, 2], [3, 4, 5]])
1402
1403 # int argument
1404 v_new = v[0]
1405 assert v_new.dims == ("y",)
1406 assert_array_equal(v_new, v._data[0])
1407
1408 # slice argument
1409 v_new = v[:2]
1410 assert v_new.dims == ("x", "y")
1411 assert_array_equal(v_new, v._data[:2])
1412
1413 # list arguments
1414 v_new = v[[0]]
1415 assert v_new.dims == ("x", "y")
1416 assert_array_equal(v_new, v._data[[0]]) # type: ignore[call-overload]
1417
1418 v_new = v[[]]
1419 assert v_new.dims == ("x", "y")
1420 assert_array_equal(v_new, v._data[[]]) # type: ignore[call-overload]
1421
1422 # dict arguments
1423 v_new = v[dict(x=0)]
1424 assert v_new.dims == ("y",)
1425 assert_array_equal(v_new, v._data[0])
1426
1427 v_new = v[dict(x=0, y=slice(None))]
1428 assert v_new.dims == ("y",)
1429 assert_array_equal(v_new, v._data[0])
1430
1431 v_new = v[dict(x=0, y=1)]
1432 assert v_new.dims == ()
1433 assert_array_equal(v_new, v._data[0, 1])
1434
1435 v_new = v[dict(y=1)]
1436 assert v_new.dims == ("x",)
1437 assert_array_equal(v_new, v._data[:, 1])
1438
1439 # tuple argument
1440 v_new = v[(slice(None), 1)]
1441 assert v_new.dims == ("x",)
1442 assert_array_equal(v_new, v._data[:, 1])
1443
1444 # test that we obtain a modifiable view when taking a 0d slice
1445 v_new = v[0, 0]
1446 v_new[...] += 99
1447 assert_array_equal(v_new, v._data[0, 0])
1448
1449 def test_getitem_with_mask_2d_input(self):
1450 v = Variable(("x", "y"), [[0, 1, 2], [3, 4, 5]])

Callers

nothing calls this directly

Calls 1

clsMethod · 0.95

Tested by

no test coverage detected