Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require keyword arguments almost everywhere #2081

Merged
merged 6 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/releases/v0.11.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ v0.11.0 (Unreleased)

- TODO stub for explaining improvements to variable specificiation. Make this good! GH2017

- Enforced keyword-only arguments for most parameters of most functions and classes. GH2052
- TODO stub for enforced keyword-only arguments for most parameters of most functions and classes. GH2052, GH2081

- Standardized the parameter names for the oldest functions (:func:`distplot`, :func:`kdeplot`, and :func:`rugplot`) to be `x` and `y`, as in other functions. Using the old names will warn now and break in the future. GH2060

Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial/axis_grids.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"outputs": [],
"source": [
"g = sns.FacetGrid(tips, col=\"day\", height=4, aspect=.5)\n",
"g.map(sns.barplot, \"sex\", \"total_bill\");"
"g.map(sns.barplot, \"sex\", \"total_bill\", order=[\"Male\", \"Female\"]);"
]
},
{
Expand Down
9 changes: 4 additions & 5 deletions doc/tutorial/categorical.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.catplot(x=\"size\", y=\"total_bill\", kind=\"swarm\",\n",
" data=tips.query(\"size != 3\"));"
"sns.catplot(x=\"size\", y=\"total_bill\", data=tips);"
]
},
{
Expand Down Expand Up @@ -526,7 +525,7 @@
"outputs": [],
"source": [
"sns.catplot(x=\"day\", y=\"total_bill\", hue=\"smoker\",\n",
" col=\"time\", aspect=.6,\n",
" col=\"time\", aspect=.7,\n",
" kind=\"swarm\", data=tips);"
]
},
Expand Down Expand Up @@ -562,7 +561,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3.6 (seaborn-py37-latest)",
"display_name": "seaborn-py37-latest",
"language": "python",
"name": "seaborn-py37-latest"
},
Expand All @@ -580,5 +579,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
8 changes: 4 additions & 4 deletions doc/tutorial/color_palettes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
"source": [
"x, y = np.random.multivariate_normal([0, 0], [[1, -.5], [-.5, 1]], size=300).T\n",
"cmap = sns.cubehelix_palette(light=1, as_cmap=True)\n",
"sns.kdeplot(x, y, cmap=cmap, shade=True);"
"sns.kdeplot(x=x, y=y, cmap=cmap, shade=True);"
]
},
{
Expand Down Expand Up @@ -527,7 +527,7 @@
"outputs": [],
"source": [
"pal = sns.dark_palette(\"palegreen\", as_cmap=True)\n",
"sns.kdeplot(x, y, cmap=pal);"
"sns.kdeplot(x=x, y=y, cmap=pal);"
]
},
{
Expand Down Expand Up @@ -738,7 +738,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3.6 (seaborn-py37-latest)",
"display_name": "seaborn-py37-latest",
"language": "python",
"name": "seaborn-py37-latest"
},
Expand All @@ -756,5 +756,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
36 changes: 18 additions & 18 deletions doc/tutorial/distributions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"outputs": [],
"source": [
"x = np.random.normal(size=100)\n",
"sns.distplot(x);"
"sns.distplot(x=x);"
]
},
{
Expand All @@ -102,7 +102,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.distplot(x, kde=False, rug=True);"
"sns.distplot(x=x, kde=False, rug=True);"
]
},
{
Expand All @@ -118,7 +118,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.distplot(x, bins=20, kde=False, rug=True);"
"sns.distplot(x=x, bins=20, kde=False, rug=True);"
]
},
{
Expand All @@ -137,7 +137,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.distplot(x, hist=False, rug=True);"
"sns.distplot(x=x, hist=False, rug=True);"
]
},
{
Expand All @@ -164,7 +164,7 @@
" kernels.append(kernel)\n",
" plt.plot(support, kernel, color=\"r\")\n",
"\n",
"sns.rugplot(x, color=\".2\", linewidth=3);"
"sns.rugplot(x=x, color=\".2\", linewidth=3);"
]
},
{
Expand Down Expand Up @@ -199,7 +199,7 @@
"metadata": {},
"outputs": [],
"source": [
"sns.kdeplot(x, shade=True);"
"sns.kdeplot(x=x, shade=True);"
]
},
{
Expand All @@ -215,9 +215,9 @@
"metadata": {},
"outputs": [],
"source": [
"sns.kdeplot(x)\n",
"sns.kdeplot(x, bw=.2, label=\"bw: 0.2\")\n",
"sns.kdeplot(x, bw=2, label=\"bw: 2\")\n",
"sns.kdeplot(x=x)\n",
"sns.kdeplot(x=x, bw=.2, label=\"bw: 0.2\")\n",
"sns.kdeplot(x=x, bw=2, label=\"bw: 2\")\n",
"plt.legend();"
]
},
Expand All @@ -234,8 +234,8 @@
"metadata": {},
"outputs": [],
"source": [
"sns.kdeplot(x, shade=True, cut=0)\n",
"sns.rugplot(x);"
"sns.kdeplot(x=x, shade=True, cut=0)\n",
"sns.rugplot(x=x);"
]
},
{
Expand All @@ -255,7 +255,7 @@
"outputs": [],
"source": [
"x = np.random.gamma(6, size=200)\n",
"sns.distplot(x, kde=False, fit=stats.gamma);"
"sns.distplot(x=x, kde=False, fit=stats.gamma);"
]
},
{
Expand Down Expand Up @@ -352,9 +352,9 @@
"outputs": [],
"source": [
"f, ax = plt.subplots(figsize=(6, 6))\n",
"sns.kdeplot(df.x, df.y, ax=ax)\n",
"sns.rugplot(df.x, color=\"g\", ax=ax)\n",
"sns.rugplot(df.y, vertical=True, ax=ax);"
"sns.kdeplot(x=df.x, y=df.y, ax=ax)\n",
"sns.rugplot(x=df.x, color=\"g\", ax=ax)\n",
"sns.rugplot(x=df.y, vertical=True, ax=ax);"
]
},
{
Expand All @@ -372,7 +372,7 @@
"source": [
"f, ax = plt.subplots(figsize=(6, 6))\n",
"cmap = sns.cubehelix_palette(as_cmap=True, dark=0, light=1, reverse=True)\n",
"sns.kdeplot(df.x, df.y, cmap=cmap, n_levels=60, shade=True);"
"sns.kdeplot(x=df.x, y=df.y, cmap=cmap, n_levels=60, shade=True);"
]
},
{
Expand Down Expand Up @@ -461,7 +461,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3.6 (seaborn-py37-latest)",
"display_name": "seaborn-py37-latest",
"language": "python",
"name": "seaborn-py37-latest"
},
Expand All @@ -479,5 +479,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
8 changes: 3 additions & 5 deletions doc/tutorial/regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@
},
{
"cell_type": "raw",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"In the presence of these kind of higher-order relationships, :func:`lmplot` and :func:`regplot` can fit a polynomial regression model to explore simple kinds of nonlinear trends in the dataset:"
]
Expand Down Expand Up @@ -517,7 +515,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3.6 (seaborn-py37-latest)",
"display_name": "seaborn-py37-latest",
"language": "python",
"name": "seaborn-py37-latest"
},
Expand All @@ -535,5 +533,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
8 changes: 3 additions & 5 deletions doc/tutorial/relational.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@
},
{
"cell_type": "raw",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"The default colormap and handling of the legend in :func:`lineplot` also depends on whether the hue semantic is categorical or numeric:"
]
Expand Down Expand Up @@ -616,7 +614,7 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3.6 (seaborn-py37-latest)",
"display_name": "seaborn-py37-latest",
"language": "python",
"name": "seaborn-py37-latest"
},
Expand All @@ -634,5 +632,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion examples/cubehelix_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Generate and plot a random bivariate dataset
x, y = rs.randn(2, 50)
sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=ax)
sns.kdeplot(x=x, y=y, cmap=cmap, shade=True, cut=5, ax=ax)
ax.set(xlim=(-3, 3), ylim=(-3, 3))

