Description
df = pd.DataFrame(np.random.randint(9, size=(4,5)), columns=list("abcde"))
df = df.astype(np.int8)
print(df.astype(int).diff())
print(df.a.diff())
df.diff()
diff works fine on a dataframe with int columns; or on a single column of type np.int8. However if there are multiple columns of np.int8 then it fails
a b c d e
0 NaN NaN NaN NaN NaN
1 6.0 -5.0 -7.0 -7.0 -1.0
2 -5.0 7.0 -1.0 5.0 -7.0
3 2.0 -6.0 8.0 0.0 3.0
0 NaN
1 6.0
2 -5.0
3 2.0
Name: a, dtype: float64
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-145-2724544318c3> in <module>()
3 print(df.astype(int).diff())
4 print(df.a.diff())
----> 5 df.diff()
C:\Users\s\Anaconda3\lib\site-packages\pandas\core\frame.py in diff(self, periods, axis)
4068 """
4069 bm_axis = self._get_block_manager_axis(axis)
-> 4070 new_data = self._data.diff(n=periods, axis=bm_axis)
4071 return self._constructor(new_data)
4072
C:\Users\s\Anaconda3\lib\site-packages\pandas\core\internals.py in diff(self, **kwargs)
3172
3173 def diff(self, **kwargs):
-> 3174 return self.apply('diff', **kwargs)
3175
3176 def interpolate(self, **kwargs):
C:\Users\s\Anaconda3\lib\site-packages\pandas\core\internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
3054
3055 kwargs['mgr'] = self
-> 3056 applied = getattr(b, f)(**kwargs)
3057 result_blocks = _extend_blocks(applied, result_blocks)
3058
C:\Users\s\Anaconda3\lib\site-packages\pandas\core\internals.py in diff(self, n, axis, mgr)
1040 def diff(self, n, axis=1, mgr=None):
1041 """ return block for the diff of the values """
-> 1042 new_values = algos.diff(self.values, n, axis=axis)
1043 return [self.make_block(values=new_values, fastpath=True)]
1044
C:\Users\s\Anaconda3\lib\site-packages\pandas\core\algorithms.py in diff(arr, n, axis)
1196 if arr.ndim == 2 and arr.dtype.name in _diff_special:
1197 f = _diff_special[arr.dtype.name]
-> 1198 f(arr, out_arr, n, axis)
1199 else:
1200 res_indexer = [slice(None)] * arr.ndim
pandas\src\algos_common_helper.pxi in pandas.algos.diff_2d_int8 (pandas\algos.c:62940)()
ValueError: Buffer dtype mismatch, expected 'float32_t' but got 'double'
######################################################################
INSTALLED VERSIONS
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.1
nose: 1.3.7
pip: 9.0.1
setuptools: 28.7.1
Cython: 0.24
numpy: 1.11.2
scipy: 0.17.1
statsmodels: 0.8.0rc1
xarray: None
IPython: 4.2.0
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None
time: 5.55 s