Skip to content

Commit

Permalink
fix(accPlot): more consistent DST handling: mask DST hour
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Nov 14, 2023
1 parent 015b50b commit b76eeef
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/accelerometer/accPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ def plotTimeSeries( # noqa: C901
if 'time' in data.columns:
data = data.set_index('time')

# use tz-naive local time
if data.index.tz is not None:
data.index = (
# convoluted way to mask the ambiguous DST pushback hour, if any
data.index
.tz_localize(None)
.tz_localize(data.index.tz, ambiguous='NaT', nonexistent='NaT')
.tz_localize(None)
)
data = data[data.index.notnull()]

# fix gaps or irregular sampling
if pd.infer_freq(data) is None:
freq = pd.infer_freq(data.head()) or '30s' # try to infer from first few rows, else default to 30s
Expand All @@ -149,7 +160,6 @@ def plotTimeSeries( # noqa: C901
data[labels] = data[labels].astype('f4') * MAXRANGE

# number of rows to display in figure (all days + legend)
data.index = data.index.tz_localize(None, ambiguous='NaT', nonexistent='NaT') # tz-unaware local time
groupedDays = data.groupby(data.index.date)
nrows = len(groupedDays) + 1

Expand Down

0 comments on commit b76eeef

Please sign in to comment.