Skip to content

Commit

Permalink
Resolving #532
Browse files Browse the repository at this point in the history
  • Loading branch information
adkinsrs committed Oct 6, 2023
1 parent 3208534 commit db37d2c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions www/api/resources/plotly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ def post(self, dataset_id):
if color_map and color_name:
# Validate if all color map keys are in the dataframe columns
# Ran into an issue where the color map keys were truncated compared to the dataframe column values
col_values = set(df[color_name].unique())
# Setting to categories ensures nulls are dropped, which are dropped already in the dataframe
col_values = set(df[color_name].cat.categories)
diff = col_values.difference(color_map.keys())
if diff:
message = "WARNING: Color map has values not in the dataframe column '{}': {}\n".format(color_name, diff)
message += "Will set color map key values to the unique values in the dataframe column."
message += "Will set color map key values to the unique Categorical values in the dataframe column."
print(message, file=sys.stderr)
# Sort both the colormap and dataframe column alphabetically
sorted_column_values = sorted(col_values)
Expand All @@ -345,7 +346,7 @@ def post(self, dataset_id):
]
color_map = purples
else:
names = df[color_name].unique().tolist()
names = df[color_name].cat.categories.tolist()
color_map = plotly_color_map(names)

# Check if color hexcodes exist and use if validated
Expand All @@ -355,7 +356,7 @@ def post(self, dataset_id):
# Ensure one-to-one mapping of color names to codes
if len(grouped) == len(names):
# Test if names are color hexcodes and use those if applicable
color_hex = df[color_code].unique().tolist()
color_hex = df[color_code].cat.categories.tolist()
if re.search(COLOR_HEX_PTRN, color_hex[0]):
color_map = {name[0]:name[1] for name, group in grouped}

Expand Down

0 comments on commit db37d2c

Please sign in to comment.