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

Enabled the equal_nan keyword argument for np.array_equal() when the arguments are astropy.units.Quantity instances. #14135

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions astropy/units/quantity_helper/function_helpers.py
Expand Up @@ -562,9 +562,9 @@ def close(a, b, rtol=1e-05, atol=1e-08, *args, **kwargs):


@function_helper
def array_equal(a1, a2):
def array_equal(a1, a2, equal_nan=False):
args, unit = _quantities2arrays(a1, a2)
return args, {}, None, None
return args, dict(equal_nan=equal_nan), None, None


@function_helper
Expand Down
8 changes: 8 additions & 0 deletions astropy/units/tests/test_quantity_non_ufuncs.py
Expand Up @@ -924,6 +924,14 @@ def test_array_equal(self):
q3 = q1.value * u.cm
assert not np.array_equal(q1, q3)

@pytest.mark.parametrize("equal_nan", [False, True])
def test_array_equal_nan(self, equal_nan):
q1 = np.linspace(0, 1, num=11) * u.m
q1[0] = np.nan
q2 = q1.to(u.cm)
result = np.array_equal(q1, q2, equal_nan=equal_nan)
assert result == equal_nan

@needs_array_function
def test_array_equiv(self):
q1 = np.array([[0.0, 1.0, 2.0]] * 3) * u.m
Expand Down
2 changes: 2 additions & 0 deletions docs/changes/units/14135.feature.rst
@@ -0,0 +1,2 @@
Enabled the ``equal_nan`` keyword argument for ``np.array_equal()`` when the
arguments are ``astropy.units.Quantity`` instances.