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

Odd error message, concerning numpy using an alias versus numpy package name #28665

Closed
apiszcz opened this issue Sep 28, 2019 · 5 comments
Closed
Assignees
Labels
Error Reporting Incorrect or improved errors from pandas good first issue

Comments

@apiszcz
Copy link

apiszcz commented Sep 28, 2019

This produces a poor warning

>>> import pandas as pd
>>> import numpy as np
>>> np.ptp(pd.Series([1, 2, 3]))
/lib/python3.7/site-packages/numpy/core/fromnumeric.py:2495: FutureWarning: Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.

because np.ptp calls Series.ptp, which is deprecated. We should instruct the user
to convert the Series to an array before calling ptp.

np.ptp(pd.Series([1, 2, 3]).array)

The warning is defined at

pandas/pandas/core/generic.py

Lines 10197 to 10199 in 20e4c18

warnings.warn(
"Method .ptp is deprecated and will be removed "
"in a future version. Use numpy.ptp instead.",


In this case I am using numpy ptp, however the error messages states I am not

>>> dfagg = df.groupby(['idf']).agg({ 'f1' : [np.min, np.max, np.ptp] })
C:\test\lib\numpy\core\fromnumeric.py:2495: FutureWarning: Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead.

NO warning
>>> dfagg = df.groupby(['idf']).agg({ 'f1' : [np.min, np.max, numpy.ptp] })

@jbrockmendel jbrockmendel added the Error Reporting Incorrect or improved errors from pandas label Oct 16, 2019
@DavidMStraub
Copy link

I'm also running into this warning. It's actually even simpler to reproduce:

import pandas as pd
import numpy as np
np.ptp(pd.Series([1, 2, 3]))

This will raise the warning. The reason, I think, is ironic: pandas warns against using the Series' method inspite of the function, but numpy, when using the function, tries if there is a method and uses that preferably:
https://github.com/numpy/numpy/blob/master/numpy/core/fromnumeric.py#L2541-L2548

@TomAugspurger
Copy link
Contributor

We faced a similar issue with argmin / argmax: https://github.com/pandas-dev/pandas/pull/16955/files

The recommendation is to have people do np.ptp(pd.Series([1, 2, 3]).to_numpy()) in the meantime. Does anyone want to update the deprecation message?

@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Dec 19, 2019
@hasnain2808
Copy link
Contributor

I would like to take up this issue but as I am new would need some support

hasnain2808 added a commit to hasnain2808/pandas that referenced this issue Dec 23, 2019
hasnain2808 added a commit to hasnain2808/pandas that referenced this issue Dec 24, 2019
@hasnain2808
Copy link
Contributor

take

@jbrockmendel
Copy link
Member

closed by #30458.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue
Projects
None yet
Development

No branches or pull requests

5 participants