{"record":{"id":"f10d0da3feb6db31","repo":"nautechsystems/nautilus_trader","slug":"chart-name-cannot-be-empty","errorCode":null,"errorMessage":"Chart name cannot be empty","messagePattern":"Chart name cannot be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/analysis/tearsheet.py","lineNumber":297,"sourceCode":"        If name is empty or func is not callable.\n\n    Examples\n    --------\n    >>> # As a decorator\n    >>> @register_chart(\"my_custom_chart\")\n    ... def create_custom_chart(returns: pd.Series, **kwargs) -> go.Figure:\n    ...     fig = go.Figure()\n    ...     # ... custom visualization logic\n    ...     return fig\n    >>>\n    >>> # Or called directly\n    >>> register_chart(\"another_chart\", create_custom_chart)\n\n    \"\"\"\n    _require_not_none(name, \"name\")\n\n    if not name.strip():\n        raise ValueError(\"Chart name cannot be empty\")\n\n    if func is None:\n\n        def decorator(f: Callable) -> Callable:\n            if not callable(f):\n                raise ValueError(f\"Chart function must be callable, was {type(f)}\")\n            _CHART_REGISTRY[name] = f\n            return f\n\n        return decorator\n\n    if not callable(func):\n        raise ValueError(f\"Chart function must be callable, was {type(func)}\")\n\n    _CHART_REGISTRY[name] = func\n    return None\n\n","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/analysis/tearsheet.py#L279-L315","documentation":"In the metadata_changed branch (use_ts_event_for_ts_init is false but bar-type metadata was migrated, e.g. converting internal bar type metadata to external), each batch is rebuilt with RecordBatch::try_new(schema, columns) so the new schema metadata takes effect. try_new fails — and this error is raised — if the rebuilt schema's fields no longer match the batch's actual columns in count, order, or type, which can happen with arrow version differences or unexpected schema contents.","triggerScenarios":"Converting stream data where convert_bar_type_metadata_to_external changed the schema metadata, and RecordBatch::try_new rejects the rebuild because columns do not match the new schema.","commonSituations":"Feather/stream files written by an older arrow-rs or older NautilusTrader version whose field definitions differ subtly from what the current code reconstructs; corrupted or non-standard batch metadata in legacy recordings.","solutions":["Log/diff the new schema fields against the batch columns (count, order, data types) to find the exact mismatch reported in the inner arrow error.","Re-export the source data with the current NautilusTrader/arrow-rs writer version so the schema round-trips cleanly.","If the mismatch is only metadata-related, rebuild the batch with SchemaRef built from batch.schema() plus new metadata instead of a reconstructed schema.","Check arrow-rs changelog for RecordBatch::try_new validation changes if files come from an older ecosystem version."],"exampleFix":"// before\n*batch = RecordBatch::try_new(schema.clone(), batch.columns().to_vec())?;\n\n// after: build schema from the batch's own fields\nlet new_schema = Arc::new(Schema::new(batch.schema().fields().clone())\n    .with_metadata(new_metadata));\n*batch = RecordBatch::try_new(new_schema, batch.columns().to_vec())?;","handlingStrategy":"try-catch","validationCode":"// verify rebuilt schema fields equal the batch's own fields\nlet fields_match = schema.fields() == batch.schema().fields();\nassert!(fields_match, \"rebuilt schema fields must match batch columns\");","typeGuard":"fn schema_fields_match(new: &Schema, batch: &RecordBatch) -> bool {\n    new.fields() == batch.schema().fields()\n}","tryCatchPattern":"match RecordBatch::try_new(schema.clone(), batch.columns().to_vec()) {\n    Err(e) => {\n        // fall back to batch's own fields + new metadata, or log and skip\n    }\n    Ok(b) => *batch = b,\n}","preventionTips":["Build the new schema from the batch's own fields plus updated metadata rather than reconstructing fields","Round-trip a small sample file through the current writer version before bulk conversion","Keep arrow-rs versions consistent across write and conversion pipelines"],"tags":["arrow","recordbatch","schema","metadata","data-conversion"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}