Skip to content

Excessive Arial font warnings when Arial not available (200+ warnings) #332

@dipsankadariya

Description

@dipsankadariya

Excessive Arial font warnings when Arial not available (200+ warnings)

Summary

dtreeviz generates hundreds of Arial font warnings when Arial font is not installed on the system, making the output unusable due to warning spam.

Environment

  • dtreeviz version: 2.2.2
  • Python version: 3.11.13
  • matplotlib version: 3.10.0
  • OS: Linux (based on GCC 11.4.0)
  • Arial available: False
  • Available fonts: DejaVu Sans, DejaVu Sans Display, DejaVu Sans Mono, DejaVu Serif, etc.

Minimal Reproducible Example

import warnings
import dtreeviz
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split

# Load data and train model
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, random_state=42)
clf = DecisionTreeClassifier(random_state=42, max_depth=3)
clf.fit(X_train, y_train)

# This generates 200+ Arial font warnings
viz_model = dtreeviz.model(clf, 
                          X_train, y_train,
                          feature_names=iris.feature_names, 
                          class_names=["setosa", "versicolor", "virginica"])
viz_model.view(scale=0.8)

Expected Behavior

  • No font warnings, or at most 1 warning with graceful fallback to available fonts
  • dtreeviz should use matplotlib's default font fallback mechanism
  • Clean output without warning spam

Actual Behavior

  • 200+ identical warnings: WARNING:matplotlib.font_manager:findfont: Font family 'Arial' not found.
  • Warnings make the output completely unusable
  • Visualization still works but is buried in warning noise

Additional Context

  • Matplotlib alone does NOT generate these warnings when using Arial font
  • The warnings only occur when using dtreeviz
  • DejaVu Sans fonts are available and should be suitable fallbacks
  • This affects user experience significantly in Jupyter notebooks and scripts

Proposed Solutions

  1. Add font configuration parameter to allow users to specify preferred fonts
  2. Use matplotlib's default font fallback instead of hardcoding Arial
  3. Check font availability before attempting to use Arial
  4. Warn once maximum instead of repeatedly for the same missing font
  5. Use available system fonts like DejaVu Sans as primary choices

Workaround

Currently users must suppress all warnings:

import warnings
warnings.filterwarnings('ignore')

This is not ideal as it suppresses potentially important warnings from other parts of the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions