Skip to content

fix(storage): persist instrument file in the column order the reader parses - #2390

Open
hz c (chz03) wants to merge 1 commit into
microsoft:mainfrom
chz03:fix/instrument-storage-write-order
Open

hz c (chz03) wants to merge 1 commit into
microsoft:mainfrom
chz03:fix/instrument-storage-write-order

Conversation

@chz03

Copy link
Copy Markdown

Description

  • FileInstrumentStorage._write_instrument built a DataFrame with column order [start_time, end_time, symbol] and persisted it with a bare df.to_csv, immediately overwriting the reordered [symbol, start_time, end_time] write above it. _read_instrument parses the file as [symbol, start_time, end_time] (usecols=[0, 1, 2], names=[SYMBOL, START, END]), so writing and then reading through the storage API never round-tripped: __getitem__ raises KeyError for the symbol, and list_instruments raises DateParseError (a symbol string arrives where an end date is expected).
  • The mismatch is invisible with data from scripts/dump_bin.py, which writes the reader's column order directly and bypasses this class. Existing tests only read bundled data, so the write→read round-trip was never covered.
  • Fix: persist only the reordered frame (matching the reader and dump_bin's on-disk layout), drop the overwriting bare write, and pass encoding="utf-8" for parity with _write_calendar. Adds TestInstrumentStorageRoundTrip, which writes through the public __setitem__ and reads back via __getitem__ / .data.

Motivation and Context

  • Any custom data provider that writes instruments through FileInstrumentStorage currently corrupts the instruments file for subsequent reads on both the 0.9.7 release and current main.
  • No existing issue or PR covers this (searched).
  • Verified red on current main logic and green with this change against the released 0.9.7 wheel (whose _write_instrument is identical to main), on Windows 11 / Python 3.12.10; CI covers main directly.

🤖 Generated with Claude Code

…parses

FileInstrumentStorage._write_instrument persisted the concatenated frame
with column order [start_time, end_time, symbol] via a bare df.to_csv,
immediately overwriting the reordered [symbol, start_time, end_time]
write above it, while _read_instrument parses [symbol, start, end].
Writing and reading through the storage API therefore never round-tripped
(KeyError on read; DateParseError from list_instruments). dump_bin writes
the reader's order directly, which masked the mismatch.

Persist only the reordered frame, add encoding="utf-8" for parity with
_write_calendar, and cover the round-trip with a regression test.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@chz03

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant