Skip to content

Fix crash on int-coded label columns in ridgeline plot - #205

Merged
jan-forest merged 4 commits into
devfrom
fix-ridgeline-int-label-crash
Aug 17, 2026
Merged

jan-forest merged 4 commits into
devfrom
fix-ridgeline-int-label-crash

Conversation

@alicia01101

@alicia01101 alicia01101 commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • Fixes a crash in GeneralVisualizer._plot_latent_ridge when coloring a Ridgeline plot by an integer-coded categorical label column (e.g. class labels) with more than 3 unique values.
  • Cause of crash: the function used isinstance(x, float) to decide which label values were valid numbers before quantile-binning. int values fail that check and were coerced to NaN. Problem: When all values in a label column are integers (which is the case for example for the MNIST dataset mapping labels), the entire series became NaN and pd.qcut raised ValueError: Bin edges must be unique because every computed bin edge was NaN.
  • Fix suggested in this PR: label columns that are only integer-valued (no floats mixed in) are now treated as categorical directly, skipping the quantile-binning branch entirely. Columns that do contain genuine float values keep the
    existing quantile-binning behavior and non-numeric outliers within such columns are still coerced to NaN like before.
  • this means that there is a behavior change for float columns which have int values mixed into them then these values are no longer dropped to NaN.

Limitations

  • the crash hasn't happend before since every other tutorial currently colors by a string-typed column (eg. cancer_type, cell_type, disease...)

  • however possible problem with this fix could be: a column that is integer-valued but semantically continuous (like age in years without missing values) will now be treated as categorical rather than quantile-binned

  • Instead of this handling it would also be possible to simply extend the numeric check to include int, not just float, to prevent the crash

@jan-forest

Copy link
Copy Markdown
Owner

I think the root error was the code line converting valid integer values into nan-values, which does not make sense and the comment above looks like a co-production of AI and myself:

                # Change all non-float labels to NaN
                labels = [x if isinstance(x, float) else float("nan") for x in labels]

Was introduced here: bd02297

To keep the original behaviour regarding integer-based annotations like age, I suggest the following fix:

                # Try to convert all labels to float, if fails, convert to nan
                for i in range(len(labels)):
                    try:
                        labels[i] = float(labels[i])
                    except ValueError:
                        labels[i] = float("nan")
                # Check if all labels are NaN, convert to string
                if all(np.isnan(labels)):
                    labels = [str(x) for x in labels]
                else:
                    labels = list(
                        pd.qcut(
                            x=pd.Series(labels),
                            q=4,
                        labels=["1stQ", "2ndQ", "3rdQ", "4thQ"],
                    ).astype(str)
                )

@jan-forest

Copy link
Copy Markdown
Owner

We need to be careful the fix would be necessary at multiple locations in general visualizer and xmodalix visualizer

@jan-forest jan-forest self-assigned this Aug 14, 2026
@jan-forest

Copy link
Copy Markdown
Owner

@alicia01101 I have introduced my suggested fix. Please, test with the tutorials, then I will merge.

@alicia01101

Copy link
Copy Markdown
Collaborator Author

The Tutorials work with the suggested fix!

@jan-forest
jan-forest merged commit 38e31bd into dev Aug 17, 2026
0 of 13 checks passed
@jan-forest
jan-forest deleted the fix-ridgeline-int-label-crash branch August 17, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants