nautechsystems/nautilus_trader · error · ValueError

Chart renderer must be callable, was

Error message

Chart renderer must be callable, was {type(renderer)}

What it means

register_tearsheet_chart requires renderer to be a callable; a non-callable value (string, class instance without __call__, None already caught by _require_not_none) raises this ValueError naming the offending type.

Solutions

  1. Pass a function with signature compatible with the registered chart spec
  2. If you have an object, wrap its method: renderer=lambda fig, ctx: obj.render(fig, ctx)
  3. Print type(renderer) to confirm it is callable before registering

Example fix

// before
register_tearsheet_chart(name="equity", subplot_type="xy", title="Equity", renderer="equity_curve")  # ValueError
// after
register_tearsheet_chart(name="equity", subplot_type="xy", title="Equity", renderer=render_equity_curve)
Defensive patterns

Strategy: type-guard

Validate before calling

if not callable(renderer):
    raise TypeError(f"renderer must be callable, got {type(renderer).__name__}")

Type guard

def is_valid_renderer(renderer) -> bool:
    return callable(renderer)

Try / catch

try:
    register_tearsheet_chart(name=n, subplot_type=st, title=t, renderer=r)
except ValueError as e:
    if "must be callable" in str(e):
        r = wrap_renderer(r)
        register_tearsheet_chart(name=n, subplot_type=st, title=t, renderer=r)
    else:
        raise

Prevention

When it happens

Trigger: Passing a non-callable such as a string, dict, or a module instead of a function that renders the chart into a plotly figure.

Common situations: Misreading the API and passing a figure or config object instead of a render function; importing the wrong symbol so the variable holds a non-function value.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/37a231d6178f7985. Report an issue: GitHub.

Appendix: source

Thrown at python/nautilus_trader/analysis/tearsheet.py:2464

        Display title for the subplot.
    renderer : Callable
        Function that adds traces to the figure. Signature:
        renderer(fig, row, col, returns, stats_pnls, stats_returns, stats_general,
        theme_config, benchmark_returns, benchmark_name, run_info, account_info, engine, **kwargs)

    Raises
    ------
    ValueError
        If name is empty or renderer is not callable.

    """
    _require_not_none(name, "name")

    if not name.strip():
        raise ValueError("Chart name cannot be empty")

    if not callable(renderer):
        raise ValueError(f"Chart renderer must be callable, was {type(renderer)}")

    _TEARSHEET_CHART_SPECS[name] = {
        "type": subplot_type,
        "title": title,
        "renderer": renderer,
    }


def _calculate_grid_layout(
    charts: list[TearsheetChart],
    custom_layout: GridLayout | None = None,
) -> tuple[int, int, list, list[str], list[float], float, float]:
    """
    Calculate dynamic grid layout based on selected charts.

    Parameters
    ----------
    charts : list[TearsheetChart]

View on GitHub (pinned to 18893faf8b)