@@ -27,10 +27,13 @@ def is_sequence(obj):
27
27
28
28
def validate_index (index_vals ):
29
29
"""
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.
31
36
32
- :raises: (PlotlyError) If there are any two items in the list whose
33
- types differ
34
37
"""
35
38
from numbers import Number
36
39
@@ -55,10 +58,13 @@ def validate_index(index_vals):
55
58
56
59
def validate_dataframe (array ):
57
60
"""
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.
59
67
60
- :raises: (PlotlyError) If there are any two items in any list whose
61
- types differ
62
68
"""
63
69
from numbers import Number
64
70
@@ -85,7 +91,10 @@ def validate_equal_length(*args):
85
91
"""
86
92
Validates that data lists or ndarrays are the same length.
87
93
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.
89
98
"""
90
99
length = len (args [0 ])
91
100
if any (len (lst ) != length for lst in args ):
@@ -98,9 +107,15 @@ def validate_positive_scalars(**kwargs):
98
107
"""
99
108
Validates that all values given in key/val pairs are positive.
100
109
101
- Accepts kwargs to improve Exception messages.
110
+ Parameters
111
+ ----------
112
+ **kwargs : dict
113
+ Key/value pairs to validate.
102
114
103
- :raises: (PlotlyError) If any value is < 0 or raises.
115
+ Raises
116
+ ------
117
+ PlotlyError
118
+ If any value is less than 0.
104
119
"""
105
120
for key , val in kwargs .items ():
106
121
try :
@@ -112,11 +127,23 @@ def validate_positive_scalars(**kwargs):
112
127
113
128
def flatten (array ):
114
129
"""
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.
116
146
117
- :param (array): An iterable to flatten
118
- :raises (PlotlyError): If iterable is not nested.
119
- :rtype (list): The flattened list.
120
147
"""
121
148
try :
122
149
return [item for sublist in array for item in sublist ]
@@ -130,16 +157,36 @@ def flatten(array):
130
157
131
158
def endpts_to_intervals (endpts ):
132
159
"""
133
- Returns a list of intervals for categorical colormaps
160
+ Returns a list of intervals for categorical colormaps.
134
161
135
162
Accepts a list or tuple of sequentially increasing numbers and returns
136
163
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]]
143
190
"""
144
191
length = len (endpts )
145
192
# Check if endpts is a list or tuple
@@ -194,18 +241,29 @@ def annotation_dict_for_label(
194
241
"""
195
242
Returns annotation dict for label of n labels of a 1xn or nx1 subplot.
196
243
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.
209
267
"""
210
268
l = (1 - (num_of_lanes - 1 ) * subplot_spacing ) / (num_of_lanes )
211
269
if not flipped :
@@ -254,7 +312,7 @@ def annotation_dict_for_label(
254
312
255
313
def list_of_options (iterable , conj = "and" , period = True ):
256
314
"""
257
- Returns an English listing of objects seperated by commas ','
315
+ Returns an English listing of objects separated by commas ','.
258
316
259
317
For example, ['foo', 'bar', 'baz'] becomes 'foo, bar and baz'
260
318
if the conjunction 'and' is selected.
0 commit comments