Skip to content

BUG: Deprecation warning for bool/numeric concatenation seems too broadly scoped #50163

Closed
@vyasr

Description

@vyasr

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
>>> bool_df = pd.DataFrame({"a": [False]})
>>> _ = pd.concat([bool_df, pd.DataFrame({"a": [1]})])
>>> _ = pd.concat([bool_df, pd.DataFrame({"a": [1.0]})])
>>> _ = pd.concat([bool_df, pd.DataFrame({"a": []}, dtype="int64")])
>>> _ = pd.concat([bool_df, pd.DataFrame({"a": []}, dtype="float64")])
<stdin>:1: FutureWarning: Behavior when concatenating bool-dtype and numeric-dtype arrays is deprecated; in a future version these will cast to object dtype (instead of coercing bools to numeric values). To retain the old behavior, explicitly cast bool-dtype arrays to numeric dtype.

Issue Description

I'm seeing a generic warning about how concatenating bool and numeric dtypes will stop casting to a numeric type, but it only seems to occur in very specific cases of inputs (specifically, for an empty float dtype with the bool data). I'm not sure if this is a bug in where a FutureWarning is being thrown or just a request for a more descriptive message with the warning, so apologies for perhaps misunderstanding the intent here. I looked through #39817 and #45101, and they seem to indicate an awareness of the difference between empty and non-empty columns, but I don't know if that was meant to propagate to the deprecation or not.

Expected Behavior

I would expect the same warning to be shown for int-bool or float-bool operations, and to be raised regardless of whether the object is empty, but based on my reading of the related issues I'm not sure if that expectation is valid. If the warnings is in fact being shown in the only relevant case, I would expect the message to more clearly indicate exactly what case is being deprecated (empty array, float data, etc).

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.8.15.final.0
python-bits : 64
OS : Linux
OS-release : 5.14.0-1054-oem
Version : #61-Ubuntu SMP Fri Oct 14 13:05:50 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.1
pip : 22.3.1
Cython : 0.29.32
pytest : 7.2.0
hypothesis : 6.60.0
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.7.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : None
numba : 0.56.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2022.11.0
scipy : 1.9.3
snappy :
sqlalchemy : 1.4.44
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugClosing CandidateMay be closeable, needs more eyeballsDtype ConversionsUnexpected or buggy dtype conversionsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions