Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/source/whatsnew/skeleton.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ None
Bug Fixes
~~~~~~~~~

None
- Fix ``_weak_lru_cache`` double-counting cache misses and fix
``cache_clear()`` crash from subscripting integer counters. (:issue:`315`)
- Fix ``AssetFinder._lookup_symbol_strict`` to materialize ``map()`` iterator
to a list before reuse, preventing empty ``options`` dict in
``SameSymbolUsedAcrossCountries`` error. (:issue:`315`)
- Fix ``AssetDBWriter._all_tables_present`` to check all tables instead of
returning after the first one. (:issue:`315`)
- Fix ``BeforeClose.calculate_dates`` to compare ``self.cal.name`` instead of
``self.cal`` to the string ``"us_futures"``. (:issue:`315`)
- Fix ``AssetDBWriter.write_direct`` argument order for futures, which
previously swapped the data and defaults arguments to
``_generate_output_dataframe``. (:issue:`315`)

Performance
~~~~~~~~~~~
Expand Down
16 changes: 7 additions & 9 deletions src/zipline/assets/asset_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def write_direct(
)

if futures is not None:
futures = _generate_output_dataframe(_futures_defaults, futures)
futures = _generate_output_dataframe(futures, _futures_defaults)

if exchanges is not None:
exchanges = _generate_output_dataframe(
Expand Down Expand Up @@ -876,7 +876,7 @@ def _write_assets(self, asset_type, assets, txn, chunk_size, mapping_data=None):

def _all_tables_present(self, txn):
"""
Checks if any tables are present in the current assets database.
Checks if all tables are present in the current assets database.

Parameters
----------
Expand All @@ -886,14 +886,12 @@ def _all_tables_present(self, txn):
Returns
-------
has_tables : bool
True if any tables are present, otherwise False.
True if all tables are present, otherwise False.
"""
# conn = txn.connect()
for table_name in asset_db_table_names:
return sa.inspect(txn).has_table(table_name)
# if txn.dialect.has_table(conn, table_name):
# return True
# return False
return all(
sa.inspect(txn).has_table(table_name)
for table_name in asset_db_table_names
)

def init_db(self, txn=None):
"""Connect to database and create tables.
Expand Down
2 changes: 1 addition & 1 deletion src/zipline/assets/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def _lookup_symbol_strict(self, ownership_map, multi_country, symbol, as_of_date
options = {self.retrieve_asset(owner.sid) for owner in owners}

if multi_country:
country_codes = map(attrgetter("country_code"), options)
country_codes = list(map(attrgetter("country_code"), options))

if len(set(country_codes)) > 1:
raise SameSymbolUsedAcrossCountries(
Expand Down
2 changes: 1 addition & 1 deletion src/zipline/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def calculate_dates(self, dt):
# Align the market close time here with the execution time used by the
# simulation clock. This ensures that scheduled functions trigger at
# the correct times.
if self.cal == "us_futures":
if self.cal.name == "us_futures":
self._period_end = self.cal.execution_time_from_close(period_end)
else:
self._period_end = period_end
Expand Down
4 changes: 2 additions & 2 deletions src/zipline/utils/memoize.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def wrapper(*args, **kwds):
result = user_function(*args, **kwds)
with lock:
cache[key] = result # record recent use of this key
misses += 1
if cache_len() > maxsize:
# purge least recently used cache entry
cache_popitem(last=False)
Expand All @@ -176,9 +175,10 @@ def cache_info():

def cache_clear():
"""Clear the cache and cache statistics"""
nonlocal hits, misses
with lock:
cache.clear()
hits[0] = misses[0] = 0
hits = misses = 0

wrapper.cache_info = cache_info
wrapper.cache_clear = cache_clear
Expand Down