def test_agg_level(self, example_staypoints, default_kwargs): """Test if different aggregation works.""" default_kwargs["agg_level"] = "user" default_kwargs["thresh_loc_period"] = pd.Timedelta("1d") f = pre_filter_locations(example_staypoints, **default_kwargs) assert all(f == ( example_staypoints[["user_id", "location_id"]] == [0, 1]).all( axis=1))
def test_pre_filter(self, example_freq, default_kwargs): """Test if function calls pre_filter correctly.""" default_kwargs["agg_level"] = "user" default_kwargs["thresh_sp_at_loc"] = 2 li = location_identifier(example_freq, method="FREQ", pre_filter=True, **default_kwargs) f = pre_filter_locations(example_freq, **default_kwargs) example_freq.loc[f, "activity_label"] = freq_method( example_freq[f])["activity_label"] assert_geodataframe_equal(li, example_freq)
def test_thresh_loc(self, example_staypoints, default_kwargs): """Test the minimum location per user parameter.""" default_kwargs["thresh_loc"] = 2 f = pre_filter_locations(example_staypoints, **default_kwargs) assert all(f == (example_staypoints["user_id"] == 0))
def test_no_kw(self, example_staypoints, default_kwargs): """Test that nothing gets filtered if all parameters are set to zero.""" assert all(pre_filter_locations(example_staypoints, **default_kwargs))
def test_agg_level_error(self, example_staypoints, default_kwargs): """Test if ValueError is raised for unknown agg_level.""" default_kwargs["agg_level"] = "unknown" with pytest.raises(ValueError): pre_filter_locations(example_staypoints, **default_kwargs)
def test_loc_period(self, example_staypoints, default_kwargs): """Test the minimum period per location parameter.""" default_kwargs["thresh_loc_period"] = "2d" f = pre_filter_locations(example_staypoints, **default_kwargs) assert all(f == (example_staypoints["location_id"] == 0))
def test_tresh_loc_time(self, example_staypoints, default_kwargs): """Test the minimum duration per location parameter.""" default_kwargs["thresh_loc_time"] = "14h" f = pre_filter_locations(example_staypoints, **default_kwargs) assert all(f == (example_staypoints["location_id"] == 1))
def test_non_continous_index(self, example_staypoints, default_kwargs): """Test if function works with non-continous index.""" # issue-#247 example_staypoints.index = [0, 999, 1, 15] f = pre_filter_locations(example_staypoints, **default_kwargs) assert_index_equal(f.index, example_staypoints.index)