-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Closed
Labels
API - ConsistencyInternal Consistency of API/BehaviorInternal Consistency of API/BehaviorBugReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeSortinge.g. sort_index, sort_valuese.g. sort_index, sort_values
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 pandas as pd
a = pd.DataFrame(np.ones((4, 2)), index=[3,2,1,0])
b = pd.DataFrame(2*np.ones((2, 1)), columns=[2], index=[3,1])
c = pd.DataFrame(3*np.ones((2, 1)), columns=[3], index=[3,1])
a.join(b, how='outer') # correct, the index is [0,1,2,3]
b.join(a, how='outer') # correct, the index is [0,1,2,3]
a.join([b, c], how='outer') # incorrect, the index is [3,2,1,0]
b.join([a, c], how='outer') # incorrect, the index is [3,1,2,0]Issue Description
The document of join says:
outer: form union of calling frame’s index (or column if on is specified) with other’s index, and sort it. lexicographically.
But the behavior is not consistent. when joining more than 2 dataframes, the result remains unsorted, which is a bug.
Expected Behavior
The result should be sorted when outer joining multiple dataframes. This test should be passed for the example above:
assert a.join([b, c], how='outer').equals(a.join([b, c], how='outer', sort=True))Installed Versions
1.5.0.dev0+471.g8e0baa2360
Metadata
Metadata
Assignees
Labels
API - ConsistencyInternal Consistency of API/BehaviorInternal Consistency of API/BehaviorBugReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, ExplodeSortinge.g. sort_index, sort_valuese.g. sort_index, sort_values