-
Notifications
You must be signed in to change notification settings - Fork 1
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
TST: test/fix astype
/clip
#20
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,8 +54,8 @@ def get_arrays(n_arrays, *, dtype='float64', xp=np, seed=None): | |||||
def assert_comparison(res, ref, seed, comparison, **kwargs): | ||||||
ref_mask = np.broadcast_to(ref.mask, ref.data.shape) | ||||||
try: | ||||||
comparison(res.data[~res.mask], ref.data[~ref_mask], **kwargs) | ||||||
comparison(res.mask, ref_mask, **kwargs) | ||||||
comparison(res.data[~res.mask], ref.data[~ref_mask], strict=True, **kwargs) | ||||||
comparison(res.mask, ref_mask, strict=True, **kwargs) | ||||||
except AssertionError as e: | ||||||
raise AssertionError(seed) from e | ||||||
|
||||||
|
@@ -417,11 +417,41 @@ def test_statistical_array(f_name, keepdims, xp=np, dtype='float64', seed=None): | |||||
|
||||||
# Use Array API tests to test the following: | ||||||
# Creation Functions (same behavior but with all-False mask) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# Data Type Functions (only `astype` remains to be tested) | ||||||
# Elementwise function `clip` (all others are tested above) | ||||||
# Indexing (same behavior as indexing data and mask separately) | ||||||
# Manipulation functions (apply to data and mask separately) | ||||||
|
||||||
|
||||||
@pytest.mark.filterwarnings('ignore::numpy.exceptions.ComplexWarning') | ||||||
@pytest.mark.parametrize('dtype_in', dtypes_all) | ||||||
@pytest.mark.parametrize('dtype_out', dtypes_all) | ||||||
@pytest.mark.parametrize('copy', [False, True]) | ||||||
def test_astype(dtype_in, dtype_out, copy, xp=np, seed=None): | ||||||
mxp = marray.masked_array(xp) | ||||||
marrays, masked_arrays, seed = get_arrays(1, dtype=dtype_in, seed=seed) | ||||||
|
||||||
if dtype_in != dtype_out and not copy: | ||||||
pytest.mark.skip("Can't change type without copy.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this actually do anything? I believe we need to use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it was a typo, and I guess it wasn't needed. Removed.
mdhaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
res = mxp.astype(marrays[0], dtype_out, copy=copy) | ||||||
if dtype_in == dtype_out: | ||||||
if copy: | ||||||
assert res.data is not marrays[0].data | ||||||
assert res.mask is not marrays[0].mask | ||||||
else: | ||||||
assert res.data is marrays[0].data | ||||||
assert res.mask is marrays[0].mask | ||||||
ref = masked_arrays[0].astype(dtype_out, copy=copy) | ||||||
assert_equal(res, ref, seed) | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize('dtype', dtypes_real) | ||||||
def test_clip(dtype, xp=np, seed=None): | ||||||
mxp = marray.masked_array(xp) | ||||||
marrays, masked_arrays, seed = get_arrays(3, dtype=dtype, seed=seed) | ||||||
res = mxp.clip(marrays[0], min=marrays[1], max=marrays[2]) | ||||||
ref = np.ma.clip(*masked_arrays) | ||||||
assert_equal(res, ref, seed) | ||||||
|
||||||
#? | ||||||
# Searching functions - would test argmin/argmax with statistical functions, | ||||||
# but NumPy masked version isn't correct | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be done in a new PR, but I believe it would be neater to use a decorator for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean for adding the attribute to the namespace? What is the advantage?