Skip to content

Commit

Permalink
Test that an extra column is not kept
Browse files Browse the repository at this point in the history
  • Loading branch information
rantahar committed Oct 21, 2024
1 parent 5a16356 commit 8303217
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/preprocessing/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_app_features():
screen["group"] = "group1"
battery["group"] = "group1"
test = app.extract_features_app(data, battery, screen, features=None)
data["extra_column"] = "extra"

user_comm = test[(test["user"] == "dvWdLQesv21a") & (test["app_group"] == "comm")]
user_work = test[(test["user"] == "dvWdLQesv21a") & (test["app_group"] == "work")]
Expand Down Expand Up @@ -45,3 +46,4 @@ def test_app_features():
assert user_work.loc["2019-08-06 04:00:00+03:00"]["count"] == 2
assert user_comm.loc["2019-08-05 20:00:00+03:00"]["duration"] == 3569.00
assert user_work.loc["2019-08-06 04:00:00+03:00"]["duration"] == 2578
assert "extra_column" not in test.columns
4 changes: 4 additions & 0 deletions tests/preprocessing/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@

def test_audio_features():
data["group"] = "group1"
data["extra_column"] = "extra"
test = audio.extract_features_audio(data)

assert "group" in test.columns
assert "extra_column" not in test.columns

test_user1 = test[test["user"] == "jd9INuQ5BBlW"]
assert test_user1["audio_count_silent"].sum() == 0
Expand Down
4 changes: 4 additions & 0 deletions tests/preprocessing/test_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
def test_format_battery_data():
df = df11.copy()
battery = niimpy.preprocessing.battery.format_battery_data(df, {})

assert battery.loc[Timestamp('2019-01-17 09:20:14.049999872+02:00'), 'battery_level'] == 96
assert battery.loc[Timestamp('2019-01-17 09:21:26.036000+02:00'), 'battery_health'] == '2'
assert battery.loc[Timestamp('2019-01-17 09:48:59.438999808+02:00'), 'battery_status'] == '-2'
Expand All @@ -39,8 +40,11 @@ def test_format_battery_data():

def test_battery_occurrences():
df = df11.copy()
df["extra_column"] = "extra"
k = niimpy.preprocessing.battery.battery_occurrences
occurrences = niimpy.preprocessing.battery.extract_features_battery(df, features={k: {}})

assert "extra_column" not in occurrences.columns
occurrences_user = occurrences[occurrences["user"] == "wAzQNrdKZZax"]
assert occurrences_user.loc[Timestamp('2019-01-17 09:00:00+02:00')]["occurrences"] == 3
occurrences_user = occurrences[occurrences["user"] == "lb983ODxEFUD"]
Expand Down
2 changes: 2 additions & 0 deletions tests/preprocessing/test_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ def test_message_features_with_google_chat(google_takeout_zipped):
sentiment_batch_size = 2
)
data["group"] = "group1"
data["extra_column"] = "extra"

test = comms.extract_features_comms(data, features=None)
assert "extra_column" not in test.columns
print(test.loc[pd.Timestamp("2024-01-30 13:00:00+00:00", tz='Europe/Helsinki')])
assert test.loc[pd.Timestamp("2024-01-30 13:00:00+00:00", tz='Europe/Helsinki')]["outgoing_count"] == 2
assert test.loc[pd.Timestamp("2024-01-30 13:00:00+00:00", tz='Europe/Helsinki')]["group"] == "group1"
Expand Down
2 changes: 2 additions & 0 deletions tests/preprocessing/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def test_distance_matrix():

def test_location_features():
# extract featuers
data["extra_column"] = "extra"
features = nilo.extract_features_location(data)
assert "extra_column" not in features.columns

sps = features['n_sps'].dropna()
assert ((sps > 0) & (sps < 100)).all(), "Number of SPs not reasonable"
Expand Down
3 changes: 3 additions & 0 deletions tests/preprocessing/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

def test_audio_features():

data["extra_column"] = "extra"
test = sc.extract_features_screen(data, bat, features=None)
assert "extra_column" not in test.columns

time = pd.Timestamp("2020-01-09 02:30:00", tz='Europe/Helsinki')

test_user = test[test["user"] == "jd9INuQ5BBlW"]
Expand Down
3 changes: 3 additions & 0 deletions tests/preprocessing/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ def test_step_summary():
# Converting the index as date
df.index = pd.to_datetime(df.index)
df = df.rename(columns={"subject_id": "user"})
df["extra_column"] = "extra"

summary_df = tracker.step_summary(df, {'value_col': 'steps'})

assert "extra_column" not in summary_df.columns
assert summary_df['max_sum_step'].values[0] == 13025
assert summary_df['min_sum_step'].values[0] == 5616
assert round(summary_df['avg_sum_step'].values[0], 2) == 8437.38
Expand Down

0 comments on commit 8303217

Please sign in to comment.