I observed a different behavior in the handling of data types for the .apply() and the .applymap() functions of pandas.
big_number = 999999
big_number * big_number
Out[715]: 999998000001
np.square(big_number)
Out[716]: -729379967
np.square(float(big_number))
Out[717]: 999998000001.0
df = pd.DataFrame([big_number], columns=["big_number"])
df.dtypes
Out[719]:
big_number int64
dtype: object
df.apply(np.square)
Out[720]:
big_number
0 999998000001
df.applymap(np.square)
Out[721]:
big_number
0 -729379967
df.astype({"big_number" : float}).applymap(np.square)
Out[722]:
big_number
0 9.999980e+11
Obviously behaves .applymap() more correctly then .apply(), because it actually reproduces the result of the np.square() function. .apply() seems to do some magic data type conversion before calling the np.square function.
Can anybody explain what happens "under the hood"?