DEPR: Compatibility with NumPy in ops #48277
Labels
Compat
pandas objects compatability with Numpy or Python functions
Deprecate
Functionality to remove in pandas
Needs Discussion
Requires discussion from core team before further action
In #47836 the
*args
/**kwargs
were deprecated in rolling, expanding, and ewm ops. They were used to raise a specific error message to users who tried to use NumPy functions on pandas objects. For example:raises
Other Series / DataFrame ops also have kwargs for NumPy compatibility, but unlike the above, the compatibility is to allow the use of NumPy functions to work on pandas objects:
This succeeds with the value 6. If one removes the kwargs on NDFrame.sum, you instead get
TypeError: sum() got an unexpected keyword argument 'out'
with the above code.For sum, the only acceptable calls using kwargs pass a subset of
{'dtype': None, 'axis': None, 'keepdims': False, 'initial': None}
. For any key out side of this, or any value that differs from this, we will raise.Using NumPy functions (especially sum) on pandas objects seems somewhat odd to me, but perhaps there are use cases where one can accomplish a computation that can't be readily done using pandas alone? I've frequently used
np.exp(ser)
, but one can use the alternativeser.apply(np.exp)
and to my surprise, the apply version has a little less overhead (but performs the same on Series of 1 million rows or more). Also - even with kwargs removed,np.exp(ser)
will still work, so it doesn't suffice as a useful example.The text was updated successfully, but these errors were encountered: