Skip to content

Commit

Permalink
Handle 'xcal' not accepting cache=True
Browse files Browse the repository at this point in the history
Handle 'xcal' not accepting cache=True ; Remove hardcoded filepaths ; Fix small bug
  • Loading branch information
ValueRaider committed Dec 5, 2022
1 parent f7d4654 commit 7a2101a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 0 additions & 2 deletions tests/test_market_intervals_tlv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import unittest

# import sys ; sys.path.insert(0, "/home/gonzo/ReposForks/exchange_calendars.dev")

from .context import yfc_dat as yfcd
from .context import yfc_time as yfct

Expand Down
2 changes: 0 additions & 2 deletions tests/test_market_schedules_tlv.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import unittest
from pprint import pprint

# import sys ; sys.path.insert(0, "/home/gonzo/ReposForks/exchange_calendars.dev")

from .context import yfc_time as yfct
from .context import yfc_dat as yfcd

Expand Down
1 change: 1 addition & 0 deletions yfinance_cache/yfc_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ def _fetchAndAddRanges_sparse(self, h, pstr, interval, ranges_to_fetch, prepost,
except yfcd.NoPriceDataInRangeException:
# If only trying to fetch 1 day of 1d data, then print warning instead of exception.
# Could add additional condition of dividend previous day (seems to mess up table).
ignore = False
if interval == yfcd.Interval.Days1 and rend - rstart == td_1d:
ignore = True
elif interval == yfcd.Interval.Mins1 and rend - rstart <= datetime.timedelta(minutes=10):
Expand Down
15 changes: 13 additions & 2 deletions yfinance_cache/yfc_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from dateutil.relativedelta import relativedelta
from zoneinfo import ZoneInfo

import sys ; sys.path.insert(0, "/home/gonzo/ReposForks/exchange_calendars.dev")
import exchange_calendars as xcal

import pandas as pd
Expand Down Expand Up @@ -99,6 +98,7 @@ def SetExchangeTzName(exchange, tz):
schedDbMetadata = {}
db_mem = sql.connect(":memory:")
schedIntervalsCache = {}
xcal_accept_cache_arg = None


def GetExchangeDataDelay(exchange):
Expand All @@ -112,6 +112,7 @@ def GetExchangeDataDelay(exchange):

def GetCalendar(exchange):
global calCache
global xcal_accept_cache_arg

cal_name = yfcd.exchangeToXcalExchange[exchange]

Expand All @@ -123,7 +124,17 @@ def GetCalendar(exchange):
start = "1997"
else:
start = str(yfcd.yf_min_year)
cal = xcal.get_calendar(cal_name, start=start, cache=True)
if xcal_accept_cache_arg is None:
try:
xcal_accept_cache_arg = True
cal = xcal.get_calendar(cal_name, start=start, cache=True)
except TypeError:
xcal_accept_cache_arg = False
cal = xcal.get_calendar(cal_name, start=start)
elif xcal_accept_cache_arg:
cal = xcal.get_calendar(cal_name, start=start, cache=True)
else:
cal = xcal.get_calendar(cal_name, start=start)

df = cal.schedule
tz = ZoneInfo(GetExchangeTzName(exchange))
Expand Down
3 changes: 0 additions & 3 deletions yfinance_cache/yfc_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,6 @@ def price_history_cleanup_tz_mess():
f_pieces = f.split('.')
ext = f_pieces[-1]

# if fp != "/home/gonzo/.cache/yfinance-cache/MEL.NZ/history-1d.pkl":
# continue

f_base = '.'.join(f_pieces[:-1])

if ("history" in f_base) and (ext == "pkl"):
Expand Down

0 comments on commit 7a2101a

Please sign in to comment.