Improve ObjectStore ergonomics for end-of-run persistence - #9674
Draft
jhonabreul wants to merge 1 commit into
Draft
Improve ObjectStore ergonomics for end-of-run persistence#9674jhonabreul wants to merge 1 commit into
jhonabreul wants to merge 1 commit into
Conversation
- Key rules (charset/extension) move to static ObjectStore.IsSupportedKey; unsupported-key errors now state the rules and point to the new ObjectStore.SanitizeKey helper for programmatically-built keys - Reading a missing key lists the available keys in the error - New Python-facing helpers: save_json/read_json with a tolerant encoder (datetime/date/time, Decimal, numpy scalars, Symbol, non-string dict keys) and read_json default for missing keys, save_dataframe (CSV, or JSON for .json keys) and save_text as an alias of save - Unit tests plus ObjectStoreErgonomicsRegressionAlgorithm (C# + Python)
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.
Description
End-of-run persistence to the ObjectStore is a common pattern, and its most frequent failures surface only in
OnEndOfAlgorithm, losing the output of an otherwise green run:The changes:
ObjectStore.IsSupportedKey/SanitizeKey(static): key validation moves to theObjectStorewrapper as the single source;SanitizeKeyconverts an arbitrary name into a supported key.SanitizeKey.SaveJson(path, PyObject)/ReadJson(path, default=None): Python JSON helpers with a tolerant encoder (datetime/dateas ISO-8601,Decimal/numpy as numbers,Symboland other types viastr()). The generic C# overloads are untouched.SaveDataframe(path, dataFrame): stores a pandas DataFrame/Series as CSV (JSON for.jsonkeys).SaveText: alias ofSave(path, text, encoding).Related Issue
N/A
Motivation and Context
Completed backtests can die on their final persistence call. Eager, self-explanatory validation plus tolerant JSON turns these total-loss failures into first-try successes.
Requires Documentation Change
Yes: the new
ObjectStoremembers and the improved errors.How Has This Been Tested?
LocalObjectStoreTestscases: key validation, rejection message,SanitizeKeycases, missing-key listing,SaveText, plus a Python-side test forsave_json/read_json/save_dataframe. Full storage suite: 136 passed, 0 failed.ObjectStoreErgonomicsRegressionAlgorithm(C# + Python): rejection, sanitize-then-save, text round trip, missing-key error; the Python twin adds the tolerant JSON round trip andsave_dataframe. Both pass.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>