Skip to content
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

Address pandas 2.1.0 FutureWarning on wind rose plot #710

Merged
merged 5 commits into from Sep 11, 2023

Conversation

pablo-benito
Copy link
Contributor

Remove pandas v2.1.0 FutureWarning on Wind Rose plot

Using FLORIS with pandas v2.1.0, the WindRose functions plot_wind_rose triggers a FutureWarning

Example code:

import pandas as pd
from floris.tools.wind_rose import WindRose
import matplotlib.pylab as plt

print(f'Using pandas version {pd.__version__}') 
wr = WindRose()
wr.make_wind_rose_from_user_data([1,2,3], [4,5,6])
wr.plot_wind_rose()

plt.show()

Output:

Using pandas version 2.1.0
Correcting negative Overhang:-2.5
Correcting negative Overhang:-7.5
wind_rose.py:165: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
  df = df.groupby([c for c in df.columns if c != "freq_val"]).sum()
wind_rose.py:264: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
  df = df.groupby([c for c in df.columns if c != "freq_val"]).sum()

The default of observed=False in pandas.DataFrame.groupby will change in a future version of pandas, so starting with pandas 2.1.0 it raises a FutureWarning if you don't use it explicitly when grouping by a categorical column. This PR removes those warnings

Related issue

None

Impacted areas of the software

wind_rose.py

Additional supporting information

From pandas v2.1.0 Changelog:

Deprecated the default of observed=False in DataFrame.groupby() and Series.groupby(); this will default to True in a future version (GH 43999)

Test results, if applicable

None

pablo-benito and others added 5 commits September 11, 2023 12:43
Starting with pandas 2.1.0, grouping by a Categorical column raises a FutureWarning, as the value of the 'observed' flag will change in future versions of pandas.

Setting it explicitly silents this warning
@rafmudaf
Copy link
Collaborator

Good catch @pablo-benito, thank you for submitting this update. Also, many thanks for the well described pull request.
Send my hello to the CENER crew 👋

@rafmudaf rafmudaf merged commit 77ea50d into NREL:develop Sep 11, 2023
5 checks passed
@rafmudaf rafmudaf added the bug Something isn't working label Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants