-
Notifications
You must be signed in to change notification settings - Fork 9
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
MAINT: finfo() / iinfo() input/output review #143
Changes from all 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 |
---|---|---|
|
@@ -35,7 +35,7 @@ def __eq__(self, other: object) -> builtins.bool: | |
stacklevel=2, | ||
) | ||
if not isinstance(other, DType): | ||
return NotImplemented | ||
return False | ||
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. You do not want Python to try 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. Would be nice to run scipy tests against this branch. I doubt any of the behaviors prohibited here is relied on, but we've been surprised more than once, so... |
||
return self._np_dtype == other._np_dtype | ||
|
||
def __hash__(self) -> int: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import warnings | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from numpy.testing import assert_raises | ||
import numpy as np | ||
|
||
from .._creation_functions import asarray | ||
from .._data_type_functions import astype, can_cast, isdtype, result_type | ||
from .._dtypes import ( | ||
bool, int8, int16, uint8, float64, int64 | ||
) | ||
from .._data_type_functions import astype, can_cast, finfo, iinfo, isdtype, result_type | ||
from .._dtypes import bool, float64, int8, int16, int64, uint8 | ||
from .._flags import set_array_api_strict_flags | ||
|
||
|
||
|
@@ -88,3 +85,40 @@ def test_result_type_py_scalars(api_version): | |
|
||
with pytest.raises(TypeError): | ||
result_type(int64, True) | ||
|
||
|
||
def test_finfo_iinfo_dtypelike(): | ||
"""np.finfo() and np.iinfo() accept any DTypeLike. | ||
Array API only accepts Array | DType. | ||
""" | ||
match = "must be a dtype or array" | ||
with pytest.raises(TypeError, match=match): | ||
finfo("float64") | ||
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. Got to admit I do miss the ability to use |
||
with pytest.raises(TypeError, match=match): | ||
finfo(float) | ||
with pytest.raises(TypeError, match=match): | ||
iinfo("int8") | ||
with pytest.raises(TypeError, match=match): | ||
iinfo(int) | ||
|
||
|
||
def test_finfo_iinfo_wrap_output(): | ||
"""Test that the finfo(...).dtype and iinfo(...).dtype | ||
are array-api-strict.DType objects; not numpy.dtype. | ||
""" | ||
# Note: array_api_strict.DType objects are not singletons | ||
assert finfo(float64).dtype == float64 | ||
assert iinfo(int8).dtype == int8 | ||
Comment on lines
+105
to
+111
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. This also ought to be in |
||
|
||
|
||
@pytest.mark.parametrize("func,arg", [(finfo, float64), (iinfo, int8)]) | ||
def test_finfo_iinfo_output_assumptions(func, arg): | ||
"""There should be no expectation for the output of finfo()/iinfo() | ||
to be comparable, hashable, or writeable. | ||
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. ...or serializable, or have a 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. Didn't bother testing against them behaving like namedtuples because numpy ones aren't anyway |
||
""" | ||
obj = func(arg) | ||
assert obj != func(arg) # Defaut behaviour for custom classes | ||
with pytest.raises(TypeError): | ||
hash(obj) | ||
with pytest.raises(Exception, match="cannot assign"): | ||
obj.min = 0 |
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 tested in
array-api-tests
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.
Do I take it you're up to adding that test https://github.com/data-apis/array-api-tests/blob/c48410f96fc58e02eea844e6b7f6cc01680f77ce/array_api_tests/test_data_type_functions.py#L151 :-).