Skip to content

Commit 3d48636

Browse files
committed
update docstrings
1 parent d61f2a7 commit 3d48636

File tree

1 file changed

+91
-33
lines changed
  • packages/python/plotly/plotly/figure_factory

1 file changed

+91
-33
lines changed

packages/python/plotly/plotly/figure_factory/utils.py

Lines changed: 91 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ def is_sequence(obj):
2727

2828
def validate_index(index_vals):
2929
"""
30-
Validates if a list contains all numbers or all strings
30+
Validates if a list contains all numbers or all strings.
31+
32+
Raises
33+
------
34+
PlotlyError
35+
If there are any two items in the list whose types differ.
3136
32-
:raises: (PlotlyError) If there are any two items in the list whose
33-
types differ
3437
"""
3538
from numbers import Number
3639

@@ -55,10 +58,13 @@ def validate_index(index_vals):
5558

5659
def validate_dataframe(array):
5760
"""
58-
Validates all strings or numbers in each dataframe column
61+
Validates all strings or numbers in each dataframe column.
62+
63+
Raises
64+
------
65+
PlotlyError
66+
If there are any two items in any list whose types differ.
5967
60-
:raises: (PlotlyError) If there are any two items in any list whose
61-
types differ
6268
"""
6369
from numbers import Number
6470

@@ -85,7 +91,10 @@ def validate_equal_length(*args):
8591
"""
8692
Validates that data lists or ndarrays are the same length.
8793
88-
:raises: (PlotlyError) If any data lists are not the same length.
94+
Raises
95+
------
96+
PlotlyError
97+
If any data lists or ndarrays are not the same length.
8998
"""
9099
length = len(args[0])
91100
if any(len(lst) != length for lst in args):
@@ -98,9 +107,15 @@ def validate_positive_scalars(**kwargs):
98107
"""
99108
Validates that all values given in key/val pairs are positive.
100109
101-
Accepts kwargs to improve Exception messages.
110+
Parameters
111+
----------
112+
**kwargs : dict
113+
Key/value pairs to validate.
102114
103-
:raises: (PlotlyError) If any value is < 0 or raises.
115+
Raises
116+
------
117+
PlotlyError
118+
If any value is less than 0.
104119
"""
105120
for key, val in kwargs.items():
106121
try:
@@ -112,11 +127,23 @@ def validate_positive_scalars(**kwargs):
112127

113128
def flatten(array):
114129
"""
115-
Uses list comprehension to flatten array
130+
Uses list comprehension to flatten an array.
131+
132+
Parameters
133+
----------
134+
array : iterable
135+
An iterable to flatten.
136+
137+
Returns
138+
-------
139+
list
140+
The flattened list.
141+
142+
Raises
143+
------
144+
PlotlyError
145+
If the iterable is not nested.
116146
117-
:param (array): An iterable to flatten
118-
:raises (PlotlyError): If iterable is not nested.
119-
:rtype (list): The flattened list.
120147
"""
121148
try:
122149
return [item for sublist in array for item in sublist]
@@ -130,16 +157,36 @@ def flatten(array):
130157

131158
def endpts_to_intervals(endpts):
132159
"""
133-
Returns a list of intervals for categorical colormaps
160+
Returns a list of intervals for categorical colormaps.
134161
135162
Accepts a list or tuple of sequentially increasing numbers and returns
136163
a list representation of the mathematical intervals with these numbers
137-
as endpoints. For example, [1, 6] returns [[-inf, 1], [1, 6], [6, inf]]
138-
139-
:raises: (PlotlyError) If input is not a list or tuple
140-
:raises: (PlotlyError) If the input contains a string
141-
:raises: (PlotlyError) If any number does not increase after the
142-
previous one in the sequence
164+
as endpoints. For example, [1, 6] returns [[-inf, 1], [1, 6], [6, inf]].
165+
166+
Parameters
167+
----------
168+
values : list or tuple
169+
A list or tuple of sequentially increasing numbers.
170+
171+
Returns
172+
-------
173+
list
174+
A list of intervals for categorical colormaps.
175+
176+
Raises
177+
------
178+
PlotlyError
179+
If input is not a list or tuple.
180+
PlotlyError
181+
If the input contains a string.
182+
PlotlyError
183+
If any number does not increase after the previous one in the sequence.
184+
185+
Examples
186+
--------
187+
>>> intervals = create_intervals([1, 6])
188+
>>> print(intervals)
189+
[[-inf, 1], [1, 6], [6, inf]]
143190
"""
144191
length = len(endpts)
145192
# Check if endpts is a list or tuple
@@ -194,18 +241,29 @@ def annotation_dict_for_label(
194241
"""
195242
Returns annotation dict for label of n labels of a 1xn or nx1 subplot.
196243
197-
:param (str) text: the text for a label.
198-
:param (int) lane: the label number for text. From 1 to n inclusive.
199-
:param (int) num_of_lanes: the number 'n' of rows or columns in subplot.
200-
:param (float) subplot_spacing: the value for the horizontal_spacing and
201-
vertical_spacing params in your plotly.tools.make_subplots() call.
202-
:param (str) row_col: choose whether labels are placed along rows or
203-
columns.
204-
:param (bool) flipped: flips text by 90 degrees. Text is printed
205-
horizontally if set to True and row_col='row', or if False and
206-
row_col='col'.
207-
:param (bool) right_side: only applicable if row_col is set to 'row'.
208-
:param (str) text_color: color of the text.
244+
Parameters
245+
----------
246+
text : str
247+
The text for a label.
248+
lane : int
249+
The label number for text. From 1 to n inclusive.
250+
num_of_lanes : int
251+
The number 'n' of rows or columns in subplot.
252+
subplot_spacing : float
253+
The value for the horizontal_spacing and vertical_spacing params in your plotly.tools.make_subplots() call.
254+
row_col : str
255+
Choose whether labels are placed along rows or columns.
256+
flipped : bool
257+
Flips text by 90 degrees. Text is printed horizontally if set to True and row_col='row', or if False and row_col='col'.
258+
right_side : bool
259+
Only applicable if row_col is set to 'row'.
260+
text_color : str
261+
Color of the text.
262+
263+
Returns
264+
-------
265+
dict
266+
Annotation dictionary for the label.
209267
"""
210268
l = (1 - (num_of_lanes - 1) * subplot_spacing) / (num_of_lanes)
211269
if not flipped:
@@ -254,7 +312,7 @@ def annotation_dict_for_label(
254312

255313
def list_of_options(iterable, conj="and", period=True):
256314
"""
257-
Returns an English listing of objects seperated by commas ','
315+
Returns an English listing of objects separated by commas ','.
258316
259317
For example, ['foo', 'bar', 'baz'] becomes 'foo, bar and baz'
260318
if the conjunction 'and' is selected.

0 commit comments

Comments
 (0)