-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix: coerce unknown types to O dtype #10339
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
base: main
Are you sure you want to change the base?
Changes from all commits
5845809
ef3df17
b82fc90
1756bc4
8f0e197
5c3acf1
8d15d2f
5fc7ccc
0afd465
22ab662
4cea3fa
8f26768
46ae113
788eedb
6512e09
e51a8c4
602adc5
78751f8
0eb085d
791bf98
46b5670
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 |
|---|---|---|
| @@ -1,7 +1,20 @@ | ||
| import datetime as dt | ||
|
|
||
| import numpy as np | ||
|
|
||
| from xarray.namedarray.pycompat import array_type | ||
|
|
||
| builtin_types = ( | ||
| bool, | ||
| int, | ||
| float, | ||
| complex, | ||
| str, | ||
| bytes, | ||
| dt.datetime, | ||
| dt.timedelta, | ||
| ) | ||
|
|
||
|
|
||
| def is_weak_scalar_type(t): | ||
| return isinstance(t, bool | int | float | complex | str | bytes) | ||
|
|
@@ -38,12 +51,15 @@ def _future_array_api_result_type(*arrays_and_dtypes, xp): | |
|
|
||
|
|
||
| def result_type(*arrays_and_dtypes, xp) -> np.dtype: | ||
| if xp is np or any( | ||
| isinstance(getattr(t, "dtype", t), np.dtype) for t in arrays_and_dtypes | ||
| ): | ||
| return xp.result_type(*arrays_and_dtypes) | ||
| else: | ||
| return _future_array_api_result_type(*arrays_and_dtypes, xp=xp) | ||
| try: | ||
| if xp is np or any( | ||
| isinstance(getattr(t, "dtype", t), np.dtype) for t in arrays_and_dtypes | ||
| ): | ||
| return xp.result_type(*arrays_and_dtypes) | ||
| else: | ||
| return _future_array_api_result_type(*arrays_and_dtypes, xp=xp) | ||
| except TypeError: | ||
| return np.dtype(object) | ||
|
Comment on lines
+61
to
+62
Member
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 entire module is intended as forwards compatible replacements for array API functionality, so we shouldn't add behavior here that deviates from |
||
|
|
||
|
|
||
| def get_array_namespace(*values): | ||
|
|
||
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.
It does not look like this is used in the current version of this PR