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: diff method raises ValueError when it's called with np.int64 #44572

Closed
2 of 3 tasks
asdf8601 opened this issue Nov 22, 2021 · 3 comments · Fixed by #44577
Closed
2 of 3 tasks

BUG: diff method raises ValueError when it's called with np.int64 #44572

asdf8601 opened this issue Nov 22, 2021 · 3 comments · Fixed by #44577
Labels
Bug Reduction Operations sum, mean, min, max, etc.
Milestone

Comments

@asdf8601
Copy link
Contributor

asdf8601 commented Nov 22, 2021

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

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

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

# w = np.array([2,3])[0]  # normal use 
w = np.int64(2)
pd.Series([1,2,3]).diff(w)     # works
pd.DataFrame([1,2,3]).diff(w)  # fails

Issue Description

When diff method is called with a np.int64 then ValueError is raised as np.int64 is not instance of int (see numpy/numpy#2951 (comment)). Also, this behavior is not consistent between Series and DataFrame.

Expected Behavior

I've expected DataFrame work like Series does.

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 945c9ed766a61c7d2c0a7cbb251b6edebf9cb7d5
python           : 3.8.9.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.11.0-40-generic
Version          : #44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021
machine          : x86_64
processor        :
byteorder        : little
LC_ALL           : None
LANG             : C.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.3.4
numpy            : 1.20.3
pytz             : 2021.3
dateutil         : 2.8.2
pip              : 21.0.1
setuptools       : 56.0.0
Cython           : None
pytest           : 6.2.5
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : 7.29.0
pandas_datareader: None
bs4              : None
bottleneck       : 1.3.2
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.5.0
numexpr          : 2.7.3
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.7.2
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : 0.54.1
@asdf8601 asdf8601 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 22, 2021
@asdf8601 asdf8601 changed the title BUG: diff method raise ValueError when it's called with np.int64 BUG: diff method raises ValueError when it's called with np.int64 Nov 22, 2021
@jbrockmendel
Copy link
Member

Easy fix in DataFrame.diff changing an isinstance(periods, int) to lib.is_integer(periods). PR welcome.

@lithomas1 lithomas1 added Reduction Operations sum, mean, min, max, etc. and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 23, 2021
@lithomas1 lithomas1 added this to the 1.4 milestone Nov 23, 2021
@asdf8601
Copy link
Contributor Author

Thank you @jbrockmendel, Have you been faster than me ;-)

I could see that the fix will be included in 1.4. So, I'm wondering if you are planning to populate it to other releases apart from 1.4 as bug fix or not. What is the rule?

@jreback
Copy link
Contributor

jreback commented Nov 23, 2021

only regressions are backport ed
and this late in the cycle (eg 1.3.5 will be the last of the series) only very critical ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants