Skip to content

Fix 5 bugs: LRU cache, symbol lookup, asset writer, BeforeClose, write_direct#327

Open
VedantMadane wants to merge 1 commit intostefan-jansen:mainfrom
VedantMadane:fix-asset-cache-event-bugs
Open

Fix 5 bugs: LRU cache, symbol lookup, asset writer, BeforeClose, write_direct#327
VedantMadane wants to merge 1 commit intostefan-jansen:mainfrom
VedantMadane:fix-asset-cache-event-bugs

Conversation

@VedantMadane
Copy link

Summary

Fixes 5 bugs reported in #315:

  1. _weak_lru_cache double-counts misses (memoize.py): Cache miss counter was incremented both on KeyError (line 159) and after storing the result (line 164). Removed the duplicate increment.

  2. _weak_lru_cache cache_clear() crashes (memoize.py): cache_clear() used list indexing (hits[0] = misses[0] = 0) on plain int variables, causing a TypeError. Fixed to use nonlocal and direct assignment.

  3. _lookup_symbol_strict exhausts map() iterator (assets.py): country_codes = map(...) creates a one-shot iterator. set(country_codes) consumed it, leaving zip(country_codes, options) empty. Replaced with a list comprehension.

  4. _all_tables_present returns on first iteration (asset_writer.py): The return inside the for loop caused the method to only check the first table. Replaced with any() over all tables.

  5. write_direct swaps arguments for futures (asset_writer.py): _generate_output_dataframe(_futures_defaults, futures) passed defaults as data_subset and vice versa. Corrected argument order.

  6. BeforeClose compares calendar object to string (events.py): self.cal == "us_futures" always evaluates to False because self.cal is a calendar object. Fixed to self.cal.name == "us_futures", consistent with AfterOpen.calculate_dates.

Test plan

  • Verified each bug against the issue description
  • Existing test suite should pass (no behavioral regressions for correct-path code)
  • BeforeClose now correctly aligns execution times for us_futures calendars

Fixes #315

…te_direct

- memoize.py: Remove double-counting of cache misses in _weak_lru_cache
  (miss incremented on KeyError AND after storing result)
- memoize.py: Fix cache_clear() crash - used list indexing (hits[0]) on
  plain int variables; use nonlocal instead
- assets.py: Fix _lookup_symbol_strict exhausting map() iterator before
  zip() can consume it; use list comprehension instead
- asset_writer.py: Fix _all_tables_present returning on first loop
  iteration instead of checking all tables
- asset_writer.py: Fix write_direct swapping data_subset/defaults args
  for futures in _generate_output_dataframe call
- events.py: Fix BeforeClose comparing calendar object to string
  "us_futures" instead of self.cal.name

Fixes stefan-jansen#315

Signed-off-by: Vedant Madane <vedantnm@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

BUG: Bugs in asset writer, LRU cache, symbol lookup, and event scheduling

1 participant