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

Function _assert_valid_xy

xarray/plot/utils.py:435–455  ·  view source on GitHub ↗

make sure x and y passed to plotting functions are valid

(
    darray: DataArray | Dataset, xy: Hashable | None, name: str
)

Source from the content-addressed store, hash-verified

433
434# TODO: Can by used to more than x or y, rename?
435def _assert_valid_xy(
436 darray: DataArray | Dataset, xy: Hashable | None, name: str
437) -> None:
438 """
439 make sure x and y passed to plotting functions are valid
440 """
441
442 # MultiIndex cannot be plotted; no point in allowing them here
443 multiindex_dims = {
444 idx.dim
445 for idx in darray.xindexes.get_unique()
446 if isinstance(idx, PandasMultiIndex)
447 }
448
449 valid_xy = (set(darray.dims) | set(darray.coords)) - multiindex_dims
450
451 if (xy is not None) and (xy not in valid_xy):
452 valid_xy_str = "', '".join(sorted(str(v) for v in valid_xy))
453 raise ValueError(
454 f"{name} must be one of None, '{valid_xy_str}'. Received '{xy}' instead."
455 )
456
457
458def get_axis(

Callers 4

_infer_line_dataFunction · 0.90
test_assert_valid_xyFunction · 0.90
_infer_xy_labelsFunction · 0.85
_guess_coords_to_plotFunction · 0.85

Calls 2

get_uniqueMethod · 0.80
joinMethod · 0.45

Tested by 1

test_assert_valid_xyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…