From 244549c7cd35898484a7d2bd75c10953d94a4b1f Mon Sep 17 00:00:00 2001 From: Shing Chan Date: Tue, 14 Nov 2023 17:50:52 +0000 Subject: [PATCH] fix(accPlot): check dataframe index is datetime --- src/accelerometer/accPlot.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/accelerometer/accPlot.py b/src/accelerometer/accPlot.py index cc91efad..36cba7cc 100644 --- a/src/accelerometer/accPlot.py +++ b/src/accelerometer/accPlot.py @@ -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 @@ -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 @@ -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: