So, I was working on a pipeline, and I stumbled upon this error when fitting it:
Traceback (most recent call last):
File "C:/Users/Shawn/Documents/temp/bool_issue.py", line 7, in <module>
_assert_all_finite(array, False)
File "C:\Users\Shawn\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\utils\validation.py", line 103, in _assert_all_finite
if _object_dtype_isnan(X).any():
AttributeError: 'bool' object has no attribute 'any'
This is actually a some custom code to test the issue, see below
Following the traceback, I see that _object_dtype_isnan() takes a numpy array, and returns another numpy array, in the form of a boolean mask (an array of booleans).
However, for some reason, it sometimes returns a boolean directly instead.
Code to reproduce the error:
import numpy as np
import pandas as pd
from sklearn.utils.validation import _assert_all_finite
bad_array = np.array(['F', 'F', 'M', 'F', 'M', pd.NA, 'F', 'M'], dtype='object')
_assert_all_finite(bad_array, False) # Raises AttributeError