Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: modin.pandas.pivot_table raises ValueError when given pandas dataframe argument #6243

Open
3 tasks done
zulee1711 opened this issue Jun 7, 2023 · 5 comments
Open
3 tasks done
Labels
bug 🦗 Something isn't working External Pull requests and issues from people who do not regularly contribute to modin P1 Important tasks that we should complete soon

Comments

@zulee1711
Copy link

Modin version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest released version of Modin.

  • I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow this guide.)

Reproducible Example

import pandas as pd
import modin.pandas as mpd
import pandas as pd
import modin.pandas as mpd
x = [{'date': pd.Timestamp('2020-01-03 00:00:00'),
  'ticker': 'CTG',
  7: 0.08},
 {'date': pd.Timestamp('2020-01-03 00:00:00'),
  'ticker': 'CTI',
  7: 0.02},
 {'date': pd.Timestamp('2020-01-03 00:00:00'),
  'ticker': 'DIG',
  7: 0.01},
 {'date': pd.Timestamp('2020-01-03 00:00:00'),
  'ticker': 'DRC',
  7: 0.069},
 {'date': pd.Timestamp('2020-01-03 00:00:00'),
  'ticker': 'HNG',
  7: 0.029},
{'date': pd.Timestamp('2020-01-04 00:00:00'),
  'ticker': 'CTG',
  7: 0.081},
 {'date': pd.Timestamp('2020-01-04 00:00:00'),
  'ticker': 'CTI',
  7: 0.025},
 {'date': pd.Timestamp('2020-01-04 00:00:00'),
  'ticker': 'DIG',
  7: 0.013},
 {'date': pd.Timestamp('2020-01-04 00:00:00'),
  'ticker': 'DRC',
  7: 0.069},
 {'date': pd.Timestamp('2020-01-04 00:00:00'),
  'ticker': 'HNG',
  7: 0.023},]
df = pd.DataFrame.from_records(x).set_index('date')
df1 = pd.pivot_table(df, index = df.index, columns = ['ticker'])
df2 = mpd.pivot_table(df, index = df.index, columns = ['ticker'])

Issue Description

When using pivot tables with modin, appear ValueError: can not create pivot table with instance of type <class 'pandas.core.frame.DataFrame'>
The regular Pandas works fine. Can anyone help me please?

Expected Behavior

df1 = pd.pivot_table(df, index = df.index, columns = ['ticker'])

Error Logs

Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\envs\risk_model\lib\site-packages\IPython\core\interactiveshell.py", line 3398, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-e94e585669d4>", line 37, in <cell line: 37>
    df1 = mpd.pivot_table(df, index = df.index, columns = ['ticker'])
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\envs\risk_model\lib\site-packages\modin\logging\logger_function.py", line 65, in run_and_log
    return f(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\envs\risk_model\lib\site-packages\modin\pandas\general.py", line 340, in pivot_table
    raise ValueError(
ValueError: can not create pivot table with instance of type <class 'pandas.core.frame.DataFrame'>

Installed Versions

INSTALLED VERSIONS

commit : e8093ba372f9adfe79439d90fe74b0b5b6dea9d6
python : 3.8.10.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 167 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.3
numpy : 1.23.5
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.1.2
Cython : 0.29.32
pytest : 7.1.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.9
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: 0.10.0
bs4 : 4.11.1
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : 2022.8.2
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.3
numba : 0.56.2
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 6.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : 1.4.31
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
zstandard : None

@zulee1711 zulee1711 added bug 🦗 Something isn't working Triage 🩹 Issues that need triage labels Jun 7, 2023
@anmyachev
Copy link
Collaborator

@zulee1711 thanks for the contribution!

At the moment, Pandas objects are specifically not accepted by Modin. For this code to work, you need to explicitly convert Pandas' dataframe to Modin's dataframe like that:

mpd.pivot_table(mpd.DataFrame(df), index = df.index, columns = ['ticker'])

@modin-project/modin-core there are more and more situations where it would be convenient for users to pass pandas objects to Modin functions. We should rethink this.

@anmyachev anmyachev added External Pull requests and issues from people who do not regularly contribute to modin and removed Triage 🩹 Issues that need triage labels Jun 7, 2023
@dchigarev
Copy link
Collaborator

there are more and more situations where it would be convenient for users to pass pandas objects to Modin functions. We should rethink this.

I think what we should do is to make a more describable error message in these situations, something like: "you're trying to pass pandas object to a modin's method, please make the conversion as follows...".

It could be a real pain to efficiently support both pandas and modin objects, so my vote here is only to make clear errors.

@anmyachev
Copy link
Collaborator

I think what we should do is to make a more describable error message in these situations, something like: "you're trying to pass pandas object to a modin's method, please make the conversion as follows...".

+1

It could be a real pain to efficiently support both pandas and modin objects, so my vote here is only to make clear errors.

We don't have to make the case with pandas dataframes fast (just give a warning that dataframe conversion takes time and if you want performance boost, you need to rewrite the code). Here it is more important to ensure seamless integration with other libraries, where the user does not have the ability to change imports.

@zulee1711
Copy link
Author

@anmyachev Thank you

I think what we should do is to make a more describable error message in these situations, something like: "you're trying to pass pandas object to a modin's method, please make the conversion as follows...".

A more detailed message is much appreciated. Since the error gave a warning in <class 'pandas.core.frame.DataFrame'>, I would know that there's something wrong with the code related to pandas dataframe, but wouldn't necessarily know where to look for an answer

@YarShev
Copy link
Collaborator

YarShev commented Jun 12, 2023

UPD: Even using Modin objects, I see the following error on latest master.

TypeError: '<' not supported between instances of 'str' and 'Timestamp'

@mvashishtha mvashishtha added the P1 Important tasks that we should complete soon label Aug 17, 2023
@mvashishtha mvashishtha changed the title BUG: Pivot Tables errors when using modin.pandas BUG: modin.pandas.pivot_table raises ValueError when given pandas dataframe argument Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🦗 Something isn't working External Pull requests and issues from people who do not regularly contribute to modin P1 Important tasks that we should complete soon
Projects
None yet
Development

No branches or pull requests

5 participants