MCPcopy
hub / github.com/pydata/xarray / test_roundtrip_character_array

Method test_roundtrip_character_array

xarray/tests/test_backends.py:1853–1869  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1851 assert_identical(expected, actual)
1852
1853 def test_roundtrip_character_array(self) -> None:
1854 with create_tmp_file() as tmp_file:
1855 values = np.array([["a", "b", "c"], ["d", "e", "f"]], dtype="S")
1856
1857 with nc4.Dataset(tmp_file, mode="w") as nc:
1858 nc.createDimension("x", 2)
1859 nc.createDimension("string3", 3)
1860 v = nc.createVariable("x", np.dtype("S1"), ("x", "string3"))
1861 v[:] = values
1862
1863 values = np.array(["abc", "def"], dtype="S")
1864 expected = Dataset({"x": ("x", values)})
1865 with open_dataset(tmp_file) as actual:
1866 assert_identical(expected, actual)
1867 # regression test for #157
1868 with self.roundtrip(actual) as roundtripped:
1869 assert_identical(expected, roundtripped)
1870
1871 def test_default_to_char_arrays(self) -> None:
1872 data = Dataset({"x": np.array(["foo", "zzzz"], dtype="S")})

Callers

nothing calls this directly

Calls 6

DatasetClass · 0.90
open_datasetFunction · 0.90
assert_identicalFunction · 0.90
create_tmp_fileFunction · 0.85
dtypeMethod · 0.45
roundtripMethod · 0.45

Tested by

no test coverage detected