Skip to content

Commit 3a87007

Browse files
wide-mode docstrings
1 parent b1bcd08 commit 3a87007

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

packages/python/plotly/plotly/express/_chart_types.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
from ._doc import make_docstring
33
import plotly.graph_objs as go
44

5+
_wide_mode_xy_append = [
6+
"Either `x` or `y` can optionally be a list of column references or array_likes, ",
7+
"in which case the data will be treated as if it were 'wide' rather than 'long'.",
8+
]
9+
_cartesian_append_dict = dict(x=_wide_mode_xy_append, y=_wide_mode_xy_append)
10+
511

612
def scatter(
713
data_frame=None,
@@ -56,7 +62,7 @@ def scatter(
5662
return make_figure(args=locals(), constructor=go.Scatter)
5763

5864

59-
scatter.__doc__ = make_docstring(scatter)
65+
scatter.__doc__ = make_docstring(scatter, append_dict=_cartesian_append_dict)
6066

6167

6268
def density_contour(
@@ -114,7 +120,16 @@ def density_contour(
114120
)
115121

116122

117-
density_contour.__doc__ = make_docstring(density_contour)
123+
density_contour.__doc__ = make_docstring(
124+
density_contour,
125+
append_dict=dict(
126+
x=_wide_mode_xy_append,
127+
y=_wide_mode_xy_append,
128+
z=[
129+
"For `density_heatmap` and `density_contour` these values are used as the inputs to `histfunc`.",
130+
],
131+
),
132+
)
118133

119134

120135
def density_heatmap(
@@ -170,7 +185,16 @@ def density_heatmap(
170185
)
171186

172187

173-
density_heatmap.__doc__ = make_docstring(density_heatmap)
188+
density_heatmap.__doc__ = make_docstring(
189+
density_heatmap,
190+
append_dict=dict(
191+
x=_wide_mode_xy_append,
192+
y=_wide_mode_xy_append,
193+
z=[
194+
"For `density_heatmap` and `density_contour` these values are used as the inputs to `histfunc`.",
195+
],
196+
),
197+
)
174198

175199

176200
def line(
@@ -218,7 +242,7 @@ def line(
218242
return make_figure(args=locals(), constructor=go.Scatter)
219243

220244

221-
line.__doc__ = make_docstring(line)
245+
line.__doc__ = make_docstring(line, append_dict=_cartesian_append_dict)
222246

223247

224248
def area(
@@ -264,7 +288,7 @@ def area(
264288
)
265289

266290

267-
area.__doc__ = make_docstring(area)
291+
area.__doc__ = make_docstring(area, append_dict=_cartesian_append_dict)
268292

269293

270294
def bar(
@@ -316,7 +340,7 @@ def bar(
316340
)
317341

318342

319-
bar.__doc__ = make_docstring(bar)
343+
bar.__doc__ = make_docstring(bar, append_dict=_cartesian_append_dict)
320344

321345

322346
def histogram(
@@ -369,7 +393,15 @@ def histogram(
369393
)
370394

371395

372-
histogram.__doc__ = make_docstring(histogram)
396+
histogram.__doc__ = make_docstring(
397+
histogram,
398+
append_dict=dict(
399+
x=["For horizontal histograms, these values are used as inputs to `histfunc`."]
400+
+ _wide_mode_xy_append,
401+
y=["For vertical histograms, these values are used as inputs to `histfunc`."]
402+
+ _wide_mode_xy_append,
403+
),
404+
)
373405

374406

375407
def violin(
@@ -416,7 +448,7 @@ def violin(
416448
)
417449

418450

419-
violin.__doc__ = make_docstring(violin)
451+
violin.__doc__ = make_docstring(violin, append_dict=_cartesian_append_dict)
420452

421453

422454
def box(
@@ -466,7 +498,7 @@ def box(
466498
)
467499

468500

469-
box.__doc__ = make_docstring(box)
501+
box.__doc__ = make_docstring(box, append_dict=_cartesian_append_dict)
470502

471503

472504
def strip(
@@ -517,7 +549,7 @@ def strip(
517549
)
518550

519551

520-
strip.__doc__ = make_docstring(strip)
552+
strip.__doc__ = make_docstring(strip, append_dict=_cartesian_append_dict)
521553

522554

523555
def scatter_3d(
@@ -1389,7 +1421,7 @@ def funnel(
13891421
return make_figure(args=locals(), constructor=go.Funnel)
13901422

13911423

1392-
funnel.__doc__ = make_docstring(funnel)
1424+
funnel.__doc__ = make_docstring(funnel, append_dict=_cartesian_append_dict)
13931425

13941426

13951427
def funnel_area(

packages/python/plotly/plotly/express/_doc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@
2525
colref_type,
2626
colref_desc,
2727
"Values from this column or array_like are used to position marks along the x axis in cartesian coordinates.",
28-
"For horizontal histograms, these values are used as inputs to `histfunc`.",
2928
],
3029
y=[
3130
colref_type,
3231
colref_desc,
3332
"Values from this column or array_like are used to position marks along the y axis in cartesian coordinates.",
34-
"For vertical histograms, these values are used as inputs to `histfunc`.",
3533
],
3634
z=[
3735
colref_type,
3836
colref_desc,
3937
"Values from this column or array_like are used to position marks along the z axis in cartesian coordinates.",
40-
"For `density_heatmap` and `density_contour` these values are used as the inputs to `histfunc`.",
4138
],
4239
a=[
4340
colref_type,
@@ -173,7 +170,7 @@
173170
colref_desc,
174171
"Values from this column or array_like are used to assign mark sizes.",
175172
],
176-
radius=["int (default is 30)", "Sets the radius of influence of each point.",],
173+
radius=["int (default is 30)", "Sets the radius of influence of each point."],
177174
hover_name=[
178175
colref_type,
179176
colref_desc,
@@ -518,14 +515,16 @@
518515
)
519516

520517

521-
def make_docstring(fn, override_dict={}):
518+
def make_docstring(fn, override_dict={}, append_dict={}):
522519
tw = TextWrapper(width=75, initial_indent=" ", subsequent_indent=" ")
523520
result = (fn.__doc__ or "") + "\nParameters\n----------\n"
524521
for param in getfullargspec(fn)[0]:
525522
if override_dict.get(param):
526-
param_doc = override_dict[param]
523+
param_doc = override_dict[param].copy()
527524
else:
528-
param_doc = docs[param]
525+
param_doc = docs[param].copy()
526+
if append_dict.get(param):
527+
param_doc += append_dict[param]
529528
param_desc_list = param_doc[1:]
530529
param_desc = (
531530
tw.fill(" ".join(param_desc_list or ""))

0 commit comments

Comments
 (0)