Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New alignment option: join='strict' #8698

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bbe7d05
New alignment option: join='strict'
etienneschalk Feb 3, 2024
cddcaa1
Fix what's new newlines + retrigger CI
etienneschalk Feb 4, 2024
37a7b09
wrong join
etienneschalk Feb 4, 2024
a93e44b
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 7, 2024
ed4873e
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 9, 2024
c6b1df5
Added test align 2d three arrays
etienneschalk Feb 9, 2024
ed0414a
Added tests and use assert_identical
etienneschalk Feb 10, 2024
a8bc8dc
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 10, 2024
451c96f
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 11, 2024
f46b19b
Added tests for join=exact
etienneschalk Feb 14, 2024
95295d1
Try replacing join=strict by broadcast=False
etienneschalk Feb 15, 2024
80f5e1b
Merge branch 'eschalk/issue-8231-align' of github.com:etienneschalk/x…
etienneschalk Feb 15, 2024
d84c688
More broadcasts
etienneschalk Feb 17, 2024
06c2077
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 17, 2024
a7148d6
CI failed: mypy + warnings
etienneschalk Feb 17, 2024
3a4e81a
Review - revert useless change
etienneschalk Feb 18, 2024
4247a86
Review - missing passed down param, useless newline
etienneschalk Feb 18, 2024
9db7db1
Apply suggestions from code review
etienneschalk Feb 18, 2024
9966d4e
Merge branch 'eschalk/issue-8231-align' of github.com:etienneschalk/x…
etienneschalk Feb 18, 2024
e4d0a84
review - error message
etienneschalk Feb 18, 2024
fe56de8
Review - Use dims
etienneschalk Feb 18, 2024
e4b0cd8
param test
etienneschalk Feb 18, 2024
6a4db7b
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 18, 2024
26d7311
Remove faulty line whats-new
etienneschalk Feb 18, 2024
df8fd3a
Review - remove broadcast from apply_ufunc
etienneschalk Feb 18, 2024
651289f
Re-add missing line
etienneschalk Feb 18, 2024
5cc61b0
Merge branch 'main' into eschalk/issue-8231-align
etienneschalk Feb 24, 2024
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
1 change: 0 additions & 1 deletion xarray/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ def assert_unindexed_dim_sizes_equal(self) -> None:
)
else:
add_err_msg = ""
# Same for indexed dims?
if len(sizes) > 1:
raise ValueError(
f"cannot reindex or align along dimension {dim!r} "
Expand Down
32 changes: 27 additions & 5 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,7 @@ def test_align_str_dtype(self) -> None:
assert_identical(expected_b, actual_b)
assert expected_b.x.dtype == actual_b.x.dtype

def test_align_exact_vs_strict(self) -> None:
def test_align_exact_vs_strict_one_element(self) -> None:
xda_1 = xr.DataArray([1], dims="x1")
xda_2 = xr.DataArray([1], dims="x2")

Expand All @@ -3206,14 +3206,36 @@ def test_align_exact_vs_strict(self) -> None:
# join='strict' fails because of non-matching dimensions' names
with pytest.raises(
ValueError,
match=(
r"cannot align objects with join='strict' "
r"because given objects do not share the same dimension names "
r"([('x1',), ('x2',)])"
match=re.escape(
"cannot align objects with join='strict' "
"because given objects do not share the same dimension names "
"([('x1',), ('x2',)])"
),
):
xr.align(xda_1, xda_2, join="strict")

def test_align_exact_vs_strict_2d(self) -> None:
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
xda_1 = xr.DataArray([[1, 2, 3], [4, 5, 6]], dims=("y1", "x1"))
xda_2 = xr.DataArray([[1, 2, 3], [4, 5, 6]], dims=("y2", "x2"))
xda_3 = xr.DataArray([[1, 2, 3], [4, 5, 6]], dims=("y3", "x3"))

# join='exact' passes
aligned_1, aligned_2, aligned_3 = xr.align(xda_1, xda_2, xda_3, join="exact")
assert (aligned_1 == xda_1).all()
assert (aligned_2 == xda_2).all()
assert (aligned_3 == xda_3).all()

# join='strict' fails because of non-matching dimensions' names
with pytest.raises(
ValueError,
match=re.escape(
"cannot align objects with join='strict' "
"because given objects do not share the same dimension names "
"([('y1', 'x1'), ('y2', 'x2'), ('y3', 'x3')])"
),
):
xr.align(xda_1, xda_2, xda_3, join="strict")

def test_broadcast_arrays(self) -> None:
x = DataArray([1, 2], coords=[("a", [-1, -2])], name="x")
y = DataArray([1, 2], coords=[("b", [3, 4])], name="y")
Expand Down
Loading