Skip to content

Commit a98ab6d

Browse files
authored
CLN Remove pandas from bart.utils.plot_dependence (#5558)
1 parent 620546b commit a98ab6d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pymc/bart/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import arviz as az
22
import matplotlib.pyplot as plt
33
import numpy as np
4-
import pandas as pd
54

65
from numpy.random import RandomState
76
from scipy.interpolate import griddata
@@ -147,13 +146,13 @@ def plot_dependence(
147146

148147
rng = RandomState(seed=random_seed)
149148

150-
if isinstance(X, pd.DataFrame):
149+
if hasattr(X, "columns") and hasattr(X, "values"):
151150
X_names = list(X.columns)
152151
X = X.values
153152
else:
154153
X_names = []
155154

156-
if isinstance(Y, pd.DataFrame):
155+
if hasattr(Y, "name"):
157156
Y_label = f"Predicted {Y.name}"
158157
else:
159158
Y_label = "Predicted Y"

pymc/tests/test_bart.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
from numpy.random import RandomState
5-
from numpy.testing import assert_almost_equal
5+
from numpy.testing import assert_almost_equal, assert_array_equal
66

77
import pymc as pm
88

@@ -103,6 +103,18 @@ def test_predict(self):
103103
def test_pdp(self, kwargs):
104104
pm.bart.utils.plot_dependence(self.idata, X=self.X, Y=self.Y, **kwargs)
105105

106+
def test_pdp_pandas_labels(self):
107+
pd = pytest.importorskip("pandas")
108+
109+
X_names = ["norm1", "norm2", "binom"]
110+
X_pd = pd.DataFrame(self.X, columns=X_names)
111+
Y_pd = pd.Series(self.Y, name="response")
112+
axes = pm.bart.utils.plot_dependence(self.idata, X=X_pd, Y=Y_pd)
113+
114+
figure = axes[0].figure
115+
assert figure.texts[0].get_text() == "Predicted response"
116+
assert_array_equal([ax.get_xlabel() for ax in axes], X_names)
117+
106118

107119
@pytest.mark.parametrize(
108120
"size, expected",

0 commit comments

Comments
 (0)