intel / p3-analysis-library

A library simplifying the collection and interpretation of P3 data.
https://intel.github.io/p3-analysis-library/
MIT License
7 stars 10 forks source link

Multiple FutureWarning on Pandas 2.2.2 #38

Closed tom91136 closed 1 month ago

tom91136 commented 4 months ago

Expected behavior

No warnings of any kind

Actual behavior

Multiple occurrences of the following:

/home/tom/p3-analysis-library/p3/metrics/_efficiency.py:58: FutureWarning: The provided callable <built-in function min> is currently using DataFrameGroupBy.min. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string "min" instead.
  best = groups.agg(min) if foms == "lower" else groups.agg(max)
/home/tom/p3-analysis-library/p3/metrics/_efficiency.py:65: FutureWarning: Calling float on a single element Series is deprecated and will raise a TypeError in the future. Use float(ser.iloc[0]) instead
  best_fom = float(best.loc[(best[key] == value).all(1)]["fom"])

Steps to reproduce the problem

effs = p3.metrics.application_efficiency(df)

The warnings go away with:

diff --git a/p3/metrics/_efficiency.py b/p3/metrics/_efficiency.py
index bd7bc88..c18a1ba 100644
--- a/p3/metrics/_efficiency.py
+++ b/p3/metrics/_efficiency.py
@@ -55,14 +55,14 @@ def application_efficiency(df, foms="lower"):
     # Identify the best FOM for each (problem, platform) triple
     key = ["problem", "platform"]
     groups = df[key + ["fom"]].groupby(key)
-    best = groups.agg(min) if foms == "lower" else groups.agg(max)
+    best = groups.agg("min") if foms == "lower" else groups.agg("max")
     best.reset_index(inplace=True)

     # Calculate application efficiency
     def app_eff(row):
         value = [row["problem"], row["platform"]]
         fom = float(row["fom"])
-        best_fom = float(best.loc[(best[key] == value).all(1)]["fom"])
+        best_fom = float(best.loc[(best[key] == value).all(1)]["fom"].iloc[0])
         if foms == "lower":
             return 0.0 if numpy.isnan(fom) else (best_fom / fom)
         else:
diff --git a/p3/metrics/_pp.py b/p3/metrics/_pp.py
index 5f6ef5b..2c9039f 100644
--- a/p3/metrics/_pp.py
+++ b/p3/metrics/_pp.py
@@ -86,7 +86,7 @@ def pp(df):
     # Keep only the most efficient (application, platform) results.
     key = ["problem", "platform", "application"]
     groups = df[key + efficiencies].groupby(key)
-    df = groups.agg(max)
+    df = groups.agg("max")
     df.reset_index(inplace=True)

     # Add a "did not run" value for applications that did not run

Let me know if PRs are welcome.

Specifications

attrs==23.2.0 contourpy==1.2.1 cssselect==1.2.0 cycler==0.12.1 fonttools==4.51.0 importlib_resources==6.4.0 jsonschema==4.21.1 jsonschema-specifications==2023.12.1 kiwisolver==1.4.5 lxml==5.2.1 matplotlib==3.8.4 numpy==1.26.4 -e git+ssh://git@github.com/intel/p3-analysis-library.git@69aaa926b5f20e755852caa9014948134c5ca9f6#egg=p3 packaging==24.0 pandas==2.2.2 pillow==10.3.0 pyparsing==3.1.2 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.34.0 rpds-py==0.18.0 six==1.16.0 tzdata==2024.1 zipp==3.18.1

Pennycook commented 4 months ago

Thanks for reporting this, @tom91136. PRs are definitely welcome, so please feel free to open a PR with the changes.