Skip to content

Commit 5323733

Browse files
Jammy2211claude
authored andcommitted
fix: make SettingWithCopyWarning import pandas>=2.2 compatible
pandas 2.2 removed `pandas.errors.SettingWithCopyWarning`, which broke nest_plotters import on modern pandas. Guard the import so the warning filter is only applied when the class exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5547313 commit 5323733

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

autofit/non_linear/plot/nest_plotters.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,22 @@ def corner_anesthetic(samples, path=None, filename="corner_anesthetic", format="
3535
columns=model.parameter_labels_with_superscripts_latex,
3636
)
3737

38-
from pandas.errors import SettingWithCopyWarning
38+
try:
39+
from pandas.errors import SettingWithCopyWarning
40+
except ImportError: # pandas >= 2.2 removed SettingWithCopyWarning
41+
SettingWithCopyWarning = None
3942

40-
warnings.filterwarnings("ignore", category=SettingWithCopyWarning)
43+
if SettingWithCopyWarning is not None:
44+
warnings.filterwarnings("ignore", category=SettingWithCopyWarning)
4145

4246
fig, axes = make_2d_axes(
4347
model.parameter_labels_with_superscripts_latex,
4448
figsize=figsize,
4549
facecolor=config_dict["facecolor"],
4650
)
4751

48-
warnings.filterwarnings("default", category=SettingWithCopyWarning)
52+
if SettingWithCopyWarning is not None:
53+
warnings.filterwarnings("default", category=SettingWithCopyWarning)
4954

5055
nested_samples.plot_2d(
5156
axes,

0 commit comments

Comments
 (0)