Skip to content

Commit d695def

Browse files
committed
break json conversion to a testable separate function
1 parent c070168 commit d695def

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

plotly/grid_objs/grid_objs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,20 @@ def _validate_insertion(self, column):
7373
err = exceptions.NON_UNIQUE_COLUMN_MESSAGE.format(column.name)
7474
raise exceptions.InputError(err)
7575

76+
def _to_plotly_grid_json(self):
77+
grid_json = {'cols': {}}
78+
for column_index, column in enumerate(self):
79+
grid_json['cols'][column.name] = {
80+
'data': column.data,
81+
'order': column_index
82+
}
83+
return grid_json
84+
7685
def get_column(self, column_name):
7786
""" Return the first column with name `column_name`.
7887
If no column with `column_name` exists in this grid, return None.
7988
"""
8089
for column in self._columns:
8190
if column.name == column_name:
8291
return column
92+

plotly/plotly/plotly.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,16 +695,10 @@ def upload(cls, grid, filename, world_readable=True, auto_open=True, meta=None):
695695
file_ops.mkdirs(parent_path)
696696

697697
# transmorgify grid object into plotly's format
698-
grid_json = {'cols': {}}
698+
grid_json = grid._to_plotly_grid_json()
699699
if meta is not None:
700700
grid_json['metadata'] = meta
701701

702-
for column_index, column in enumerate(grid):
703-
grid_json['cols'][column.name] = {
704-
'data': column.data,
705-
'order': column_index
706-
}
707-
708702
payload = {
709703
'filename': filename,
710704
'data': json.dumps(grid_json),

0 commit comments

Comments
 (0)