|
22 | 22 | from ..utility.beta_pert import FairBetaPert |
23 | 23 |
|
24 | 24 |
|
| 25 | +def _dataframe_elementwise(df, func): |
| 26 | + """Element-wise transform; pandas 2.1+ uses map, older uses applymap.""" |
| 27 | + applymap = getattr(df, "applymap", None) |
| 28 | + if applymap is not None: |
| 29 | + return applymap(func) |
| 30 | + return df.map(func) |
| 31 | + |
| 32 | + |
25 | 33 | class FairBaseReport(object): |
26 | 34 | """A base class for creating FairModel and FairMetaModel reports |
27 | 35 |
|
@@ -262,8 +270,8 @@ def _get_overview_table(self, model_or_models): |
262 | 270 | risk_results = risk_results.agg(["mean", "std", "min", "max"]) |
263 | 271 | risk_results.index = ["Mean", "Stdev", "Minimum", "Maximum"] |
264 | 272 | # Format risk results into dataframe |
265 | | - overview_df = risk_results.map( |
266 | | - lambda x: self._format_strings["Risk"].format(x) |
| 273 | + overview_df = _dataframe_elementwise( |
| 274 | + risk_results, lambda x: self._format_strings["Risk"].format(x) |
267 | 275 | ) |
268 | 276 | overview_df.loc["Simulations"] = [ |
269 | 277 | "{0:,.0f}".format(len(model.export_results())) |
@@ -321,7 +329,9 @@ def _get_model_parameter_table(self, model): |
321 | 329 | # On a column basis |
322 | 330 | axis=1, |
323 | 331 | ) |
324 | | - param_df = param_df.map(lambda x: "" if "nan" in x else x) |
| 332 | + param_df = _dataframe_elementwise( |
| 333 | + param_df, lambda x: "" if "nan" in x else x |
| 334 | + ) |
325 | 335 | # Do not truncate our base64 images. |
326 | 336 | pd.set_option("display.max_colwidth", None) |
327 | 337 | # Create our distribution icons as strings in table |
|
0 commit comments