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

Function test_slice

xarray/tests/test_accessor_str.py:2161–2176  ·  view source on GitHub ↗
(dtype)

Source from the content-addressed store, hash-verified

2159
2160
2161def test_slice(dtype) -> None:
2162 arr = xr.DataArray(["aafootwo", "aabartwo", "aabazqux"]).astype(dtype)
2163
2164 result = arr.str.slice(2, 5)
2165 exp = xr.DataArray(["foo", "bar", "baz"]).astype(dtype)
2166 assert result.dtype == exp.dtype
2167 assert_equal(result, exp)
2168
2169 for start, stop, step in [(0, 3, -1), (None, None, -1), (3, 10, 2), (3, 0, -1)]:
2170 try:
2171 result = arr.str[start:stop:step]
2172 expected = xr.DataArray([s[start:stop:step] for s in arr.values])
2173 assert_equal(result, expected.astype(dtype))
2174 except IndexError:
2175 print(f"failed on {start}:{stop}:{step}")
2176 raise
2177
2178
2179def test_slice_broadcast(dtype) -> None:

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
astypeMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…