FIX Make get_namespace handle pandas dataframe input#32838
FIX Make get_namespace handle pandas dataframe input#32838lesteve merged 7 commits intoscikit-learn:mainfrom
get_namespace handle pandas dataframe input#32838Conversation
A pandas DataFrame or Series does not have a namespace associated to it in the array API. As such we should filter it out, like sparse arrays, before trying to determine the namespace.
Treating pandas dataframes the same as sparse arrays seems to make sense to me. ccing the other members of the Array API special team to have a second opinion @OmarManzoor @lucyleeow |
ogrisel
left a comment
There was a problem hiding this comment.
Thanks. I think this is the correct fix but it needs to be generalized, see below.
+1 from me too |
9fa59a3 to
ae852b8
Compare
|
I've moved the |
ogrisel
left a comment
There was a problem hiding this comment.
LGTM as it is, but feel free to to implement https://github.com/scikit-learn/scikit-learn/pull/32838/files#r2591717992 as well.
|
Let's merge this one! |
|
If the tests pass this is ready. Automerge? |
Reference Issues/PRs
Closes #32836
What does this implement/fix? Explain your changes.
A pandas DataFrame or Series does not have a namespace associated to it in the array API. As such we should filter it out, like we do for sparse arrays, before trying to determine the namespace. This means that for
get_namespace(a_df)(with array API enabled) we get the NumPy compat namespace back asxp. I think this makes sense.AI usage disclosure
I used AI assistance for:
test_get_namespace_ndarray_with_dispatchwhich I used as starting pointAny other comments?
How do we solve the problem that we can't import
_is_pandas_df_or_seriesfromsklearn.utils.validationas it causes a circular import. Duplicating it feels a bit weird, but I can't think of a great alternative. We could usehasattr(array, "iloc")to detect "pandas-ness"?Before discussing how we best detect "pandas-ness" we should agree that filtering
DataFrameandSeriesout (like sparse arrays) is the right approach.cc @ogrisel