Skip to content

short-circuit instead of bypass flag #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,20 +988,25 @@ def build_dataframe(args, attrables, array_attrables):
if isinstance(argument, str) or isinstance(
argument, int
): # just a column name given as str or int
bypass_warnings = (
hover_data_is_dict
and argument in args["hover_data"]
and args["hover_data"][argument][1] is not None
)
if not df_provided and not bypass_warnings:

if (
field_name == "hover_data"
and hover_data_is_dict
and args["hover_data"][str(argument)][1] is not None
):
col_name = str(argument)
df_output[col_name] = args["hover_data"][col_name][1]
continue

if not df_provided:
raise ValueError(
"String or int arguments are only possible when a "
"DataFrame or an array is provided in the `data_frame` "
"argument. No DataFrame was provided, but argument "
"'%s' is of type str or int." % field
)
# Check validity of column name
if not bypass_warnings and argument not in df_input.columns:
if argument not in df_input.columns:
err_msg = (
"Value of '%s' is not the name of a column in 'data_frame'. "
"Expected one of %s but received: %s"
Expand All @@ -1012,7 +1017,7 @@ def build_dataframe(args, attrables, array_attrables):
"\n To use the index, pass it in directly as `df.index`."
)
raise ValueError(err_msg)
if not bypass_warnings and length and len(df_input[argument]) != length:
if length and len(df_input[argument]) != length:
raise ValueError(
"All arguments should have the same length. "
"The length of column argument `df[%s]` is %d, whereas the "
Expand All @@ -1025,14 +1030,7 @@ def build_dataframe(args, attrables, array_attrables):
)
)
col_name = str(argument)
if (
field_name == "hover_data"
and hover_data_is_dict
and args["hover_data"][col_name][1] is not None
):
df_output[col_name] = args["hover_data"][col_name][1]
else:
df_output[col_name] = df_input[argument].values
df_output[col_name] = df_input[argument].values
# ----------------- argument is a column / array / list.... -------
else:
is_index = isinstance(argument, pd.RangeIndex)
Expand Down