Skip to content

"Concatenation will no longer sort" wording is very inconsistent #21112

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
quant5 opened this issue May 17, 2018 · 15 comments
Closed

"Concatenation will no longer sort" wording is very inconsistent #21112

quant5 opened this issue May 17, 2018 · 15 comments

Comments

@quant5
Copy link

quant5 commented May 17, 2018

The wording in the update docs is (emphasis added):

In a future version of pandas pandas.concat() will no longer sort the non-concatenation axis when it is not already aligned. (...)

To keep the previous behavior (sorting) and silence the warning, pass sort=True.
To accept the future behavior (no sorting), pass sort=False

https://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#concatenation-will-no-longer-sort

But the wording in the FutureWarning messages is (emphasis added):

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=True.
To retain the current behavior and silence the warning, pass sort=False

https://github.com/pandas-dev/pandas/blob/c4da79b5b322c73d8e61d1cb98ac4ab1e2438b40/pandas/core/indexes/api.py

It needs to be clearer that current default is still sort=True but will revert to sort=False in a future version.

@TomAugspurger
Copy link
Contributor

It's confusing because it's wrong :)

Duplicate of #21101 if you want to take a look at fixing it.

@techvslife
Copy link

techvslife commented May 21, 2018

also: Currently the warning doesn't get silenced if you pass "sort=False" (i.e. the true future default behavior)--presumably there should be no warning as long as the sort parameter is explicitly set (passed).

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 21, 2018 via email

@techvslife
Copy link

techvslife commented May 21, 2018

Yes, what happens is that it does not produce the line of code in the warning (as it does when you omit the sort parameter), but it does still print the warning (this is the exact text and line spacing, not sure why the last line looks so strange):

C:\Users\mlopez\Anaconda3\lib\site-packages\pandas\core\frame.py:6201: 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=True'.

To retain the current behavior and silence the warning, pass sort=False

  sort=sort)

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 21, 2018 via email

@techvslife
Copy link

Sorry, I'm not having luck reproducing with a small example; may not be a concat command, but a merge command instead. Unfortunately I don't know what line in code is triggering the warning from the warning.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 21, 2018 via email

@techvslife
Copy link

ok thanks, I'll try re-running it, but I won't be able to set up the full script today.

@techvslife
Copy link

Ok, I found it. It actually was an append command (not concat or merge). Adding the sort parameter did remove the warning. I added the sort=False parameter to this:
df_B = df_A.append(df_B, verify_integrity=True, sort=False).copy()

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 26, 2018 via email

@allayli
Copy link

allayli commented Jun 7, 2018

It seems that sort=None is NOT backward compatible.
Why NOT make it True by default? Or any Global config can set it be True?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 7, 2018 via email

@TasneemVKhan
Copy link

i had the same error I resolved it using
store_items = store_items.append(new_store , sort=True)

You just have to add sort =True to your code and the warning disappears

@Dougz00
Copy link

Dougz00 commented Jan 21, 2020

If you are using glob and a loop to read a large number of csv files this also works:
files = glob.glob(pattern)
df = pd.DataFrame()
for f in files:
df = df.append(pd.read_csv(f),sort=True)

@jreback
Copy link
Contributor

jreback commented Jan 22, 2020

If you are using glob and a loop to read a large number of csv files this also works:
files = glob.glob(pattern)
df = pd.DataFrame()
for f in files:
df = df.append(pd.read_csv(f),sort=True)

@Dougz00 that is exponential time

concatenation a list of data frames ; don’t append
see the append warnings in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants