Input checking with preserved pandas dataframes
- Dominant language
- Python
- Stars
- 951
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
The current implementation of `check_array` with `preserve_pandas_dataframe=True` is only a pass-through.
https://github.com/dask/dask-ml/blob/7793962d990a4b5290a5cfd1aee1d5b48828f1a1/dask_ml/utils.py#L167
It's clear from the comment (`# TODO: validation?`) that there is (or at least was) intent to do some form of validation but I could not find any trace of that in the open issues or PRs.
I would be happy to give it a try if this is of general interest.
My approach would be to write a wrapper around the scikit-learn `check_array` function which preserves the axis labels and dtypes where applicable.
(As of now) I don't really see real obstacles as pandas is more strict with the numpy compatible datatypes so preserving those should not be a big issue. On the other hand categoricals might need some tinkering, though.
Also not entirely sure about how to support `pandas.SparseArray`s but there is a potential workaround with converting to scipy coo format which avoids densifying.
Any thoughts?
Contributor guide
Research direction
Start in dask_ml/utils.py at check_array and its preserve_pandas_dataframe=True path, then inspect how scikit-learn’s check_array handles pandas inputs. Define the validation behavior for labels, dtypes, categoricals, and pandas SparseArrays before implementing a wrapper. Done means validation is no longer a pass-through while applicable pandas structure is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python, scikit-learn
- Domain
- data, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100