Skip to content

Commit

Permalink
#875 - Fixed bug with NA values in color mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
adkinsrs committed Sep 16, 2024
1 parent 0deb41c commit bd83731
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions www/api/resources/plotly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ def post(self, dataset_id):
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."
print(message, file=sys.stderr)
# If any element in diff is nan and color_map contains a valid missing value key like "NA", change the value in the dataframe to match the color_map key
for key in list(diff):
if pd.isna(key) and "NA" in color_map.keys():
df[color_name] = df[color_name].replace({key: "NA"})
col_values.remove(key) # Remove the nan value from the set
col_values = col_values.union({"NA"})
break

# Sort both the colormap and dataframe column alphabetically
sorted_column_values = sorted(col_values)
updated_color_map = {}
Expand Down

0 comments on commit bd83731

Please sign in to comment.