nautechsystems/nautilus_trader · error · ImportError

pandas is required for visualization; install it with `pip…

Error message

pandas is required for visualization; install it with `pip install nautilus_trader[visualization]`

What it means

Same as the ts_event lookup, but for the ts_init column: when use_ts_event_for_ts_init is true, apply_stream_conversion_transforms needs a ts_init column to overwrite with ts_event values. schema.index_of("ts_init") fails because the batch schema contains no ts_init column, so this error is raised.

Solutions

  1. Confirm the source batches include ts_init (batch.schema().column_with_name("ts_init")) before enabling the conversion.
  2. If ts_init is genuinely absent, either add a ts_init column when writing the data or handle the data without the ts_event-for-ts_init substitution.
  3. Re-record/re-export the stream with the current writer version so both timestamp columns are present.
  4. Ensure all batches fed to the conversion come from a consistent schema/writer version.

Example fix

// before
let opts = StreamConversionOptions { use_ts_event_for_ts_init: true, .. };

// after: require both columns up front
for col in ["ts_event", "ts_init"] {
    assert!(batch.schema().column_with_name(col).is_some(),
        "missing required column: {col}");
}
Defensive patterns

Strategy: validation

Validate before calling

assert!(batch.schema().column_with_name("ts_init").is_some(),
    "stream batch lacks ts_init");

Type guard

fn has_ts_init(batch: &RecordBatch) -> bool {
    batch.schema().column_with_name("ts_init").is_some()
}

Try / catch

match apply_transforms(batches, use_ts_event_for_ts_init) {
    Err(e) if e.to_string().contains("ts_init column not found") => {
        // add/derive ts_init or disable the substitution
    }
    r => r,
}

Prevention

When it happens

Trigger: Running the stream conversion with use_ts_event_for_ts_init = true on batches whose schema lacks a ts_init column.

Common situations: Stream recordings from data writers that emitted only ts_event; custom data encoders that omitted ts_init; mixing batches from different writer versions where some carry ts_init and others do not.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

    import pandas as pd

    from nautilus_trader.analysis.config import GridLayout
    from nautilus_trader.analysis.config import TearsheetChart
    from nautilus_trader.backtest import BacktestEngine
    from nautilus_trader.backtest import BacktestNode
    from nautilus_trader.backtest import BacktestResult
    from nautilus_trader.common import Cache
    from nautilus_trader.model import Currency
    from nautilus_trader.model import PortfolioSnapshot
    from nautilus_trader.model import Venue
    from nautilus_trader.portfolio import Portfolio


def _require_pandas() -> ModuleType:
    try:
        import pandas as pd
    except ImportError as e:
        raise ImportError(
            "pandas is required for visualization; install it with "
            "`pip install nautilus_trader[visualization]`",
        ) from e

    return pd


if not TYPE_CHECKING:

    class _PandasProxy:
        def __getattr__(self, name: str) -> Any:
            return getattr(_require_pandas(), name)

    pd = _PandasProxy()


try:
    import plotly.graph_objects as go

View on GitHub (pinned to 18893faf8b)