narwhals-dev / narwhals

Lightweight and extensible compatibility layer between dataframe libraries!
https://narwhals-dev.github.io/narwhals/
MIT License
613 stars 91 forks source link

feat: raise informative error or warning when passing narwhals object to `nw.dependencies.is_*_dataframe` #1437

Open MarcoGorelli opened 2 days ago

MarcoGorelli commented 2 days ago

If someone has a df: nw.DataFrame and they do

nw.dependencies.is_pandas_dataframe(df)

then they almost certainly meant to call

nw.dependencies.is_pandas_dataframe(df.to_native())

Source: I made this mistake 😳

To save others from making this mistake (as well as to save myself from re-making it in the future), we could:

Maybe just raising an error would be fine, I can't imagine a situation where you have an object which is either a narwhals dataframe or a native object and in both cases you pass it as-is to is_pandas_dataframe