-
- Notifications
You must be signed in to change notification settings - Fork 19.1k
Open
Labels
BugCompatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functions
Description
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 numpy as np, pandas as pd data = pd.DataFrame([np.nan,1,2,3,np.Inf]) np.nan_to_num(data)
### Issue Description It seems that some numpy functions applied on a pandas DataFrame output numpy arrays / pandas DataFrames inconsistently. As an exemple is the nan_to_num function outputting a numpy array instead of a DataFrame, while for exemple the numpy log function correctly output a DataFrame. I have asked about this issue on the numpy github and was told that it is a panda issue. ### Expected Behavior Ideally np.nan_to_num would output a DataFrame, one that can currently be obtained in the following way: `pd.DataFrame(np.nan_to_num(data),index=data.index,columns=data.columns)` ### Installed Versions I only tried this with pandas version 1.5.3, but checked the logs to see if the problem was resolved. <details> INSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.10.12.final.0 python-bits : 64 OS : Linux OS-release : 5.15.109+ Version : #1 SMP Wed Jun 28 11:06:41 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : C.UTF-8 LANG : C.UTF-8 LOCALE : en_US.UTF-8 pandas : 1.5.3 numpy : 1.23.5 pytz : 2023.3 dateutil : 2.8.2 setuptools : 59.8.0 pip : 23.1.2 Cython : 0.29.35 pytest : 7.4.0 hypothesis : None sphinx : None blosc : None feather : 0.4.1 xlsxwriter : None lxml.etree : 4.9.3 html5lib : 1.1 pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.14.0 pandas_datareader: 0.10.0 bs4 : 4.12.2 bottleneck : None brotli : fastparquet : None fsspec : 2023.6.0 gcsfs : 2023.6.0 matplotlib : 3.7.2 numba : 0.57.1 numexpr : 2.8.4 odfpy : None openpyxl : 3.1.2 pandas_gbq : None pyarrow : 9.0.0 pyreadstat : None pyxlsb : None s3fs : 2023.6.0 scipy : 1.7.3 snappy : None sqlalchemy : 2.0.17 tables : 3.8.0 tabulate : 0.9.0 xarray : 2023.6.0 xlrd : None xlwt : None zstandard : 0.19.0 tzdata : 2023.3 </details>
Metadata
Metadata
Assignees
Labels
BugCompatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functions