Skip to content

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

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

Closed
2 of 3 tasks
vyasr opened this issue Dec 10, 2022 · 4 comments
Closed
2 of 3 tasks
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@vyasr
Copy link
Contributor

vyasr commented Dec 10, 2022

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

@vyasr vyasr added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 10, 2022
@phofl
Copy link
Member

phofl commented Dec 11, 2022

Agree, this is really odd. We already enforced the deprecation on main and we are still converting False to 0 in some cases

Adding Milestone 2.0 for now to avoid this getting lost

@phofl phofl added this to the 2.0 milestone Dec 11, 2022
@phofl phofl added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 11, 2022
@phofl
Copy link
Member

phofl commented Dec 11, 2022

bool_df = pd.DataFrame({"a": [False]})
x = pd.concat([bool_df, pd.DataFrame({"a": [1]})])
x.dtypes

a    int64
dtype: object

x

   a
0  0
0  1

x = pd.concat([bool_df, pd.DataFrame({"a": [1.0]})])
x.dtypes

a    object
dtype: object

x

       a
0  False
0    1.0


x = pd.concat([bool_df, pd.DataFrame({"a": []}, dtype="int64")])
x.dtypes

a    int64
dtype: object

x

   a
0  0

x = pd.concat([bool_df, pd.DataFrame({"a": []}, dtype="float64")])
x.dtypes

a    object
dtype: object

x

     a
0  0.0

cc @jbrockmendel I think every case except the second looks off?

@jbrockmendel
Copy link
Member

I think every case except the second looks off?

agreed

@MarcoGorelli
Copy link
Member

looks like this has already been enforced

>>> 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")])

and there's not going to be another 1.5.x release - OK to close this one?

removing the 2.0 milestone anyway

@MarcoGorelli MarcoGorelli removed this from the 2.0 milestone Mar 27, 2023
@MarcoGorelli MarcoGorelli added the Closing Candidate May be closeable, needs more eyeballs label Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

4 participants