f.tight_layout()
13 changes: 7 additions & 6 deletions examples/distplot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
sns.despine(left=True)

# Generate a random univariate dataset
d = rs.normal(size=100)
x = rs.normal(size=100)

# Plot a simple histogram with binsize determined automatically
sns.distplot(d, kde=False, color="b", ax=axes[0, 0])
sns.distplot(x=x, kde=False, color="b", ax=axes[0, 0])

# Plot a kernel density estimate and rug plot
sns.distplot(d, hist=False, rug=True, color="r", ax=axes[0, 1])
sns.distplot(x=x, hist=False, rug=True, color="r", ax=axes[0, 1])

# Plot a filled kernel density estimate
sns.distplot(d, hist=False, color="g", kde_kws={"shade": True}, ax=axes[1, 0])
sns.distplot(x=x, hist=False, color="g",
kde_kws={"shade": True}, ax=axes[1, 0])

# Plot a histogram and kernel density estimate
sns.distplot(d, color="m", ax=axes[1, 1])
sns.distplot(x=x, color="m", ax=axes[1, 1])

plt.setp(axes, yticks=[])
plt.tight_layout()
f.tight_layout()
2 changes: 1 addition & 1 deletion examples/hexbin_marginals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
x = rs.gamma(2, size=1000)
y = -.5 * x + rs.normal(size=1000)

