Skip to content

Commit d17b6b5

Browse files
sft-managedsft-managed
authored andcommitted
add duck-type check for KNeighbors-likeness
1 parent edf6eae commit d17b6b5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

imblearn/utils/_validation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def check_neighbors_object(nn_name, nn_object, additional_neighbor=0):
9595
return NearestNeighbors(n_neighbors=nn_object + additional_neighbor)
9696
elif isinstance(nn_object, KNeighborsMixin):
9797
return clone(nn_object)
98+
elif hasattr(nn_object, 'kneighbors') and hasattr(nn_object, 'kneighbors_graph'):
99+
return clone(nn_object)
98100
else:
99101
raise_isinstance_error(nn_name, [int, KNeighborsMixin], nn_object)
100102

0 commit comments

Comments
 (0)