Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bug fixes #42

Merged
merged 1 commit into from
Aug 27, 2023
Merged
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
8 changes: 6 additions & 2 deletions yfinance_cache/yfc_prices_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def _getCachedPrices(self):
elif h is not None:
h_modified = False

# h = yfcu.CustomNanCheckingDataFrame(h)

if "Adj Close" in h.columns:
raise Exception("Adj Close in cached h")

Expand Down Expand Up @@ -817,14 +819,14 @@ def get(self, start=None, end=None, period=None, max_age=None, trigger_at_market
delete_range = (sched is not None) and dt_now < (sched["open"].iloc[0] + yf_lag)
if delete_range:
if debug_yfc:
print("- deleting future range:", ranges_to_fetch[i])
print("- deleting future range:", r[i])
del ranges_to_fetch[i]
else:
# Check if range ends in future, if yes then adjust to tomorrow max
y = r[1]
if isinstance(y, (datetime, pd.Timestamp)):
if y > dt_now:
ranges_to_fetch[i][1] = min(dt_now.ceil(), y)
ranges_to_fetch[i] = (r[0], min(dt_now.ceil('1D'), y))
elif y > d_now_exchange:
sched = yfct.GetExchangeSchedule(self.exchange, d_now_exchange, y + td_1d)
if sched is not None:
Expand Down Expand Up @@ -2440,6 +2442,8 @@ def _fetchYfHistory_dateRange(self, start, end, prepost, debug):
elif debug_yfc:
print(log_msg)

# df = yfcu.CustomNanCheckingDataFrame(df)

return df

def _reconstruct_intervals_batch(self, df, tag=-1):
Expand Down
28 changes: 28 additions & 0 deletions yfinance_cache/yfc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@
from . import yfc_dat as yfcd


class CustomNanCheckingDataFrame(pd.DataFrame):
def __init__(self, *args, **kwargs):
super(CustomNanCheckingDataFrame, self).__init__(*args, **kwargs)
self.check_nans()

def __setitem__(self, key, value):
super(CustomNanCheckingDataFrame, self).__setitem__(key, value)
self.check_nans()

@classmethod
def concat(cls, objs, *args, **kwargs):
result = super(CustomNanCheckingDataFrame, cls).concat(objs, *args, **kwargs)
result.check_nans()
return result

@classmethod
def merge(cls, *args, **kwargs):
result = super(CustomNanCheckingDataFrame, cls).merge(*args, **kwargs)
result.check_nans()
return result

def check_nans(self):
if 'Repaired?' not in self.columns:
return
if self['Repaired?'].isna().any():
raise Exception(f"NaNs detected in column 'Repaired?'!")


def TypeCheckStr(var, varName):
if not isinstance(var, str):
raise TypeError(f"'{varName}' must be str not {type(var)}")
Expand Down