Elffuss BraidHub

kikocis/auto-code-rover public

main · 1.5 KiBRawPermalink
1diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py
2--- a/sklearn/utils/validation.py
3+++ b/sklearn/utils/validation.py
4@@ -466,6 +466,12 @@ def check_array(array, accept_sparse=False, accept_large_sparse=True,
5 # not a data type (e.g. a column named dtype in a pandas DataFrame)
6 dtype_orig = None
7
8+ # check if the object contains several dtypes (typically a pandas
9+ # DataFrame), and store them. If not, store None.
10+ dtypes_orig = None
11+ if hasattr(array, "dtypes") and hasattr(array, "__array__"):
12+ dtypes_orig = np.array(array.dtypes)
13+
14 if dtype_numeric:
15 if dtype_orig is not None and dtype_orig.kind == "O":
16 # if input is object, convert to float.
17@@ -581,6 +587,16 @@ def check_array(array, accept_sparse=False, accept_large_sparse=True,
18 if copy and np.may_share_memory(array, array_orig):
19 array = np.array(array, dtype=dtype, order=order)
20
21+ if (warn_on_dtype and dtypes_orig is not None and
22+ {array.dtype} != set(dtypes_orig)):
23+ # if there was at the beginning some other types than the final one
24+ # (for instance in a DataFrame that can contain several dtypes) then
25+ # some data must have been converted
26+ msg = ("Data with input dtype %s were all converted to %s%s."
27+ % (', '.join(map(str, sorted(set(dtypes_orig)))), array.dtype,
28+ context))
29+ warnings.warn(msg, DataConversionWarning, stacklevel=3)
30+
31 return array
32
33