Skip to content
Open
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
11 changes: 9 additions & 2 deletions www/api/resources/plotly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,15 @@ def post(self, dataset_id):
dataframe = pd.concat([dataframe,selected.obs], axis=1)

# fill any missing adata.obs values with "NA"
# The below line gives the error - TypeError: Cannot setitem on a Categorical with a new category (NA), set the categories first
#df = df.fillna("NA")
# Categorical columns must have "NA" added as a category before filling
for col in dataframe.select_dtypes(include="category").columns:
if dataframe[col].isna().any():
if "NA" not in dataframe[col].cat.categories:
dataframe[col] = dataframe[col].cat.add_categories("NA")
dataframe[col] = dataframe[col].fillna("NA")
for col in dataframe.select_dtypes(include="object").columns:
if dataframe[col].isna().any():
dataframe[col] = dataframe[col].fillna("NA")

# Valid analysis column names from api/resources/h5ad.py
analysis_tsne_columns = ['X_tsne_1', 'X_tsne_2']
Expand Down