8000 MAINT: Require `select` for NEP 50 support · numpy/numpy@61245d0 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61245d0

Browse files
committed
MAINT: Require select for NEP 50 support
This isn't quite ideally, it would be nice to grow specific code for it (and actually, we currently allow some subclasses in other paths, but I am planning to undo that).
1 parent 37fddc8 commit 61245d0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

numpy/lib/function_base.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -817,22 +817,19 @@ def select(condlist, choicelist, default=0):
817817
if len(condlist) == 0:
818818
raise ValueError("select with an empty condition list is not possible")
819819

820-
choicelist = [np.asarray(choice) for choice in choicelist]
820+
# TODO: This preserves the Python int, float, complex manually to get the
821+
# right `result_type` with NEP 50. Most likely we will grow a better
822+
# way to spell this (and this can be replaced).
823+
choicelist = [
824+
choice if type(choice) in (int, float, complex) else np.asarray(choice)
825+
for choice in choicelist]
826+
choicelist.append(default if type(default) in (int, float, complex)
827+
else np.asarray(default))
821828

822829
try:
823-
intermediate_dtype = np.result_type(*choicelist)
830+
dtype = np.result_type(*choicelist)
824831
except TypeError as e:
825-
msg = f'Choicelist elements do not have a common dtype: {e}'
826-
raise TypeError(msg) from None
827-
default_array = np.asarray(default)
828-
choicelist.append(default_array)
829-
830-
# need to get the result type before broadcasting for correct scalar
831-
# behaviour
832-
try:
833-
dtype = np.result_type(intermediate_dtype, default_array)
834-
except TypeError as e:
835-
msg = f'Choicelists and default value do not have a common dtype: {e}'
832+
msg = f'Choicelist and default value do not have a common dtype: {e}'
836833
raise TypeError(msg) from None
837834

838835
# Convert conditions to arrays and broadcast conditions and choices

0 commit comments

Comments
 (0)
0