Skip to content

Commit

Permalink
Improve handling of broken time series
Browse files Browse the repository at this point in the history
  • Loading branch information
highfestiva committed Oct 19, 2023
1 parent d54891c commit dc547ff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions finplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def tickValues(self, minVal, maxVal, size):
except: pass
ax = self.vb.parent()
rng = _pdtime2index(ax=ax, ts=pd.Series(rng), require_time=True)
indices = [ceil(i) for i in rng]
indices = [ceil(i) for i in rng if i>-1e200]
return [(0, indices)]
return [(0,[])]

Expand Down Expand Up @@ -291,8 +291,9 @@ def period_ns(self):
return 1
if not self._period:
timecol = self.df.columns[0]
times = self.df[timecol].iloc[0:100]
self._period = int(times.diff().median()) if len(times)>1 else 1
dtimes = self.df[timecol].iloc[0:100].diff()
dtimes = dtimes[dtimes!=0]
self._period = int(dtimes.median()) if len(dtimes)>1 else 1
return self._period

@property
Expand Down Expand Up @@ -2732,8 +2733,11 @@ def _pdtime2index(ax, ts, any_end=False, require_time=False):
if i0 < 0:
i0,i1 = 0,1
t0,t1 = xs.loc[i0], xs.loc[i1]
dt = (t-t0) / (t1-t0)
r.append(lerp(dt, i0, i1))
if t0 == t1:
r.append(i0)
else:
dt = (t-t0) / (t1-t0)
r.append(lerp(dt, i0, i1))
return r


Expand Down

0 comments on commit dc547ff

Please sign in to comment.