Skip to content

BUG: New versions of numpy breaks log/where using pandas series #54900

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

Open
2 of 3 tasks
rikardn opened this issue Aug 31, 2023 · 1 comment
Open
2 of 3 tasks

BUG: New versions of numpy breaks log/where using pandas series #54900

rikardn opened this issue Aug 31, 2023 · 1 comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions

Comments

@rikardn
Copy link

rikardn commented Aug 31, 2023

Pandas version checks

  • 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 main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

ser = pd.Series([0.0, 17.3])
np.log(ser, where=ser != 0)    # Crashes, but used to work

Issue Description

Using pandas 2.1.0 the example has been working fine until using numpy version 1.24.4. Tested now using numpy 1.25.2 and it also crashes. If instead converting the mask to numpy beforehand the example runs fine.

Since it works with numpy's native datatype I filed the issue here rather than at numpy.

Expected Behavior

import pandas as pd
import numpy as np

ser = pd.Series([0.0, 17.3])
np.log(ser, where=(ser != 0).values)    # works

Installed Versions

INSTALLED VERSIONS ------------------ commit : ba1cccd python : 3.10.12.final.0 python-bits : 64 OS : Linux OS-release : 5.15.0-82-generic Version : #91-Ubuntu SMP Mon Aug 14 14:14:14 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.1.0
numpy : 1.25.2
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.0.2
Cython : None
pytest : 7.2.2
hypothesis : None
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.31.1
pandas_datareader : None
bs4 : 4.10.0
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : 2023.4.0
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.3.0
pyqt5 : None
/usr/lib/python3/dist-packages/scipy/init.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 1.25.2
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"

@rikardn rikardn added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 31, 2023
@simonjayhawkins simonjayhawkins added the Compat pandas objects compatability with Numpy or Python functions label Feb 6, 2024
@Aloqeely
Copy link
Member

Aloqeely commented Jul 5, 2024

Thanks for the report! Sorry for the very late response but at first glance, this looks like an issue with numpy rather than pandas.
It seems like np.log's where argument does not support passing a pandas Series to it. Maybe raise an issue there instead?

A simple solution would be to do where=(ser != 0).to_numpy()) or .values like you just did.

@Aloqeely Aloqeely removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

No branches or pull requests

3 participants