Pandas version checks

  • [X] I have checked that this issue has not already been reported.
  • [X] I have confirmed this bug exists on the latest version of pandas.
  • [X] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

from pandas.core.interchange import from_dataframe
import pandas as pd

df = pd.DataFrame({'year': [2020, 2022, 2019, 2021],
                   'n_legs': [2, 4, 5, 100]})

# Works
from_dataframe.from_dataframe(df)

# TypeError: 'module' object is not callable
from_dataframe(df)

Issue Description

pandas.api.interchange.from_dataframe is a module not a function.

Expected Behavior

From the documentation, I expect pandas.api.interchange.from_dataframe to be a function.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 5a1f280647bca201ddc7168b2b01e65d89419ca7 python : 3.11.2.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-69-generic Version : #76~20.04.1-Ubuntu SMP Mon Mar 20 15:54:19 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.1.0.dev0+409.g5a1f280647 numpy : 1.24.2 pytz : 2023.3 dateutil : 2.8.2 setuptools : 67.6.1 pip : 23.0.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : 8.12.0 pandas_datareader: None bs4 : None bottleneck : None brotli : None fastparquet : None fsspec : None gcsfs : None matplotlib : None numba : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 11.0.0 pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None zstandard : None tzdata : 2023.3 qtpy : None pyqt5 : None

Comment From: MarcoGorelli

Thanks @thomasjpfan for the report

Given

https://github.com/pandas-dev/pandas/blob/76de473c2523d5cb26449fbc2eb6c56ae49237c4/pandas/api/interchange/init.py#L6-L8

it seems intentional to let users use it as a function

I think we can just, internally, rename pandas/core/interchange/from_dataframe.py to pandas/core/interchange/_from_dataframe.py, rename the import in interchange/__init__.py accordingly (as well as in tests), and keep the docs unaltered

Comment From: MarcoGorelli

Hi @thomasjpfan

Looking at this again, I think it's behaving as expected

The documentation points to pandas.api.interchange.from_dataframe, which is indeed a function. If you write your code using that then it works:


In [1]: from pandas.api.interchange import from_dataframe
   ...: import pandas as pd
   ...:
   ...: df = pd.DataFrame({'year': [2020, 2022, 2019, 2021],
   ...:                    'n_legs': [2, 4, 5, 100]})
   ...:
   ...: from_dataframe(df)
Out[1]:
   year  n_legs
0  2020       2
1  2022       4
2  2019       5
3  2021     100

I think we can close then

Comment From: thomasjpfan

I misread api as core 😅. I agree, lets close.