Skip to content

Commit d913f8e

Browse files
authored
Updated chart-studio logic to not overwrite files when filename not passed (#1648)
1 parent de02fca commit d913f8e

File tree

1 file changed

+9
-19
lines changed
  • packages/python/chart-studio/chart_studio/plotly

1 file changed

+9
-19
lines changed

Diff for: packages/python/chart-studio/chart_studio/plotly/plotly.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
__all__ = None
4646

4747
DEFAULT_PLOT_OPTIONS = {
48-
"filename": "plot from API",
4948
"world_readable": files.FILE_CONTENT[files.CONFIG_FILE]["world_readable"],
5049
"auto_open": files.FILE_CONTENT[files.CONFIG_FILE]["auto_open"],
5150
"validate": True,
@@ -97,7 +96,9 @@ def _plot_option_logic(plot_options_from_args):
9796
user_plot_options.update(session_options)
9897
user_plot_options.update(plot_options_from_args)
9998
user_plot_options = {
100-
k: v for k, v in user_plot_options.items() if k in default_plot_options
99+
k: v
100+
for k, v in user_plot_options.items()
101+
if k in default_plot_options or k == "filename"
101102
}
102103

103104
return user_plot_options
@@ -240,7 +241,7 @@ def plot(figure_or_data, validate=True, **plot_options):
240241
filename = paths[-1]
241242

242243
# Create parent directory
243-
if parent_path != "":
244+
if parent_path:
244245
file_ops.ensure_dirs(parent_path)
245246
payload["parent_path"] = parent_path
246247

@@ -1065,6 +1066,8 @@ def upload(
10651066
if meta is not None:
10661067
grid_json["metadata"] = meta
10671068

1069+
payload = {"data": grid_json, "world_readable": world_readable}
1070+
10681071
# Make a folder path
10691072
if filename:
10701073
if filename[-1] == "/":
@@ -1076,23 +1079,10 @@ def upload(
10761079

10771080
if parent_path != "":
10781081
file_ops.ensure_dirs(parent_path)
1079-
else:
1080-
# Create anonymous grid name
1081-
hash_val = hash(json.dumps(grid_json, sort_keys=True))
1082-
id = base64.urlsafe_b64encode(str(hash_val).encode("utf8"))
1083-
id_str = id.decode(encoding="utf8").replace("=", "")
1084-
filename = "grid_" + id_str
1085-
# filename = 'grid_' + str(hash_val)
1086-
parent_path = ""
1087-
1088-
payload = {
1089-
"filename": filename,
1090-
"data": grid_json,
1091-
"world_readable": world_readable,
1092-
}
10931082

1094-
if parent_path != "":
1095-
payload["parent_path"] = parent_path
1083+
payload["filename"] = filename
1084+
if parent_path:
1085+
payload["parent_path"] = parent_path
10961086

10971087
file_info = _create_or_overwrite_grid(payload)
10981088

0 commit comments

Comments
 (0)