Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c070168

Browse files
committed
💥 grid_id
1 parent fd0775a commit c070168

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

gridspec.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ unique_url = py.grid_ops.upload(grid, filename, world_readable=True)
1414

1515
### Updating grids
1616

17-
Grids are identified with either `grid`, `grid_id`, `grid_url`, or `filename`
17+
Grids are identified with either `grid` or `grid_url`, or `filename`
1818
`filename` will be unsupported in this version
1919
```python
2020

@@ -28,8 +28,6 @@ py.grid_ops.upload(grid, 'my file')
2828
py.grid_ops.append_rows(rows, grid=grid)
2929

3030
# But, these all do the same thing
31-
py.grid_ops.append_rows(rows, grid_id=grid.id)
32-
py.grid_ops.append_rows(rows, grid_id="chris:3")
3331
py.grid_ops.append_rows(rows, grid_url="https://plot.ly/~chris/3") #shortcut
3432
py.grid_ops.append_rows(rows, filename='my file') # currently unsupported.
3533
# will do a get request behind
@@ -43,7 +41,6 @@ from plotly.grid_objs import Column
4341
new_col = Column([1,2,3], 'new col name')
4442

4543
# these are equivalent
46-
py.grid_ops.append_columns([new_col], grid_id='chris:3')
4744
py.grid_ops.append_columns([new_col], grid_url='https://plot.ly/~chris/3')
4845
py.grid_ops.append_columns([new_col], filename='my file')
4946

plotly/plotly/plotly.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ def upload(cls, grid, filename, world_readable=True, auto_open=True, meta=None):
740740
return grid_url
741741

742742
@classmethod
743-
def append_columns(cls, columns, grid=None, grid_url=None, grid_id=None):
744-
grid_id = _api_v2.parse_grid_id_args(grid, grid_url, grid_id)
743+
def append_columns(cls, columns, grid=None, grid_url=None):
744+
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
745745

746746
# Verify unique column names
747747
column_names = [c.name for c in columns]
@@ -767,8 +767,8 @@ def append_columns(cls, columns, grid=None, grid_url=None, grid_id=None):
767767
grid.extend(columns)
768768

769769
@classmethod
770-
def append_rows(cls, rows, grid=None, grid_url=None, grid_id=None):
771-
grid_id = _api_v2.parse_grid_id_args(grid, grid_url, grid_id)
770+
def append_rows(cls, rows, grid=None, grid_url=None):
771+
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
772772

773773
if grid:
774774
n_columns = len([column for column in grid])
@@ -805,8 +805,8 @@ def append_rows(cls, rows, grid=None, grid_url=None, grid_id=None):
805805
local_column.data.extend(column_extension)
806806

807807
@classmethod
808-
def delete(cls, grid=None, grid_url=None, grid_id=None):
809-
grid_id = _api_v2.parse_grid_id_args(grid, grid_url, grid_id)
808+
def delete(cls, grid=None, grid_url=None):
809+
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
810810
api_url = _api_v2.api_url('grids')+'/'+grid_id
811811
res = requests.delete(api_url, headers=_api_v2.headers())
812812
_api_v2.response_handler(res)
@@ -817,8 +817,8 @@ class meta_ops:
817817
"""
818818

819819
@classmethod
820-
def upload(cls, meta, grid=None, grid_url=None, grid_id=None):
821-
grid_id = _api_v2.parse_grid_id_args(grid, grid_url, grid_id)
820+
def upload(cls, meta, grid=None, grid_url=None):
821+
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
822822

823823
payload = {
824824
'metadata': json.dumps(meta)
@@ -828,56 +828,51 @@ def upload(cls, meta, grid=None, grid_url=None, grid_id=None):
828828

829829
res = requests.patch(api_url, data=payload, headers=_api_v2.headers())
830830

831-
_api_v2.response_handler(res)
831+
return _api_v2.response_handler(res)
832832

833833

834834
class _api_v2:
835835
""" Request and response helper class for communicating with
836836
Plotly's v2 API
837837
"""
838838
@classmethod
839-
def parse_grid_id_args(cls, grid, grid_url, grid_id):
839+
def parse_grid_id_args(cls, grid, grid_url):
840840
"""Return the grid_id from the non-None input argument.
841841
Raise an error if more than one argument was supplied.
842842
"""
843843
if grid is not None:
844844
id_from_grid = grid.id
845845
else:
846846
id_from_grid = None
847-
args = [id_from_grid, grid_url, grid_id]
848-
arg_names = ('grid', 'grid_url', 'grid_id')
847+
args = [id_from_grid, grid_url]
848+
arg_names = ('grid', 'grid_url')
849849

850850
supplied_arg_names = [arg_name for arg_name, arg
851851
in zip(arg_names, args) if arg is not None]
852852

853853
if not supplied_arg_names:
854854
raise exceptions.InputError(
855-
"One of the following keyword arguments is required:\n"
856-
" `grid`, `grid_id`, or `grid_url`\n\n"
855+
"One of the two keyword arguments is required:\n"
856+
" `grid` or `grid_url`\n\n"
857857
"grid: a plotly.graph_objs.Grid object that has already\n"
858858
" been uploaded to Plotly.\n\n"
859859
"grid_url: the url where the grid can be accessed on\n"
860860
" Plotly, e.g. 'https://plot.ly/~chris/3043'\n\n"
861-
"grid_id: a unique identifier assigned by Plotly to the\n"
862-
" grid object, e.g. 'chris:3043'."
863861
)
864862
elif len(supplied_arg_names) > 1:
865863
raise exceptions.InputError(
866-
"Only one of `grid`, `grid_id`, or `grid_url` is required. \n"
867-
"You supplied '{}'. \n".format(supplied_arg_names)
864+
"Only one of `grid` or `grid_url` is required. \n"
865+
"You supplied both. \n"
868866
)
869867
else:
870868
supplied_arg_name = supplied_arg_names.pop()
871869
if supplied_arg_name == 'grid_url':
872870
path = urlparse(grid_url).path
873871
file_owner, file_id = path.replace("/~", "").split('/')[0:2]
874872
return '{}:{}'.format(file_owner, file_id)
875-
elif supplied_arg_name == 'grid_id':
876-
return grid_id
877873
else:
878874
return grid.id
879875

880-
881876
@classmethod
882877
def response_handler(cls, response):
883878

plotly/tests/test_core/test_grid/test_grid.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,47 +105,42 @@ def test_get_figure_from_references():
105105

106106
def test_grid_id_args():
107107
assert(
108-
py._api_v2.parse_grid_id_args(_grid, None, None) ==
109-
py._api_v2.parse_grid_id_args(None, _grid_url, None)
110-
)
111-
112-
assert(
113-
py._api_v2.parse_grid_id_args(_grid, None, None) ==
114-
py._api_v2.parse_grid_id_args(None, None, _grid_id)
108+
_api_v2.parse_grid_id_args(_grid, None) ==
109+
_api_v2.parse_grid_id_args(None, _grid_url)
115110
)
116111

117112

118113
@raises(InputError)
119114
def test_no_grid_id_args():
120-
py._api_v2.parse_grid_id_args(None, None, None)
115+
_api_v2.parse_grid_id_args(None, None)
121116

122117

123118
@raises(InputError)
124119
def test_overspecified_grid_args():
125-
py._api_v2.parse_grid_id_args(_grid, _grid_url, None)
120+
_api_v2.parse_grid_id_args(_grid, _grid_url)
126121

127122

128123
## Out of order usage
129124
@raises(InputError)
130125
def test_scatter_from_non_uploaded_grid():
131-
c1 = Column('first column', [1, 2, 3, 4])
132-
c2 = Column('second column', ['a', 'b', 'c', 'd'])
126+
c1 = Column([1, 2, 3, 4], 'first column')
127+
c2 = Column(['a', 'b', 'c', 'd'], 'second column')
133128
g = Grid([c1, c2])
134129

135130
Scatter(xsrc=g[0], ysrc=g[1])
136131

137132

138133
@raises(PlotlyRequestError)
139134
def test_column_append_of_non_uploaded_grid():
140-
c1 = Column('first column', [1, 2, 3, 4])
141-
c2 = Column('second column', ['a', 'b', 'c', 'd'])
135+
c1 = Column([1, 2, 3, 4], 'first column')
136+
c2 = Column(['a', 'b', 'c', 'd'], 'second column')
142137
g = Grid([c1])
143138
py.grid_ops.append_columns([c2], grid=g)
144139

145140

146141
@raises(PlotlyRequestError)
147142
def test_row_append_of_non_uploaded_grid():
148-
c1 = Column('first column', [1, 2, 3, 4])
143+
c1 = Column([1, 2, 3, 4], 'first column')
149144
rows = [[1], [2]]
150145
g = Grid([c1])
151146
py.grid_ops.append_rows(rows, grid=g)

0 commit comments

Comments
 (0)