Skip to content

Commit

Permalink
shallow copy input dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaozGelbart committed Jan 18, 2020
1 parent 3cb5cca commit 7cd7285
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
18 changes: 6 additions & 12 deletions seaborn/axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,12 +2110,9 @@ def pairplot(data, hue=None, hue_order=None, palette=None,
"'data' must be pandas DataFrame object, not: {typefound}".format(
typefound=type(data)))

if plot_kws is None:
plot_kws = {}
if diag_kws is None:
diag_kws = {}
if grid_kws is None:
grid_kws = {}
plot_kws = {} if plot_kws is None else plot_kws.copy()
diag_kws = {} if diag_kws is None else diag_kws.copy()
grid_kws = {} if grid_kws is None else grid_kws.copy()

# Set up the PairGrid
grid_kws.setdefault("diag_sharey", diag_kind == "hist")
Expand Down Expand Up @@ -2302,13 +2299,10 @@ def jointplot(x, y, data=None, kind="scatter", stat_func=None,
warnings.warn(msg, UserWarning)

# Set up empty default kwarg dicts
if joint_kws is None:
joint_kws = {}
joint_kws = {} if joint_kws is None else joint_kws.copy()
joint_kws.update(kwargs)
if marginal_kws is None:
marginal_kws = {}
if annot_kws is None:
annot_kws = {}
marginal_kws = {} if marginal_kws is None else marginal_kws.copy()
annot_kws = {} if annot_kws is None else annot_kws.copy()

# Make a colormap based off the plot color
if color is None:
Expand Down
12 changes: 4 additions & 8 deletions seaborn/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,10 @@ def distplot(a, bins=None, hist=True, kde=True, rug=False, fit=None,
norm_hist = norm_hist or kde or (fit is not None)

# Handle dictionary defaults
if hist_kws is None:
hist_kws = dict()
if kde_kws is None:
kde_kws = dict()
if rug_kws is None:
rug_kws = dict()
if fit_kws is None:
fit_kws = dict()
hist_kws = {} if hist_kws is None else hist_kws.copy()
kde_kws = {} if kde_kws is None else kde_kws.copy()
rug_kws = {} if rug_kws is None else rug_kws.copy()
fit_kws = {} if fit_kws is None else fit_kws.copy()

# Get the color from the current color cycle
if color is None:
Expand Down
4 changes: 2 additions & 2 deletions seaborn/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def __init__(self, data, vmin, vmax, cmap, center, robust, annot, fmt,
self.annot_data = annot_data

self.fmt = fmt
self.annot_kws = {} if annot_kws is None else annot_kws
self.annot_kws = {} if annot_kws is None else annot_kws.copy()
self.cbar = cbar
self.cbar_kws = {} if cbar_kws is None else cbar_kws
self.cbar_kws = {} if cbar_kws is None else cbar_kws.copy()
self.cbar_kws.setdefault('ticks', mpl.ticker.MaxNLocator(6))

def _determine_cmap_params(self, plot_data, vmin, vmax,
Expand Down
4 changes: 2 additions & 2 deletions seaborn/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ def residplot(x, y, data=None, lowess=False, x_partial=None, y_partial=None,
ax.axhline(0, ls=":", c=".2")

# Draw the scatterplot
scatter_kws = {} if scatter_kws is None else scatter_kws
line_kws = {} if line_kws is None else line_kws
scatter_kws = {} if scatter_kws is None else scatter_kws.copy()
line_kws = {} if line_kws is None else line_kws.copy()
plotter.plot(ax, scatter_kws, line_kws)
return ax
9 changes: 9 additions & 0 deletions seaborn/tests/test_axisgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,3 +1600,12 @@ def test_bad_kind(self):

with nt.assert_raises(ValueError):
ag.jointplot("x", "y", self.data, kind="not_a_kind")

def test_leaky_dict(self):
# Validate input dicts are unchanged by jointplot plotting function

for kwarg in ("joint_kws", "marginal_kws", "annot_kws"):
for kind in ("hex", "kde", "resid", "reg", "scatter"):
empty_dict={}
g = ag.jointplot("x", "y", self.data, kind=kind, **{kwarg:empty_dict})
assert empty_dict == {}

0 comments on commit 7cd7285

Please sign in to comment.