Repository: pandas-dev/pandas

Issue:
Concatenation warning still appears with sort=False
#### Code Sample, a copy-pastable example if possible

```python
a = pd.DataFrame(
    {'col1': [1, 2, 3, 4, 5],
     'col2': [6, 7, 8, 9, 10]},
    index=['a', 'c', 'e', 'f', 'i'])
a.index.name = 'index_name'
b = pd.DataFrame(
    {'col4': [1, 2, 3, 4, 5],
     'col3': [1, 2, 3, 4, 5]},
    index=['a', 'b', 'c', 'd', 'e'])
b.index.name = 'index_name'
c = pd.DataFrame(
    {'col5': [1, 2, 3, 4, 5]},
    index=['f', 'g', 'h', 'i', 'j'])
c.index.name = 'index_name'
dfs = [a, b, c]

dfs[0].join(dfs[1:], how='outer', sort=True)
dfs[0].join(dfs[1:], how='outer', sort=False)
```

#### Problem description

Running either or the last two lines still shows the warning. For example, the last step gives me
```
/homes/nber/barronk-dua51929/local/anaconda3/envs/medicare_utils/lib/python3.6/site-packages/pandas/core/frame.py:6369: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

  verify_integrity=True)
col1	col2	col4	col3	col5
a	1.0	6.0	1.0	1.0	NaN
b	NaN	NaN	2.0	2.0	NaN
c	2.0	7.0	3.0	3.0	NaN
d	NaN	NaN	4.0	4.0	NaN
e	3.0	8.0	5.0	5.0	NaN
f	4.0	9.0	NaN	NaN	1.0
g	NaN	NaN	NaN	NaN	2.0
h	NaN	NaN	NaN	NaN	3.0
i	5.0	10.0	NaN	NaN	4.0
j	NaN	NaN	NaN	NaN	5.0
```

By passing `sort=False`, the warning should be hidden. From [here](https://pandas.pydata.org/pandas-docs/stable/whatsnew.html#concatenation-will-no-longer-sort) I believed that passing `True` or `False` for the sort argument should silence the warning.

I'm using pandas 0.23.3.

#### Expected Output

Silenced warning.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.32-696.18.7.el6.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.3
pytest: 3.6.2
pip: 9.0.1
setuptools: 39.2.0
Cython: 0.28.4
numpy: 1.14.5
scipy: 1.1.0
pyarrow: 0.9.0
xarray: None
IPython: 6.4.0
sphinx: 1.7.5
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: 4.2.3
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: 0.1.5
pandas_gbq: None
pandas_datareader: None

</details>



Discussion:
Thanks for the report - investigation and PRs are always welcome!
Same issue here.
It seems we fail to pass `sort` through here

https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L7217-L7223

A PR adding that with tests would be quite welcome. Tests can go in https://github.com/pandas-dev/pandas/blob/0fd888c8b318d4041b0ae53c64715eca0d345dd3/pandas/tests/reshape/test_concat.py#L1145.
Looking to start contributing. I'll work on a PR for this. 

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -7217,10 +7217,14 @@ def _join_compat(
             # join indexes only using concat
             if can_concat:
                 if how == "left":
-                    res = concat(frames, axis=1, join="outer", verify_integrity=True)
+                    res = concat(
+                        frames, axis=1, join="outer", verify_integrity=True, sort=sort
+                    )
                     return res.reindex(self.index, copy=False)
                 else:
-                    return concat(frames, axis=1, join=how, verify_integrity=True)
+                    return concat(
+                        frames, axis=1, join=how, verify_integrity=True, sort=sort
+                    )
 
             joined = frames[0]
 


Test patch:
diff --git a/pandas/tests/frame/test_join.py b/pandas/tests/frame/test_join.py
--- a/pandas/tests/frame/test_join.py
+++ b/pandas/tests/frame/test_join.py
@@ -193,3 +193,32 @@ def test_join_left_sequence_non_unique_index():
     )
 
     tm.assert_frame_equal(joined, expected)
+
+
+@pytest.mark.parametrize("sort_kw", [True, False, None])
+def test_suppress_future_warning_with_sort_kw(sort_kw):
+    a = DataFrame({"col1": [1, 2]}, index=["c", "a"])
+
+    b = DataFrame({"col2": [4, 5]}, index=["b", "a"])
+
+    c = DataFrame({"col3": [7, 8]}, index=["a", "b"])
+
+    expected = DataFrame(
+        {
+            "col1": {"a": 2.0, "b": float("nan"), "c": 1.0},
+            "col2": {"a": 5.0, "b": 4.0, "c": float("nan")},
+            "col3": {"a": 7.0, "b": 8.0, "c": float("nan")},
+        }
+    )
+    if sort_kw is False:
+        expected = expected.reindex(index=["c", "a", "b"])
+
+    if sort_kw is None:
+        # only warn if not explicitly specified
+        ctx = tm.assert_produces_warning(FutureWarning, check_stacklevel=False)
+    else:
+        ctx = tm.assert_produces_warning(None, check_stacklevel=False)
+
+    with ctx:
+        result = a.join([b, c], how="outer", sort=sort_kw)
+    tm.assert_frame_equal(result, expected)