-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Open
Labels
BugNeeds DiscussionRequires discussion from core team before further actionRequires discussion from core team before further actionReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeWarningsWarnings that appear or should be added to pandasWarnings that appear or should be added to pandas
Milestone
Description
The warning is due to #39122
pd.set_option("infer_string", True)
df = pd.DataFrame({"a": "x", "b": ["y", "z"]}).set_index(["a", "b"])
df.columns = pd.Index([], dtype="int")
ser = pd.DataFrame({"b": ["y", "z"], "value": [1, 2]}).set_index("b")["value"]
df.join(ser, on="b")
# FutureWarning: The behavior of array concatenation with empty entries is deprecated...In the above code, we hit
pandas/pandas/core/reshape/merge.py
Line 1134 in 82fa271
| result = concat([left, right], axis=1) |
with left having no columns but of int64 dtype and right having columns with str dtype. Both before and after the deprecation we get str dtype for the columns. The call to pandas.core.dtypes.concat.concat_compact does result in object dtype, but then we wrap this with Index._with_infer(...) in Index._concat giving str again.
Should we be inferring dtype after the concat index is determined?
In merge, it seems to me we should skip calling concat with axis=1 if left or right has empty columns but perhaps still call concat if both are empty.
Metadata
Metadata
Assignees
Labels
BugNeeds DiscussionRequires discussion from core team before further actionRequires discussion from core team before further actionReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeWarningsWarnings that appear or should be added to pandasWarnings that appear or should be added to pandas