FutureWarning
FutureWarning: behavior will change in a future version
Traceback
Traceback (most recent call last):
File "main.py", line 2, in <module>
df = pd.concat([df1, df2]) # sort behavior changing
FutureWarning: behavior will change in a future versionWhat causes this error
The behavior of a feature will change in a future version. The current behavior still works but will produce different results after an upgrade.
How to fix it
Explicitly specify the parameter or behavior that will change. Read the warning message for details on the upcoming change. Update code to match the future behavior before upgrading.
Code that causes this error
import pandas as pd df = pd.concat([df1, df2]) # sort behavior changing
Fixed code
import pandas as pd df = pd.concat([df1, df2], sort=False) # explicit
About FutureWarning
A FutureWarning indicates that the behavior of a feature will change in a future version, unlike DeprecationWarning which indicates removal. FutureWarning is shown to end users by default (unlike DeprecationWarning) because the code will continue to work but produce different results. This is particularly common in scientific Python libraries: numpy and pandas use FutureWarning extensively to signal upcoming changes to default parameter values, data type inference, and method behaviors.
For example, pandas may warn that a default parameter will change from `sort=True` to `sort=False` in a future release. Addressing FutureWarnings is important because ignoring them means your code's output may silently change when you upgrade the library. The fix is usually to explicitly pass the parameter that will change.
Common scenarios
Using deprecated APIs that will be removed in future versions
Performing numerical operations that produce inf or NaN values
Leaving files, sockets, or connections open without proper cleanup
Calling async functions without awaiting the result