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
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.