From f48679b52ec32448c0fca46894c4511c23f6b9a9 Mon Sep 17 00:00:00 2001 From: Rantaharju Jarno Date: Tue, 20 Feb 2024 14:35:24 +0200 Subject: [PATCH] Remove warnings in tests. Mostly row index accesses. --- tests/reading/test_read_mhealth.py | 53 +++++++++++++++++------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/reading/test_read_mhealth.py b/tests/reading/test_read_mhealth.py index 939e29a1..73347b4e 100644 --- a/tests/reading/test_read_mhealth.py +++ b/tests/reading/test_read_mhealth.py @@ -11,7 +11,7 @@ def test_format_part_of_day(): }]) df = niimpy.reading.mhealth.format_part_of_day(df, "prefix.col") - assert df["date"][0] == pd.to_datetime("2022-01-14") + assert df["date"][0] == pd.to_datetime("2022-01-14 00:00:00+00:00") assert df["part_of_day"][0] == "afternoon" @@ -28,8 +28,8 @@ def test_duration_to_timedelta(): df = niimpy.reading.mhealth.duration_to_timedelta(df, "prefix.col") - assert df["prefix.col"][0] == pd.to_timedelta(20, unit="minutes") - assert df["prefix.col"][1] == pd.to_timedelta(0.02, unit="nanoseconds") + assert df.iloc[0]["prefix.col"] == pd.to_timedelta(20, unit="minutes") + assert df.iloc[1]["prefix.col"] == pd.to_timedelta(0.02, unit="nanoseconds") def test_format_time_interval(): @@ -66,32 +66,41 @@ def test_format_time_interval(): def test_read_mhealth_total_sleep_time(): data = niimpy.reading.mhealth.total_sleep_time_from_file(config.MHEALTH_TOTAL_SLEEP_TIME_PATH) - assert data['total_sleep_time'][0] == pd.Timedelta(465, unit="minutes") - assert data['descriptive_statistic'][1] == "average" - assert data['descriptive_statistic_denominator'][1] == "d" - assert data['date'][3] == pd.to_datetime("2013-02-05") - assert data['part_of_day'][3] == "evening" - assert data['start'][0] == pd.to_datetime("2016-02-06 04:35:00+00:00") - assert data['end'][0] == pd.to_datetime("2016-02-06 14:35:00+00:00") - assert data['start'][2] == pd.to_datetime("2013-01-26 07:35:00+00:00") - assert data['end'][2] == pd.to_datetime("2013-02-05 07:35:00+00:00") + + row = data.loc["2016-02-06 04:35:00+00:00"] + assert row['total_sleep_time'] == pd.Timedelta(465, unit="minutes") + assert row['start'] == pd.to_datetime("2016-02-06 04:35:00+00:00") + assert row['end'] == pd.to_datetime("2016-02-06 14:35:00+00:00") + + row = data.loc["2016-02-05 15:00:00+00:00"] + assert row['descriptive_statistic'] == "average" + assert row['descriptive_statistic_denominator'] == "d" + + row = data.loc["2013-01-26 07:35:00+00:00"] + assert row['start'] == pd.to_datetime("2013-01-26 07:35:00+00:00") + assert row['end'] == pd.to_datetime("2013-02-05 07:35:00+00:00") + + part_of_day_row = data.iloc[3] + assert part_of_day_row['date'] == pd.to_datetime("2013-02-05", utc=True) + assert part_of_day_row['part_of_day'] == "evening" + def test_read_mhealth_heart_rate(): data = niimpy.reading.mhealth.heart_rate_from_file(config.MHEALTH_HEART_RATE_PATH) - assert data['heart_rate'][0] == 70 - assert data['heart_rate'][1] == 65 - assert data['descriptive_statistic'][2] == "average" - assert data['temporal_relationship_to_sleep'][2] == "during sleep" - assert data['temporal_relationship_to_sleep'][0] == "on waking" - assert data['start'][2] == pd.to_datetime("2023-12-20T01:50:00-02:00") + assert data.iloc[0]['heart_rate'] == 70 + assert data.iloc[1]['heart_rate'] == 65 + assert data.iloc[2]['descriptive_statistic'] == "average" + assert data.iloc[2]['temporal_relationship_to_sleep'] == "during sleep" + assert data.iloc[0]['temporal_relationship_to_sleep'] == "on waking" + assert data.iloc[2]['start'] == pd.to_datetime("2023-12-20T01:50:00-02:00") def test_read_mhealth_geolocation(): data = niimpy.reading.mhealth.geolocation_from_file(config.MHEALTH_GEOLOCATION_PATH) - assert data['latitude'][0] == 60.1867 - assert data['longitude'][0] == 24.8283 - assert data['latitude'][1] == 60.1867 - assert data['longitude'][1] == 24.8283 + assert data.iloc[0]['latitude'] == 60.1867 + assert data.iloc[0]['longitude'] == 24.8283 + assert data.iloc[1]['latitude'] == 60.1867 + assert data.iloc[1]['longitude'] == 24.8283