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

Method test_repr

xarray/tests/test_dataset.py:281–342  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

279
280class TestDataset:
281 def test_repr(self) -> None:
282 data = create_test_data(seed=123, use_extension_array=True)
283 data.attrs["foo"] = "bar"
284 # need to insert str dtype at runtime to handle different endianness
285 var5 = (
286 "\n var5 (dim1) int64[pyarrow] 64B 5 9 7 2 6 2 8 1"
287 if has_pyarrow
288 else ""
289 )
290 expected = dedent(
291 f"""\
292 <xarray.Dataset> Size: 2kB
293 Dimensions: (dim2: 9, dim3: 10, time: 20, dim1: 8)
294 Coordinates:
295 * dim2 (dim2) float64 72B 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0
296 * dim3 (dim3) {data["dim3"].dtype} 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j'
297 numbers (dim3) int64 80B 0 1 2 0 0 1 1 2 2 3
298 * time (time) datetime64[ns] 160B 2000-01-01 2000-01-02 ... 2000-01-20
299 Dimensions without coordinates: dim1
300 Data variables:
301 var1 (dim1, dim2) float64 576B -0.9891 -0.3678 1.288 ... -0.2116 0.364
302 var2 (dim1, dim2) float64 576B 0.953 1.52 1.704 ... 0.1347 -0.6423
303 var3 (dim3, dim1) float64 640B 0.4107 0.9941 0.1665 ... 0.716 1.555
304 var4 (dim1) category 3{6 if Version(pd.__version__) >= Version("3.0.0dev0") else 2}B b c b a c a c a{var5}
305 Attributes:
306 foo: bar"""
307 )
308 actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
309
310 assert expected == actual
311
312 with set_options(display_width=100):
313 max_len = max(map(len, repr(data).split("\n")))
314 assert 90 < max_len < 100
315
316 expected = dedent(
317 """\
318 <xarray.Dataset> Size: 0B
319 Dimensions: ()
320 Data variables:
321 *empty*"""
322 )
323 actual = "\n".join(x.rstrip() for x in repr(Dataset()).split("\n"))
324 print(actual)
325 assert expected == actual
326
327 # verify that ... doesn't appear for scalar coordinates
328 data = Dataset({"foo": ("x", np.ones(10))}).mean()
329 expected = dedent(
330 """\
331 <xarray.Dataset> Size: 8B
332 Dimensions: ()
333 Data variables:
334 foo float64 8B 1.0"""
335 )
336 actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
337 print(actual)
338 assert expected == actual

Callers

nothing calls this directly

Calls 7

create_test_dataFunction · 0.90
set_optionsClass · 0.90
DatasetClass · 0.90
rstripMethod · 0.80
splitMethod · 0.80
joinMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected