@@ -740,8 +740,8 @@ def upload(cls, grid, filename, world_readable=True, auto_open=True, meta=None):
740
740
return grid_url
741
741
742
742
@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 )
745
745
746
746
# Verify unique column names
747
747
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):
767
767
grid .extend (columns )
768
768
769
769
@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 )
772
772
773
773
if grid :
774
774
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):
805
805
local_column .data .extend (column_extension )
806
806
807
807
@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 )
810
810
api_url = _api_v2 .api_url ('grids' )+ '/' + grid_id
811
811
res = requests .delete (api_url , headers = _api_v2 .headers ())
812
812
_api_v2 .response_handler (res )
@@ -817,8 +817,8 @@ class meta_ops:
817
817
"""
818
818
819
819
@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 )
822
822
823
823
payload = {
824
824
'metadata' : json .dumps (meta )
@@ -828,56 +828,51 @@ def upload(cls, meta, grid=None, grid_url=None, grid_id=None):
828
828
829
829
res = requests .patch (api_url , data = payload , headers = _api_v2 .headers ())
830
830
831
- _api_v2 .response_handler (res )
831
+ return _api_v2 .response_handler (res )
832
832
833
833
834
834
class _api_v2 :
835
835
""" Request and response helper class for communicating with
836
836
Plotly's v2 API
837
837
"""
838
838
@classmethod
839
- def parse_grid_id_args (cls , grid , grid_url , grid_id ):
839
+ def parse_grid_id_args (cls , grid , grid_url ):
840
840
"""Return the grid_id from the non-None input argument.
841
841
Raise an error if more than one argument was supplied.
842
842
"""
843
843
if grid is not None :
844
844
id_from_grid = grid .id
845
845
else :
846
846
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' )
849
849
850
850
supplied_arg_names = [arg_name for arg_name , arg
851
851
in zip (arg_names , args ) if arg is not None ]
852
852
853
853
if not supplied_arg_names :
854
854
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 "
857
857
"grid: a plotly.graph_objs.Grid object that has already\n "
858
858
" been uploaded to Plotly.\n \n "
859
859
"grid_url: the url where the grid can be accessed on\n "
860
860
" 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'."
863
861
)
864
862
elif len (supplied_arg_names ) > 1 :
865
863
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 "
868
866
)
869
867
else :
870
868
supplied_arg_name = supplied_arg_names .pop ()
871
869
if supplied_arg_name == 'grid_url' :
872
870
path = urlparse (grid_url ).path
873
871
file_owner , file_id = path .replace ("/~" , "" ).split ('/' )[0 :2 ]
874
872
return '{}:{}' .format (file_owner , file_id )
875
- elif supplied_arg_name == 'grid_id' :
876
- return grid_id
877
873
else :
878
874
return grid .id
879
875
880
-
881
876
@classmethod
882
877
def response_handler (cls , response ):
883
878
0 commit comments