Skip to content

Commit 4434b5f

Browse files
committed
update docstrings
1 parent 6d43b9a commit 4434b5f

File tree

2 files changed

+94
-53
lines changed

2 files changed

+94
-53
lines changed

packages/python/plotly/_plotly_utils/colors/__init__.py

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,17 @@ def convert_colors_to_same_type(
426426
be coverted to the selected colortype. If colors is None, then there is an
427427
option to return portion of the DEFAULT_PLOTLY_COLORS
428428
429-
:param (str|tuple|list) colors: either a plotly scale name, an rgb or hex
430-
color, a color tuple or a list/tuple of colors
431-
:param (list) scale: see docs for validate_scale_values()
432-
433-
:rtype (tuple) (colors_list, scale) if scale is None in the function call,
434-
then scale will remain None in the returned tuple
429+
Parameters
430+
----------
431+
colors : str or tuple or list
432+
Either a plotly scale name, an rgb or hex color, a color tuple, or a list/tuple of colors.
433+
scale : list
434+
See docs for validate_scale_values().
435+
436+
Returns
437+
-------
438+
tuple
439+
(colors_list, scale) if scale is None in the function call, then scale will remain None in the returned tuple.
435440
"""
436441
colors_list = []
437442

@@ -496,7 +501,10 @@ def convert_dict_colors_to_same_type(colors_dict, colortype="rgb"):
496501
"""
497502
Converts a colors in a dictionary of colors to the specified color type
498503
499-
:param (dict) colors_dict: a dictionary whose values are single colors
504+
Parameters
505+
----------
506+
colors_dict : dict
507+
A dictionary whose values are single colors.
500508
"""
501509
for key in colors_dict:
502510
if "#" in colors_dict[key]:
@@ -522,14 +530,17 @@ def convert_dict_colors_to_same_type(colors_dict, colortype="rgb"):
522530

523531
def validate_scale_values(scale):
524532
"""
525-
Validates scale values from a colorscale
533+
Validates scale values from a colorscale.
526534
527-
:param (list) scale: a strictly increasing list of floats that begins
528-
with 0 and ends with 1. Its usage derives from a colorscale which is
529-
a list of two-lists (a list with two elements) of the form
530-
[value, color] which are used to determine how interpolation weighting
531-
works between the colors in the colorscale. Therefore scale is just
532-
the extraction of these values from the two-lists in order
535+
Parameters
536+
----------
537+
scale : list of float
538+
A strictly increasing list of floats that begins with 0 and ends with 1.
539+
Its usage derives from a colorscale which is a list of two-element lists
540+
of the form [value, color]. These values are used to determine how
541+
interpolation weighting works between the colors in the colorscale.
542+
Therefore, `scale` is just the extraction of these values from the
543+
two-element lists in order.
533544
"""
534545
if len(scale) < 2:
535546
raise exceptions.PlotlyError(
@@ -565,16 +576,23 @@ def validate_colorscale(colorscale):
565576

566577
def make_colorscale(colors, scale=None):
567578
"""
568-
Makes a colorscale from a list of colors and a scale
579+
Makes a colorscale from a list of colors and a scale.
569580
570581
Takes a list of colors and scales and constructs a colorscale based
571-
on the colors in sequential order. If 'scale' is left empty, a linear-
572-
interpolated colorscale will be generated. If 'scale' is a specificed
573-
list, it must be the same legnth as colors and must contain all floats
574-
For documentation regarding to the form of the output, see
575-
https://plot.ly/python/reference/#mesh3d-colorscale
576-
577-
:param (list) colors: a list of single colors
582+
on the colors in sequential order. If `scale` is left empty, a linear-
583+
interpolated colorscale will be generated. If `scale` is a specified
584+
list, it must be the same length as `colors` and must contain all floats.
585+
For documentation regarding the form of the output, see
586+
https://plot.ly/python/reference/#mesh3d-colorscale.
587+
588+
Parameters
589+
----------
590+
colors : list
591+
A list of single colors.
592+
scale : list of float, optional
593+
A list of scale values. If provided, it must be the same length as
594+
`colors` and must contain all floats. If not provided, a linear-
595+
interpolated colorscale will be generated.
578596
"""
579597
colorscale = []
580598

@@ -646,16 +664,28 @@ def unconvert_from_RGB_255(colors):
646664

647665
def convert_to_RGB_255(colors):
648666
"""
649-
Multiplies each element of a triplet by 255
667+
Multiplies each element of a triplet by 255.
650668
651669
Each coordinate of the color tuple is rounded to the nearest float and
652670
then is turned into an integer. If a number is of the form x.5, then
653671
if x is odd, the number rounds up to (x+1). Otherwise, it rounds down
654672
to just x. This is the way rounding works in Python 3 and in current
655-
statistical analysis to avoid rounding bias
673+
statistical analysis to avoid rounding bias.
674+
675+
Parameters
676+
----------
677+
colors : list of float
678+
A list of three float values representing the RGB components of a color.
656679
657-
:param (list) rgb_components: grabs the three R, G and B values to be
658-
returned as computed in the function
680+
Returns
681+
-------
682+
tuple of int
683+
A tuple of three integers representing the RGB components.
684+
685+
Examples
686+
--------
687+
>>> convert_to_RGB_255([0.1, 0.2, 0.3])
688+
(26, 51, 76)
659689
"""
660690
rgb_components = []
661691

@@ -752,11 +782,22 @@ def unlabel_rgb(colors):
752782

753783
def hex_to_rgb(value):
754784
"""
755-
Calculates rgb values from a hex color code.
785+
Calculates RGB values from a hex color code.
786+
787+
Parameters
788+
----------
789+
value : str
790+
Hex color string.
756791
757-
:param (string) value: Hex color string
792+
Returns
793+
-------
794+
tuple of int
795+
A tuple of three integers representing the RGB components.
758796
759-
:rtype (tuple) (r_value, g_value, b_value): tuple of rgb values
797+
Examples
798+
--------
799+
>>> hex_to_rgb("#ff5733")
800+
(255, 87, 51)
760801
"""
761802
value = value.lstrip("#")
762803
hex_total_length = len(value)

packages/python/plotly/plotly/data/__init__.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ def gapminder(
2424
2525
Parameters
2626
----------
27-
datetimes: bool
27+
datetimes : bool
2828
Whether or not 'year' column will converted to datetime type
2929
30-
centroids: bool
30+
centroids : bool
3131
If True, ['centroid_lat', 'centroid_lon'] columns are added
3232
33-
year: int | None
33+
year : int | None
3434
If provided, the dataset will be filtered for that year
3535
36-
pretty_names: bool
36+
pretty_names : bool
3737
If True, prettifies the column names
3838
39-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
39+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
4040
Type of the resulting dataframe
4141
4242
Returns
@@ -91,10 +91,10 @@ def tips(pretty_names=False, return_type="pandas"):
9191
9292
Parameters
9393
----------
94-
pretty_names: bool
94+
pretty_names : bool
9595
If True, prettifies the column names
9696
97-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
97+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
9898
Type of the resulting dataframe
9999
100100
Returns
@@ -128,7 +128,7 @@ def iris(return_type="pandas"):
128128
129129
Parameters
130130
----------
131-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
131+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
132132
Type of the resulting dataframe
133133
134134
Returns
@@ -146,7 +146,7 @@ def wind(return_type="pandas"):
146146
147147
Parameters
148148
----------
149-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
149+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
150150
Type of the resulting dataframe
151151
152152
Returns
@@ -165,7 +165,7 @@ def election(return_type="pandas"):
165165
166166
Parameters
167167
----------
168-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
168+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
169169
Type of the resulting dataframe
170170
171171
Returns
@@ -183,9 +183,9 @@ def election_geojson():
183183
184184
Returns
185185
-------
186-
A GeoJSON-formatted `dict` with 58 polygon or multi-polygon features whose `id`
187-
is an electoral district numerical ID and whose `district` property is the ID and
188-
district name.
186+
A GeoJSON-formatted `dict` with 58 polygon or multi-polygon features whose `id`
187+
is an electoral district numerical ID and whose `district` property is the ID and
188+
district name.
189189
"""
190190
import gzip
191191
import json
@@ -209,13 +209,13 @@ def carshare(return_type="pandas"):
209209
210210
Parameters
211211
----------
212-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
212+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
213213
Type of the resulting dataframe
214214
215215
Returns
216216
-------
217217
Dataframe of `return_type` type
218-
Dataframe` with 249 rows and the following columns:
218+
Dataframe with 249 rows and the following columns:
219219
`['centroid_lat', 'centroid_lon', 'car_hours', 'peak_hour']`.
220220
"""
221221
return _get_dataset("carshare", return_type=return_type)
@@ -227,14 +227,14 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
227227
228228
Parameters
229229
----------
230-
indexed: bool
230+
indexed : bool
231231
Whether or not the 'date' column is used as the index and the column index
232232
is named 'company'. Applicable only if `return_type='pandas'`
233233
234-
datetimes: bool
234+
datetimes : bool
235235
Whether or not the 'date' column will be of datetime type
236236
237-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
237+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
238238
Type of the resulting dataframe
239239
240240
Returns
@@ -272,11 +272,11 @@ def experiment(indexed=False, return_type="pandas"):
272272
273273
Parameters
274274
----------
275-
indexed: bool
275+
indexed : bool
276276
If True, then the index is named "participant".
277277
Applicable only if `return_type='pandas'`
278278
279-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
279+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
280280
Type of the resulting dataframe
281281
282282
Returns
@@ -308,11 +308,11 @@ def medals_wide(indexed=False, return_type="pandas"):
308308
309309
Parameters
310310
----------
311-
indexed: bool
311+
indexed : bool
312312
Whether or not the 'nation' column is used as the index and the column index
313313
is named 'medal'. Applicable only if `return_type='pandas'`
314314
315-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
315+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
316316
Type of the resulting dataframe
317317
318318
Returns
@@ -345,11 +345,11 @@ def medals_long(indexed=False, return_type="pandas"):
345345
346346
Parameters
347347
----------
348-
indexed: bool
348+
indexed : bool
349349
Whether or not the 'nation' column is used as the index.
350350
Applicable only if `return_type='pandas'`
351351
352-
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
352+
return_type : {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
353353
Type of the resulting dataframe
354354
355355
Returns

0 commit comments

Comments
 (0)