Skip to content

Commit

Permalink
fix(accPlot): check dataframe index is datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
chanshing committed Nov 14, 2023
1 parent fec1139 commit 244549c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/accelerometer/accPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ def main(): # noqa: C901

# read time series file to pandas DataFrame
data = pd.read_csv(
args.timeSeriesFile, index_col='time',
parse_dates=['time'], date_parser=utils.date_parser
args.timeSeriesFile,
index_col='time',
parse_dates=['time'],
date_parser=utils.date_parser
)

# set backend if run from main
Expand All @@ -92,10 +94,10 @@ def main(): # noqa: C901


def plotTimeSeries( # noqa: C901
data,
title=None,
showFirstNDays=None
):
data,
title=None,
showFirstNDays=None
):
"""Plot overall activity and classified activity types
:param pd.DataFrame data: Input DataFrame with time series data
Expand All @@ -119,9 +121,9 @@ def plotTimeSeries( # noqa: C901
>>> fig.show()
"""

# double check time index
if 'time' in data.columns:
data = data.set_index('time')
# check index is datetime
if not isinstance(data.index, pd.DatetimeIndex):
raise ValueError("Index must be a DatetimeIndex")

# use tz-naive local time
if data.index.tz is not None:
Expand Down

0 comments on commit 244549c

Please sign in to comment.