Skip to content

Commit 495b015

Browse files
committed
changed some terminology around
1 parent 587dfa5 commit 495b015

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

plotly/grid_objs/grid_objs.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ class Grid(MutableSequence):
118118
py.plot([trace], filename='graph from grid')
119119
```
120120
"""
121-
def __init__(self, columns_or_json, grid_id=None):
121+
def __init__(self, columns_or_json, fid=None):
122122
"""
123123
Initialize a grid with an iterable of `plotly.grid_objs.Column`
124124
objects or a json/dict describing a grid. See second usage example
125125
below for the necessary structure of the dict.
126126
127-
:param (str|bool) grid_id: should not be accessible to users. Default
127+
:param (str|bool) fid: should not be accessible to users. Default
128128
is 'None' but if a grid is retrieved via `py.get_grid()` then the
129-
retrieved grid response will contain the grid_id which will be
129+
retrieved grid response will contain the fid which will be
130130
necessary to set `self.id` and `self._columns.id` below.
131131
132132
Example from iterable of columns:
@@ -148,16 +148,16 @@ def __init__(self, columns_or_json, grid_id=None):
148148
"""
149149
# TODO: verify that columns are actually columns
150150
if isinstance(columns_or_json, dict):
151-
# check that grid_id is entered
152-
if grid_id is None:
151+
# check that fid is entered
152+
if fid is None:
153153
raise exceptions.PlotlyError(
154154
"If you are manually converting a raw json/dict grid "
155155
"into a Grid instance, you must ensure that make "
156-
"'grid_id' is set to your file ID. This looks like "
156+
"'fid' is set to your file ID. This looks like "
157157
"'username:187'."
158158
)
159-
# TODO: verify that grid_id is a correct fid if a string
160-
self.id = grid_id
159+
# TODO: verify that fid is a correct fid if a string
160+
self.id = fid
161161

162162
# check if 'cols' is a root key
163163
if 'cols' not in columns_or_json:
@@ -255,16 +255,26 @@ def get_column(self, column_name):
255255
if column.name == column_name:
256256
return column
257257

258-
def get_fid_uid(self, column_name):
258+
def get_column_reference(self, column_name):
259259
"""
260-
Return uid of given column name in the grid by column name.
260+
Returns the column reference of given column in the grid by its name.
261261
262-
Returns an empty string if either the column name does not exist in
263-
the grid or if the id of the specified column has the empty string id.
262+
Raises an error if the column name is not in the grid. Otherwise,
263+
returns the fid:uid pair, which may be the empty string.
264264
"""
265-
uid = ''
265+
col_names = []
266+
for column in self._columns:
267+
col_names.append(column.name)
268+
269+
column_id = None
266270
for column in self._columns:
267271
if column.name == column_name:
268-
uid = column.id
272+
column_id = column.id
269273
break
270-
return uid
274+
275+
if column_id is None:
276+
raise exceptions.PlotlyError(
277+
"Whoops, that column name doesn't match any of the column "
278+
"names in your grid. You must pick from {cols}".format(col_names)
279+
)
280+
return column_id

plotly/plotly/plotly.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ def _send_to_plotly(figure, **plot_options):
14561456

14571457
def get_grid(grid_url, raw=False):
14581458
"""
1459-
Returns a JSON figure representation for the specified grid.
1459+
Returns the specified grid as a Grid instance or in JSON/dict form.
14601460
14611461
:param (bool) raw: if False, will output a Grid instance of the JSON grid
14621462
being retrieved. If True, raw JSON will be returned.
@@ -1502,7 +1502,7 @@ def create_animations(figure, filename=None, sharing='public', auto_open=True):
15021502
to `plotly.plotly.plot`, folder-creation and overwriting are not supported
15031503
but creating a plot with or without animations via frames is supported.
15041504
1505-
:param (str) filename: if set to 'None', an automatically generated plot
1505+
:param (str) filename: if set to 'None', an automatically-generated plot
15061506
name will be created. Does not support folder creation, meaning that
15071507
a folder of the form 'folder/name' will NOT create a the folder and
15081508
place the plot in it.
@@ -1526,17 +1526,17 @@ def create_animations(figure, filename=None, sharing='public', auto_open=True):
15261526
figure = {
15271527
'data': [
15281528
{
1529-
'xsrc': grid.get_fid_uid('x'),
1530-
'ysrc': grid.get_fid_uid('y')
1529+
'xsrc': grid.get_column_reference('x'),
1530+
'ysrc': grid.get_column_reference('y')
15311531
}
15321532
],
15331533
'layout': {'title': 'First Title'},
15341534
'frames': [
15351535
{
15361536
'data': [
15371537
{
1538-
'xsrc': grid.get_fid_uid('new x'),
1539-
'ysrc': grid.get_fid_uid('new y')
1538+
'xsrc': grid.get_column_reference('new x'),
1539+
'ysrc': grid.get_column_reference('new y')
15401540
}
15411541
],
15421542
'layout': {'title': 'Second Title'}
@@ -1615,6 +1615,7 @@ def icreate_animations(figure, filename=None, sharing='public', auto_open=False)
16151615
This function is based off `plotly.plotly.iplot`. See `plotly.plotly.
16161616
create_animations` Doc String for param descriptions.
16171617
"""
1618+
# TODO - create a wrapper for iplot and icreate_animations
16181619
url = create_animations(figure, filename, sharing, auto_open)
16191620

16201621
if isinstance(figure, dict):

0 commit comments

Comments
 (0)