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

Function test_align_dataarray

xarray/tests/test_units.py:483–560  ·  view source on GitHub ↗
(value, variant, unit, error, dtype)

Source from the content-addressed store, hash-verified

481)
482@pytest.mark.parametrize("value", (10, dtypes.NA))
483def test_align_dataarray(value, variant, unit, error, dtype):
484 if variant == "coords" and (
485 value != dtypes.NA or isinstance(unit, unit_registry.Unit)
486 ):
487 pytest.xfail(
488 reason=(
489 "fill_value is used for both data variables and coords. "
490 "See https://github.com/pydata/xarray/issues/4165"
491 )
492 )
493
494 fill_value = dtypes.get_fill_value(dtype) if value == dtypes.NA else value
495
496 original_unit = unit_registry.m
497
498 variants = {
499 "data": ((original_unit, unit), (1, 1), (1, 1)),
500 "dims": ((1, 1), (original_unit, unit), (1, 1)),
501 "coords": ((1, 1), (1, 1), (original_unit, unit)),
502 }
503 (
504 (data_unit1, data_unit2),
505 (dim_unit1, dim_unit2),
506 (coord_unit1, coord_unit2),
507 ) = variants[variant]
508
509 array1 = np.linspace(0, 10, 2 * 5).reshape(2, 5).astype(dtype) * data_unit1
510 array2 = np.linspace(0, 8, 2 * 5).reshape(2, 5).astype(dtype) * data_unit2
511
512 x = np.arange(2) * dim_unit1
513 y1 = np.arange(5) * dim_unit1
514 y2 = np.arange(2, 7) * dim_unit2
515
516 u1 = np.array([3, 5, 7, 8, 9]) * coord_unit1
517 u2 = np.array([7, 8, 9, 11, 13]) * coord_unit2
518
519 coords1 = {"x": x, "y": y1}
520 coords2 = {"x": x, "y": y2}
521 if variant == "coords":
522 coords1["y_a"] = ("y", u1)
523 coords2["y_a"] = ("y", u2)
524
525 data_array1 = xr.DataArray(data=array1, coords=coords1, dims=("x", "y"))
526 data_array2 = xr.DataArray(data=array2, coords=coords2, dims=("x", "y"))
527
528 fill_value = fill_value * data_unit2
529 func = function(xr.align, join="outer", fill_value=fill_value)
530 if error is not None and (value != dtypes.NA or isinstance(fill_value, Quantity)):
531 with pytest.raises(error):
532 func(data_array1, data_array2)
533
534 return
535
536 stripped_kwargs = {
537 key: strip_units(
538 convert_units(value, {None: data_unit1 if data_unit2 != 1 else None})
539 )
540 for key, value in func.kwargs.items()

Callers

nothing calls this directly

Calls 12

assert_allcloseFunction · 0.90
functionClass · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
itemsMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…