Skip to content

Conversation

@jeremymanning
Copy link
Member

Summary

  • Fix ValueError/UnboundLocalError when importing hypertools in Google Colab
  • Suppress SyntaxWarning from hdbscan's unescaped LaTeX docstrings in Python 3.12+

Problem

When importing hypertools in Google Colab, users encountered:

ValueError: invalid literal for int() with base 10: '/usr/local/lib/python3'
UnboundLocalError: cannot access local variable 'working_backend' where it is not associated with a value

This occurred because jupyter notebook --version in Colab returns a path instead of a version number, and the version parsing code didn't handle this edge case.

Additionally, hdbscan (a dependency via umap-learn) has unescaped LaTeX backslashes in docstrings that trigger SyntaxWarning in Python 3.12+.

Changes

  1. hypertools/plot/backend.py:

    • Add robust version parsing with try-except to handle malformed output
    • Initialize working_backend before any code that could raise exceptions
    • Add null check before tuple version comparison
  2. hypertools/__init__.py:

    • Add warning filter to suppress hdbscan's SyntaxWarning on import
  3. tests/test_backend.py (new):

    • Add regression tests for version parsing edge cases including Colab paths

Testing

  • All 136 tests pass
  • Manually verified in Google Colab - import now works cleanly with no errors or warnings

- Add robust version parsing in _get_jupyter_frontend() with try-except
  to handle unexpected output formats (e.g., paths instead of versions)
- Initialize working_backend='inline' before _get_jupyter_frontend() call
  to prevent UnboundLocalError if version parsing fails
- Add notebook_version_tup None check before tuple comparison
- Add tests/test_backend.py with regression tests for Colab edge case

Fixes ValueError/UnboundLocalError when importing hypertools in Colab:
  ValueError: invalid literal for int() with base 10: '/usr/local/lib/python3'
  UnboundLocalError: cannot access local variable 'working_backend'
The hdbscan package has unescaped LaTeX backslashes in docstrings that
trigger SyntaxWarning in Python 3.12+. Suppress this warning during
import since it's harmless and outside our control.
Filter must be set before any imports to suppress compile-time warnings
from hdbscan (imported transitively via umap-learn).
Use message='invalid escape sequence' pattern which reliably matches
the hdbscan warnings regardless of module name resolution.
Set MPLBACKEND=Agg for pytest runs to avoid Tcl/Tk dependencies on
headless CI environments. This is standard practice for CI systems
that don't have display servers.
@jeremymanning jeremymanning merged commit 60c9fe2 into master Jan 29, 2026
12 checks passed
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