You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importwarningsimportpandasaspdwithwarnings.catch_warnings(record=True) asw:
df=pd.DataFrame({'A': [1]})
df2=pd.DataFrame({'A': [None]})
df['A'].combine_first(df2['A'])
assertlen(w) ==1assertw[0].category.__name__=='FutureWarning'assertx.message.args== ('The behavior of array concatenation with empty entries is deprecated. In a future version, this will no longer exclude empty items when determining the result dtype. To retain the old behavior, exclude the empty entries before the concat operation.',)
Issue Description
The concat function in pandas is designed to emit a FutureWarning when attempting to concatenate an empty DataFrame, which is a logical consequence of its intended behavior. However, there is an inconsistency with the combine_first method. It occasionally generates the same FutureWarning associated with concatenation, in a manner that may seem perplexing, even when both DataFrames involved in the operation are clearly non-empty. This anomaly can present challenges in preemptively suppressing the warning within one's code without affecting the overall functionality.
Expected Behavior
Avoid confusing warnings
Installed Versions
INSTALLED VERSIONS
commit : fd3f571
python : 3.11.6.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US
LOCALE : en_US.UTF-8
Thanks for the report! It is intended to emit a FutureWarning here.
On pandas 2.2.2 the resulting dtype of df['A'].combine_first(df2['A']) is int64, so it didn't take into account the dtype of the empty value None, whereas in main this produces object dtype.
@Aloqeely I understand that the FutureWarning for concat makes sense.
However, for combine_first, since the merging algorithm is internal to combine_first, it is difficult for the caller to ensure that a FutureWarning will not be triggered before invoking it; if the caller can manage this, then it would be equivalent to implementing combine_first themselves.
In the online environment logs and unit test reports of my system, there are numerous FutureWarnings generated due to calls to combine_first, which greatly interferes with system maintenance and code debugging.
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
Issue Description
The
concat
function in pandas is designed to emit aFutureWarning
when attempting to concatenate an empty DataFrame, which is a logical consequence of its intended behavior. However, there is an inconsistency with thecombine_first
method. It occasionally generates the sameFutureWarning
associated with concatenation, in a manner that may seem perplexing, even when both DataFrames involved in the operation are clearly non-empty. This anomaly can present challenges in preemptively suppressing the warning within one's code without affecting the overall functionality.Expected Behavior
Avoid confusing warnings
Installed Versions
INSTALLED VERSIONS
commit : fd3f571
python : 3.11.6.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US
LOCALE : en_US.UTF-8
pandas : 2.2.0
numpy : 1.25.2
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 67.4.0
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.9.2
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: