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

Method test_repr_multiindex

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

Source from the content-addressed store, hash-verified

342 assert len(repr(data)) < 1000
343
344 def test_repr_multiindex(self) -> None:
345 data = create_test_multiindex()
346 obj_size = np.dtype("O").itemsize
347 expected = dedent(
348 f"""\
349 <xarray.Dataset> Size: {8 * obj_size + 32}B
350 Dimensions: (x: 4)
351 Coordinates:
352 * x (x) object {4 * obj_size}B MultiIndex
353 * level_1 (x) object {4 * obj_size}B 'a' 'a' 'b' 'b'
354 * level_2 (x) int64 32B 1 2 1 2
355 Data variables:
356 *empty*"""
357 )
358 actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
359 print(actual)
360 assert expected == actual
361
362 # verify that long level names are not truncated
363 midx = pd.MultiIndex.from_product(
364 [["a", "b"], [1, 2]], names=("a_quite_long_level_name", "level_2")
365 )
366 midx_coords = Coordinates.from_pandas_multiindex(midx, "x")
367 data = Dataset({}, midx_coords)
368 expected = dedent(
369 f"""\
370 <xarray.Dataset> Size: {8 * obj_size + 32}B
371 Dimensions: (x: 4)
372 Coordinates:
373 * x (x) object {4 * obj_size}B MultiIndex
374 * a_quite_long_level_name (x) object {4 * obj_size}B 'a' 'a' 'b' 'b'
375 * level_2 (x) int64 32B 1 2 1 2
376 Data variables:
377 *empty*"""
378 )
379 actual = "\n".join(x.rstrip() for x in repr(data).split("\n"))
380 print(actual)
381 assert expected == actual
382
383 def test_repr_period_index(self) -> None:
384 data = create_test_data(seed=456)

Callers

nothing calls this directly

Calls 7

DatasetClass · 0.90
create_test_multiindexFunction · 0.85
rstripMethod · 0.80
splitMethod · 0.80
dtypeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected