From d975511849bcc8adfcf96667e946d991c453c0ea Mon Sep 17 00:00:00 2001 From: Eytan Bakshy Date: Thu, 19 Mar 2026 08:30:51 -0700 Subject: [PATCH] Fix pandas FutureWarning in Data.deduplicate for groupby operations (#5069) Summary: Pull Request resolved: https://github.com/facebook/Ax/pull/5069 Fixes a pandas FutureWarning that appears when using `DataFrameGroupBy.apply` on grouping columns by changing to `SeriesGroupBy.apply`. The fix adds `[MAP_KEY]` selector before `.apply()` at line 360 in `ax/core/data.py`, which operates on the series rather than the entire grouped DataFrame. This eliminates the deprecation warning on pandas >= 2.1 while maintaining backward compatibility with older pandas versions. -- Reviewed + modified AI generated Summary & Test Plan from DEV115723120 Reviewed By: saitcakmak Differential Revision: D97020436 --- ax/core/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ax/core/data.py b/ax/core/data.py index 7ec309442a4..2939143ff79 100644 --- a/ax/core/data.py +++ b/ax/core/data.py @@ -357,7 +357,7 @@ def df(self) -> pd.DataFrame: # In the case where all MAP_KEY values are NaN for a group we return an # arbitrary row from that group. .fillna( - self.full_df.groupby(self.DEDUPLICATE_BY_COLUMNS).apply( + self.full_df.groupby(self.DEDUPLICATE_BY_COLUMNS)[MAP_KEY].apply( lambda group: group.index[0] ) )