-
Notifications
You must be signed in to change notification settings - Fork 49
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
Dtype / checking standardization #152
Comments
With NumPy, one can do this. However I don't think the In [1]: from numbers import Integral
In [2]: import numpy as np
In [3]: a = np.arange(5)
In [4]: issubclass(a.dtype.type, Integral)
Out[4]: True In [1]: from numbers import Real
In [2]: import numpy as np
In [3]: a = np.arange(5).astype(float)
In [4]: issubclass(a.dtype.type, Real)
Out[4]: True |
https://data-apis.org/array-api/latest/API_specification/data_types.html says
(I had thought that somewhere it was required that dtype objects be comparable by I will point out that if you only care about the dtypes in the spec, there are a finite number of them, so you can use def is_floating(dtype):
return dtype in [float32, float64]
def is_integral(dtype):
return dtype in [int8, ...] |
Sounds like something we should add. By the way, did we specify that dtype objects are singletons so that they can also be checked via |
The docs weren't clear to me, but I didn't interpret those as singletons and instead thought that it was just guidance on what data types need to be supported by the standard. |
The dtype names need to be part of the namespace. Otherwise passing
isinstance(x, float32) implies that x is a scalar, which we do not have in the spec ( |
FWIW |
@asmeurer I think you misread. If I wanna do |
Right this is also why in the OP it mentions that with NumPy, we need to |
So IIUC the current standard does not specify what property or method a dtype object needs to implement:
so for now I think it is a no-go to check dtype.type . We need either the equal check (== ) or something equivalent added or the standard revised I think.
|
(And also it doesn't seem that subclassing is an option, depending on how one interprets the standard.) |
Reopening this issue as relevant to the proposal in #425. |
In the current specification, there are not standardized data type objects, or a specification as to what a data type object needs to implement: https://data-apis.org/array-api/latest/API_specification/data_types.html
Additionally, there's no APIs in the specification for checking dtypes, i.e. something like
np.issubdtype
that is somewhat commonly used in code that would look something like:cc @jakirkham as I believe this pattern is used quite a bit in Dask which would presumably want to be able to target arbitrary array objects under the hood
The text was updated successfully, but these errors were encountered: