-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: apply for series of numpy arrays falis with np functions #33492
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
Labels
Apply
Apply, Aggregate, Transform, Map
Bug
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
Comments
Hmm, given that this works either by wrapping the ufunc in a lambda or using map I think it likely qualifies as a bug (in the meantime you should be able to use either of these workarounds): [ins] In [1]: ser = pd.Series([np.array([1, 2])])
[ins] In [2]: ser.map(np.sin)
Out[2]:
0 [0.8414709848078965, 0.9092974268256817]
dtype: object
[ins] In [3]: ser.apply(lambda x: np.sin(x))
Out[3]:
0 [0.8414709848078965, 0.9092974268256817]
dtype: object |
5 tasks
I wouldn't say, the failure is for all numpy functions, >>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame({"col": [np.array([.1, .2], dtype=float), np.array([.3]) ]})
>>> df.col.apply(np.max)
0 0.2
1 0.3
Name: col, dtype: float64
>>> I suppose, pandas is calling vectorised version of NumPy calls, which too raises the same exception. >>> np.sin(df.col)
AttributeError: 'numpy.ndarray' object has no attribute 'sin'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/skmohan 1/Workspace/github.com/pandas/pandas/core/series.py", line 732, in __array_ufunc__
result = getattr(ufunc, method)(*inputs, **kwargs)
TypeError: loop of ufunc does not support argument 0 of type numpy.ndarray which has no callable sin method
>>> |
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Apply
Apply, Aggregate, Transform, Map
Bug
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Raises:
Problem description
When I have a pd.Series where each row is a numerical numpy array, I can't apply numpy functions to them, I tried np.sin, np.cos, np.exp, but I think it's a general problem. I can apply them to individual rows manually and it works fine.
Moreover, If I import tqdm with tqdm.pandas and use progress_apply instead of apply it also works just fine!
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-46-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200325
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: