Skip to content

Commit f1ec098

Browse files
short-circuit instead of bypass flag
1 parent 5a66bbf commit f1ec098

File tree

1 file changed

+14
-16
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+14
-16
lines changed

Diff for: packages/python/plotly/plotly/express/_core.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -988,20 +988,25 @@ def build_dataframe(args, attrables, array_attrables):
988988
if isinstance(argument, str) or isinstance(
989989
argument, int
990990
): # just a column name given as str or int
991-
bypass_warnings = (
992-
hover_data_is_dict
993-
and argument in args["hover_data"]
994-
and args["hover_data"][argument][1] is not None
995-
)
996-
if not df_provided and not bypass_warnings:
991+
992+
if (
993+
field_name == "hover_data"
994+
and hover_data_is_dict
995+
and args["hover_data"][str(argument)][1] is not None
996+
):
997+
col_name = str(argument)
998+
df_output[col_name] = args["hover_data"][col_name][1]
999+
continue
1000+
1001+
if not df_provided:
9971002
raise ValueError(
9981003
"String or int arguments are only possible when a "
9991004
"DataFrame or an array is provided in the `data_frame` "
10001005
"argument. No DataFrame was provided, but argument "
10011006
"'%s' is of type str or int." % field
10021007
)
10031008
# Check validity of column name
1004-
if not bypass_warnings and argument not in df_input.columns:
1009+
if argument not in df_input.columns:
10051010
err_msg = (
10061011
"Value of '%s' is not the name of a column in 'data_frame'. "
10071012
"Expected one of %s but received: %s"
@@ -1012,7 +1017,7 @@ def build_dataframe(args, attrables, array_attrables):
10121017
"\n To use the index, pass it in directly as `df.index`."
10131018
)
10141019
raise ValueError(err_msg)
1015-
if not bypass_warnings and length and len(df_input[argument]) != length:
1020+
if length and len(df_input[argument]) != length:
10161021
raise ValueError(
10171022
"All arguments should have the same length. "
10181023
"The length of column argument `df[%s]` is %d, whereas the "
@@ -1025,14 +1030,7 @@ def build_dataframe(args, attrables, array_attrables):
10251030
)
10261031
)
10271032
col_name = str(argument)
1028-
if (
1029-
field_name == "hover_data"
1030-
and hover_data_is_dict
1031-
and args["hover_data"][col_name][1] is not None
1032-
):
1033-
df_output[col_name] = args["hover_data"][col_name][1]
1034-
else:
1035-
df_output[col_name] = df_input[argument].values
1033+
df_output[col_name] = df_input[argument].values
10361034
# ----------------- argument is a column / array / list.... -------
10371035
else:
10381036
is_index = isinstance(argument, pd.RangeIndex)

0 commit comments

Comments
 (0)