Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7bc2105
add tests for replication functions
keewis Nov 7, 2019
007ad7b
add tests for `xarray.dot`
keewis Nov 7, 2019
4f6daf2
Merge branch 'master' into tests-for-toplevel-functions-with-units
keewis Nov 7, 2019
c1407e2
add tests for apply_ufunc
keewis Nov 7, 2019
a21c872
explicitly set the test ids to repr
keewis Nov 7, 2019
9abb729
add tests for align
keewis Nov 7, 2019
4664630
cover a bit more of align
keewis Nov 8, 2019
3ecdb35
add tests for broadcast
keewis Nov 8, 2019
cf75525
black changed how tuple unpacking should look like
keewis Nov 8, 2019
b79d961
correct the xfail message for full_like tests
keewis Nov 8, 2019
6b6729e
add tests for where
keewis Nov 8, 2019
93b003c
add tests for concat
keewis Nov 8, 2019
f8351ec
add tests for combine_by_coords
keewis Nov 8, 2019
a1cecdc
Merge branch 'master' into tests-for-toplevel-functions-with-units
keewis Nov 9, 2019
eb8fe4e
fix a bug in convert_units
keewis Nov 9, 2019
f9f727e
convert the align results to the same units
keewis Nov 9, 2019
3d0dfb1
rename the combine_by_coords test
keewis Nov 9, 2019
2e426a3
convert the units for expected in combine_by_coords
keewis Nov 9, 2019
341ffbc
add tests for combine_nested
keewis Nov 9, 2019
a474203
add tests for merge with datasets
keewis Nov 9, 2019
61627f0
only use three datasets for merging
keewis Nov 10, 2019
d989ae8
add tests for merge with dataarrays
keewis Nov 10, 2019
c1d8e92
update whats-new.rst
keewis Nov 10, 2019
2c6e604
Merge branch 'master' into tests-for-toplevel-functions-with-units
keewis Nov 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for merge with dataarrays
  • Loading branch information
keewis committed Nov 10, 2019
commit d989ae825993ce4e3affb3de268df73b6dd6fc88
90 changes: 90 additions & 0 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,96 @@ def test_concat_dataset(variant, unit, error, dtype):
assert_equal_with_units(expected, result)


@pytest.mark.xfail(reason="blocked by `where`")
@pytest.mark.parametrize(
"unit,error",
(
pytest.param(1, DimensionalityError, id="no_unit"),
pytest.param(
unit_registry.dimensionless, DimensionalityError, id="dimensionless"
),
pytest.param(unit_registry.s, DimensionalityError, id="incompatible_unit"),
pytest.param(unit_registry.mm, None, id="compatible_unit"),
pytest.param(unit_registry.m, None, id="identical_unit"),
),
ids=repr,
)
@pytest.mark.parametrize(
"variant",
(
"data",
pytest.param("dims", marks=pytest.mark.xfail(reason="indexes strip units")),
"coords",
),
)
def test_merge_dataarray(variant, unit, error, dtype):
original_unit = unit_registry.m

variants = {
"data": (unit, original_unit, original_unit),
"dims": (original_unit, unit, original_unit),
"coords": (original_unit, original_unit, unit),
}
data_unit, dim_unit, coord_unit = variants.get(variant)

array1 = np.linspace(0, 1, 2 * 3).reshape(2, 3).astype(dtype) * original_unit
array2 = np.linspace(1, 2, 2 * 4).reshape(2, 4).astype(dtype) * data_unit
array3 = np.linspace(0, 2, 3 * 4).reshape(3, 4).astype(dtype) * data_unit

x = np.arange(2) * original_unit
y = np.arange(3) * original_unit
z = np.arange(4) * original_unit
u = np.linspace(10, 20, 2) * original_unit
v = np.linspace(10, 20, 3) * original_unit
w = np.linspace(10, 20, 4) * original_unit

arr1 = xr.DataArray(
name="a",
data=array1,
coords={"x": x, "y": y, "u": ("x", u), "v": ("y", v)},
dims=("x", "y"),
)
arr2 = xr.DataArray(
name="b",
data=array2,
coords={
"x": np.arange(2, 4) * dim_unit,
"z": z,
"u": ("x", np.linspace(20, 30, 2) * coord_unit),
"w": ("z", w),
},
dims=("x", "z"),
)
arr3 = xr.DataArray(
name="c",
data=array3,
coords={
"y": np.arange(3, 6) * dim_unit,
"z": np.arange(4, 8) * dim_unit,
"v": ("y", np.linspace(10, 20, 3) * coord_unit),
"w": ("z", np.linspace(10, 20, 4) * coord_unit),
},
dims=("y", "z"),
)

func = function(xr.merge)
if error is not None:
with pytest.raises(error):
func([arr1, arr2, arr3])

return

units = {name: original_unit for name in list("abcuvwxyz")}
convert_and_strip = lambda arr: strip_units(convert_units(arr, units))
expected = attach_units(
func([strip_units(arr1), convert_and_strip(arr2), convert_and_strip(arr3)]),
units,
)
result = func([arr1, arr2, arr3])

assert_equal_with_units(expected, result)


@pytest.mark.xfail(reason="blocked by `where`")
@pytest.mark.parametrize(
"unit,error",
Expand Down