sns.jointplot(x, y, kind="hex", color="#4CB391")
sns.jointplot(x=x, y=y, kind="hex", color="#4CB391")
2 changes: 1 addition & 1 deletion examples/joint_kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
x2 = pd.Series(x2, name="$X_2$")

# Show the joint distribution using kernel density estimation
g = sns.jointplot(x1, x2, kind="kde", height=7, space=0)
g = sns.jointplot(x=x1, y=x2, kind="kde", height=7, space=0)
2 changes: 1 addition & 1 deletion examples/marginal_ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
x, y = rs.multivariate_normal(mean, cov, 100).T

# Use JointGrid directly to draw a custom plot
grid = sns.JointGrid(x, y, space=0, height=6, ratio=20)
grid = sns.JointGrid(x=x, y=y, space=0, height=6, ratio=20)
grid.plot_joint(sns.scatterplot, color="g")
grid.plot_marginals(sns.rugplot, height=1, color="g")
2 changes: 1 addition & 1 deletion examples/regression_marginals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sns.set(style="darkgrid")

tips = sns.load_dataset("tips")
g = sns.jointplot("total_bill", "tip", data=tips,
g = sns.jointplot(x="total_bill", y="tip", data=tips,
kind="reg", truncate=False,
xlim=(0, 60), ylim=(0, 12),
color="m", height=7)
2 changes: 1 addition & 1 deletion examples/residplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
y = 2 + 1.5 * x + rs.normal(0, 2, 75)

# Plot the residuals after fitting a linear model
sns.residplot(x, y, lowess=True, color="g")
sns.residplot(x=x, y=y, lowess=True, color="g")
21 changes: 11 additions & 10 deletions seaborn/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ def _deprecate_positional_args(f):
def inner_f(*args, **kwargs):
extra_args = len(args) - len(all_args)
if extra_args > 0:
# ignore first 'self' argument for instance methods
args_msg = ['{}={}'.format(name, arg)
for name, arg in zip(kwonly_args[:extra_args],
args[-extra_args:])]
plural = "s" if len(args_msg) > 1 else ""
warnings.warn("Pass {} as keyword arg{}. From version 0.12, "
"passing these as positional arguments will "
"result in an error"
.format(", ".join(args_msg), plural),
FutureWarning)
plural = "s" if extra_args > 1 else ""
article = "" if plural else "a "
warnings.warn(
"Pass the following variable{} as {}keyword arg{}: {}. "
"From version 0.12, the only valid positional argument "
"will be `data`, and passing other arguments without an "
"explcit keyword will result in an error or misinterpretation."
.format(plural, article, plural,
", ".join(kwonly_args[:extra_args])),
FutureWarning
)
kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
return f(**kwargs)
return inner_f
Loading