@@ -118,12 +118,17 @@ class Grid(MutableSequence):
118
118
py.plot([trace], filename='graph from grid')
119
119
```
120
120
"""
121
- def __init__ (self , columns_or_json ):
121
+ def __init__ (self , columns_or_json , grid_id = None ):
122
122
"""
123
123
Initialize a grid with an iterable of `plotly.grid_objs.Column`
124
124
objects or a json/dict describing a grid. See second usage example
125
125
below for the necessary structure of the dict.
126
126
127
+ :param (str|bool) grid_id: should not be accessible to users. Default
128
+ 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
130
+ necessary to set `self.id` and `self._columns.id` below.
131
+
127
132
Example from iterable of columns:
128
133
```
129
134
column_1 = Column([1, 2, 3], 'time')
@@ -141,9 +146,19 @@ def __init__(self, columns_or_json):
141
146
grid = Grid(grid_json)
142
147
```
143
148
"""
144
-
145
149
# TODO: verify that columns are actually columns
146
150
if isinstance (columns_or_json , dict ):
151
+ # check that grid_id is entered
152
+ if grid_id is None :
153
+ raise exceptions .PlotlyError (
154
+ "If you are manually converting a raw json/dict grid "
155
+ "into a Grid instance, you must ensure that make "
156
+ "'grid_id' is set to your file ID. This looks like "
157
+ "'username:187'."
158
+ )
159
+ # TODO: verify that grid_id is a correct fid if a string
160
+ self .id = grid_id
161
+
147
162
# check if 'cols' is a root key
148
163
if 'cols' not in columns_or_json :
149
164
raise exceptions .PlotlyError (
@@ -182,7 +197,8 @@ def __init__(self, columns_or_json):
182
197
183
198
# fill in uids
184
199
for column in self :
185
- column .id = columns_or_json ['cols' ][column .name ]['uid' ]
200
+ column .id = self .id + ':' + columns_or_json ['cols' ][column .name ]['uid' ]
201
+
186
202
else :
187
203
column_names = [column .name for column in columns_or_json ]
188
204
duplicate_name = utils .get_first_duplicate (column_names )
@@ -193,8 +209,6 @@ def __init__(self, columns_or_json):
193
209
self ._columns = list (columns_or_json )
194
210
self .id = ''
195
211
196
- #self._fid = ''
197
-
198
212
def __repr__ (self ):
199
213
return self ._columns .__repr__ ()
200
214
@@ -241,7 +255,7 @@ def get_column(self, column_name):
241
255
if column .name == column_name :
242
256
return column
243
257
244
- def get_uid (self , column_name ):
258
+ def get_fid_uid (self , column_name ):
245
259
"""
246
260
Return uid of given column name in the grid by column name.
247
261
0 commit comments