Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 75792cc

Browse files
committed
Tweaks
1 parent 06f1abd commit 75792cc

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

plotly_express/_core.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,28 @@ def apply_default_cascade(args):
659659
if args["color_discrete_sequence"] is None:
660660
args["color_discrete_sequence"] = qualitative.Plotly
661661

662+
def has_value(collection, key):
663+
return collection.get(key, None) is not None
664+
665+
def build_dataframe(args, attrables):
666+
"""
667+
Constructs an implicit dataframe and modifies `args` in-place.
668+
669+
`attrables` is a list of keys into `args`, all of whose corresponding
670+
values are converted into columns of a dataframe.
671+
672+
Used to be support calls to plotting function that elide a dataframe argument;
673+
for example `scatter(x=[1,2], y=[3,4])`.
674+
"""
675+
data_frame_columns = {}
676+
for field in attrables:
677+
if not has_value(args, field):
678+
continue
679+
data_frame_columns[field] = args[field]
680+
# This sets the label of an attribute to be the name of the attribute.
681+
args[field] = field
682+
args["data_frame"] = pandas.DataFrame(data_frame_columns)
683+
return args
662684

663685
def infer_config(args, constructor, trace_patch):
664686
attrables = (
@@ -791,29 +813,6 @@ def get_orderings(args, grouper, grouped):
791813

792814
return orders, group_names
793815

794-
def has_value(d, key):
795-
return d.get(key, None) is not None
796-
797-
def build_dataframe(args, attrables):
798-
"""
799-
Constructs an implicit dataframe and modifies `args` in-place.
800-
801-
`attrables` is a list of keys into `args`, all of whose corresponding
802-
values are converted into columns of a dataframe.
803-
804-
Used to be support calls to plotting function that elide a dataframe argument;
805-
for example `scatter(x=[1,2], y=[3,4])`.
806-
"""
807-
dataset_fields = {}
808-
for field in attrables:
809-
if not has_value(args, field):
810-
continue
811-
dataset_fields[field] = args[field]
812-
# This sets the label of an attribute to be the name of the attribute.
813-
args[field] = field
814-
args["data_frame"] = pandas.DataFrame(dataset_fields)
815-
return args
816-
817816
def make_figure(args, constructor, trace_patch={}, layout_patch={}):
818817
apply_default_cascade(args)
819818
trace_specs, grouped_mappings, sizeref, show_colorbar = infer_config(

0 commit comments

Comments
 (0)