Add symbol resolution helpers (instrument_id → raw_symbol join)#38
Merged
Conversation
Records carry only the opaque numeric hd.instrument_id; the human-readable symbol lives in Metadata.mappings as interval-keyed (raw_symbol, mapped_symbol, start_date, end_date) tuples. When a query is resolved with stype_out = INSTRUMENT_ID (the historical default) the mapped symbol is the decimal instrument-id string, making the table an interval-keyed instrument_id -> raw_symbol map. New helpers invert it and join the symbol back: - symbol_map(metadata): build the id -> intervals lookup once for reuse - symbol_for(map_or_metadata, instrument_id, ts_event): resolve symbol valid at a record's timestamp (half-open [start, end) intervals) - add_symbol_column!(df, metadata; column=:symbol): join in place, keying on the frame's instrument_id/ts_event so it also covers the row-expanded MBP-10 frame; unmatched rows get missing - records_to_dataframe(records, metadata; symbols=true): convert + join Non-INSTRUMENT_ID stype_out yields an empty map (single warning, missing column) since records can't be keyed back to the mapping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The new symbol_map / symbol_for / add_symbol_column! docstrings cross-ref each other and records_to_dataframe with [`...`](@ref); Documenter's cross_references check fails unless the targets are spliced into a docs page. Add a "Symbol Resolution" @docs block to the Conversion API reference. Bump the package version to 0.1.4 so the symbol-resolution helpers can be released (downstream DatabentoAPI.jl pins this as its minimum). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Records carry only the opaque numeric
hd.instrument_id. The human-readable symbol lives inMetadata.mappingsas interval-keyed(raw_symbol, mapped_symbol, start_date, end_date)tuples. When a query is resolved withstype_out = INSTRUMENT_ID(the historical default),mapped_symbolis the decimal instrument-id string — so the table is really an interval-keyedinstrument_id → raw_symbolmap. This PR adds helpers to invert it and join the symbol back onto records.New API
symbol_map(metadata)— build theinstrument_id → [(start_date, end_date, raw_symbol)]lookup once for reuse in a hot loop.symbol_for(map_or_metadata, instrument_id, ts_event)— resolve theraw_symbolvalid at a record'shd.ts_event(half-open[start, end)intervals;nothingif unknown/out of range).add_symbol_column!(df, metadata; column=:symbol)— join a symbol column onto a records DataFrame in place. Keys on the frame'sinstrument_id/ts_event, so it also covers the row-expanded MBP-10 frame; unmatched rows getmissing.records_to_dataframe(records, metadata; symbols=true)— convert + join in one call.Notes
INSTRUMENT_IDstype_outyields an empty map (single warning,missingcolumn), since records can't be keyed back to the mapping.YYYYMMDD), no float round-trip.test/test_symbols.jl(20 assertions) wired intoruntests.jl; covers the map, lookup edge cases (inclusive start / exclusive end / id rolls / degenerate single-day interval), the DataFrame join, custom column name, the non-INSTRUMENT_ID warning path, and the empty-frame no-op.🤖 Generated with Claude Code