fix isnan exception in erroranalysis for newer versions of pandas and numpy when calling qcut #1784
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fix isnan exception in erroranalysis for newer versions of pandas and numpy when calling qcut.
When going to heatmap, in some environments with python 3.8 installed and latest versions of pandas and numpy, erroranalysis matrix_filter method would fail with error:
\responsibleai\responsible-ai-widgets\erroranalysis\erroranalysis\_internal\matrix_filter.py", line 365, in bin_data\n bindf = pd.qcut(feat_col, bins, precision=PRECISION, duplicates=DROP)\n \.conda\envs\big_data\lib\site-packages\pandas\core\reshape\tile.py", line 375, in qcut\n x_np = x_np[~np.isnan(x_np)]\nTypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''\n"
The solution was to change to more specific dtypes using convert_dtypes() for pandas dataframe after making a copy, since the copy was changing all types to object dtype.
Since qcut was failing on object dtype column when creating the dataframe copy, changing to more specify number type via convert_dtypes() fixed the error.
Checklist