Repository navigation
feat: YAML feature builders, feature caching, importance/selection, pipeline audit - #821
Merged
gelluisaac merged 2 commits intoSep 28, 2026
Conversation
…ipeline audit Implements four feature-store and governance issues in one coherent change. Closes Traqora#742 Closes Traqora#743 Closes Traqora#744 Closes Traqora#757 Traqora#742 — YAML-configurable feature builders: - astroml/features/yaml_builders.py defines FeatureBuilderSpec (name, description, primitive, inputs, window, output_column, tags), a strict loader (unknown keys, duplicate names, and bad windows fail loudly), eight built-in primitives (count, sum, mean, max, min, std, unique_count, ratio), and registration into FeatureRegistryService. - configs/feature_builders.yaml ships six documented example builders. Traqora#743 — caching layer for expensive features: - astroml/features/cached_builders.py wraps builders with a transparent FeatureCache (memory/disk/Redis) keyed by (feature, window, data_version, definition_hash, entity). Definition changes produce new keys so stale entries expire naturally; explicit invalidate/recompute/invalidate_all cover forced refreshes. Traqora#744 — feature importance and selection: - astroml/features/importance.py adds model-agnostic permutation importance (R2 or accuracy scorer) and select_features with variance/missing/correlation filters plus importance-threshold and top-k cuts, mirroring configs/feature_engineering.yaml thresholds. Traqora#757 — audit logging for critical pipeline operations: - astroml/tracking/pipeline_audit.py records immutable, hash-chained who/what/when/result records for model activations, config changes, and rollbacks, reusing the governance AuditStore backends; verify_chain detects tampered history. Documented in docs/AUDIT_TRAIL.md; usage of all three feature modules documented in docs/FEATURE_STORE.md. Also repairs astroml/cache/graph_cache.py, which was left unimportable on main by an earlier merge (two concatenated module docstrings left bare code and interleaved class bodies from two implementations). Restored the last coherent version (decorators + GraphCacheStats API) and added the cached_graph_computation decorator the package __init__ exports; all 15 tests in tests/test_cache_invalidation.py pass again.
|
@abercrombie04 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📏 Pull request size warningThis pull request exceeds the review-friendly size limits. CI is not blocked — this is guidance, not a gate.
Why it matters Review quality drops sharply with diff size: defects slip through, review turnaround grows, and reverts become riskier because unrelated changes are bundled together. What to do
Legitimately large?
Breached limits
|
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.
Closes #742
Closes #743
Closes #744
Closes #757
Overview
This PR implements four assigned feature-store and governance issues in one coherent change. They form a natural progression: features become declaratively configurable (#742), configurable features gain a transparent cache (#743), results become analyzable and selectable (#744), and the pipeline operations that change any of it become auditable (#757).
Changes
#742 — Add configurable feature-builder definitions (YAML)
New:
astroml/features/yaml_builders.pyFeatureBuilderSpec: a frozen dataclass capturingname,description,primitive,inputs(entity / source / columns),window(7d,12h,30m,45s),output_column,feature_type,tags,owner, and primitive-specificparams. Invalid windows and empty names are rejected at construction.load_feature_builder_specs(path): strict YAML loader — missing files, malformed YAML, a missingbuilderslist, unknown keys (typo protection), duplicate names, and invalidfeature_typevalues all raiseBuilderSpecErrorwith the offending index.count,sum,mean,max,min,std,unique_count,ratio(all window-agnostic; the caller passes rows already filtered to the entity/window). Custom primitives merge over the built-ins via an explicitprimitives=mapping; passing an explicit mapping replaces built-ins so callers can restrict the surface.register_feature_builder_specs(registry, specs): registers each spec as aFeatureDefinitionwith its computer attached, taggingyaml_builderand recording adefinition_hashin metadata — this hash is the cache-invalidation hook for Add caching layer for expensive features #743.configs/feature_builders.yaml— six fully documented example builders (transaction counts, volume sums, averages, max single transaction, distinct counterparties, inbound/outbound ratio) that double as the documentation of the format.Caching / recompute semantics (documented in module, config, and docs/FEATURE_STORE.md): every output-affecting field is part of the definition hash; changing YAML never silently reuses old values.
#743 — Add caching layer for expensive features
New:
astroml/features/cached_builders.pyCachedFeatureBuilderwraps any builder spec with the existingFeatureCachebackend (memory, disk, or Redis — reused fromastroml.features.feature_cache/astroml.cache, per the issue's instruction).(feature, window, data_version, definition_hash, entity, extra context)— deterministic and complete.computereturns aFeatureCacheResult(value,cache_hit,cache_key) so callers can observe hit rates;compute_batchhandles many entities.invalidate(key),recompute(key)(invalidate + compute), andinvalidate_all()for hard resets. Bumpingdata_versionforces global recompute after a data refresh; changing the YAML definition naturally orphans old entries (they expire via TTL/LRU rather than being read).#744 — Add feature importance and selection utilities
New:
astroml/features/importance.pycompute_permutation_importance(predict, X, y, ...): model-agnostic permutation importance — shuffles one column at a time, records the scorer drop vs. baseline. Default scorer is accuracy for binary targets and R² otherwise; custom scorers are supported. Seeded RNG gives reproducible reports; results are plain dataclasses (FeatureImportanceReport, withranked(),top_k(),to_frame()).select_features(X, y, predict=None, ...): transparent selection combiningconfigs/feature_engineering.yaml; the correlation filter handles constant/all-NaN columns safely under pandas 3.x),top_kcuts when a predictor is supplied.SelectionReport.droppedrecords a human-readable reason per dropped column, and.transform(X)applies the selection.#757 — Add audit logging for critical pipeline operations
New:
astroml/tracking/pipeline_audit.pyPipelineAuditLoggerrecords frozen, who/what/when/result records formodel_activated,model_deactivated,model_rolled_back,config_changed,config_rolled_back, andfeature_config_changed.AuditStorebackends (InMemoryAuditStorefor tests, append-onlyFileAuditStoreNDJSON for production) — no new infrastructure, aligned withdocs/AUDIT_TRAIL.mdconventions.verify_chain()detects edits, deletions, or reordering. The chain survived a subtle bug hunt: timestamps must propagate through the store roundtrip and ordering must use the sequence id (timestamps can tie), both covered by tests.docs/AUDIT_TRAIL.mdgains a full "Pipeline Audit Logging (Issue Add audit logging for critical pipeline operations #757)" section (operations table, tamper-evidence, usage, retention).Tests (85 new, all passing)
tests/features/test_yaml_builders.py— window parsing, strict YAML loading (9 error paths), every primitive's math including empty/degenerate inputs, definition-hash stability/sensitivity, registry integration, and a guard that the shipped example config always loads.tests/features/test_cached_builders.py— key construction across all dimensions, hit/miss transitions, entity isolation, data-version bumps forcing recompute, invalidate/recompute semantics, batch API, stats, and unknown-primitive errors.tests/features/test_importance.py— signal-dominates-noise ranking, exact baseline scoring, seed reproducibility, feature subsets, error paths, frame rendering, binary-target scoring, and each filter/selection path.tests/tracking/test_pipeline_audit.py— who/what/when/result capture, record immutability, chain verification (including two tamper scenarios), query filters, file-store roundtrip, and UTC/monotonic timestamps.Repo health fix (required for CI to run at all)
astroml/cache/graph_cache.pywas left unimportable on currentmain— the #818 merge concatenated two module docstrings (leaving the second's em-dash as bare code,SyntaxError: invalid character '—') and interleaved class bodies from two incompatible implementations (self._lru/self._redisvs_MemoryGraphStore). Every pytest collection in CI would fail onimport astroml.cache. This PR restores the last coherent implementation (the decorator +GraphCacheStatsAPI thattests/test_cache_invalidation.pytargets) and adds thecached_graph_computationdecorator the package__init__exports but no surviving version defined. All 15 cache-invalidation tests pass again.Verification
pytest tests/features/test_yaml_builders.py tests/features/test_cached_builders.py tests/features/test_importance.py tests/tracking/test_pipeline_audit.py tests/test_cache_invalidation.py→ 99 passedblack --checkon all touched files → clean (remaining reformat candidates inastroml/features/are pre-existing files this PR does not touch)ruff checkon all touched files → cleanmypyon the four new modules → cleandocs/AUDIT_TRAIL.md,docs/FEATURE_STORE.md, and inline module/config docstrings