Repository: mie-lab/trackintel
Pull request #599 (2024-01-14 01:23:10)

ENH: Change AttributeError to ValueError
A bit of a pet peeve of mine.
All over trackintel we used `AttributeError` where `ValueError` would make more sense.
I changed it where it made sense for me.

for reference: https://docs.python.org/3/library/exceptions.html
>**AttributeError**
Raised when an attribute reference (see [Attribute references](https://docs.python.org/3/reference/expressions.html#attribute-references)) or assignment fails. (When an object does not support attribute references or attribute assignments at all, [TypeError](https://docs.python.org/3/library/exceptions.html#TypeError) is raised.)

e.g.
```python
>> a = object()
>> a.not_existing_field
AttributeError: 'object' object has no attribute 'not_existing_field'
```
> **ValueError**
Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as [IndexError](https://docs.python.org/3/library/exceptions.html#IndexError).

e.g.
```python
>> chr(0x1100001)
ValueError: chr() arg not in range(0x110000)
```

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/mie-lab/trackintel/pull/599?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`a74f437`)](https://app.codecov.io/gh/mie-lab/trackintel/commit/a74f4378dc65801dcceb507372d7570b1c885198?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) 93.31% compared to head [(`c0f8ab9`)](https://app.codecov.io/gh/mie-lab/trackintel/pull/599?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab) 93.41%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
+ Coverage   93.31%   93.41%   +0.09%     
==========================================
  Files          33       33              
  Lines        2064     2064              
  Branches      364      364              
==========================================
+ Hits         1926     1928       +2     
+ Misses        127      126       -1     
+ Partials       11       10       -1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/mie-lab/trackintel/pull/599?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mie-lab).


Patch:
diff --git a/LICENSE b/LICENSE
index fc78d15..283b6be 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2019 mie-lab at ETH Zurich, Switzerland
+Copyright (c) 2024 mie-lab at ETH Zurich, Switzerland
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/apt.txt b/apt.txt
deleted file mode 100644
index 16f3421..0000000
--- a/apt.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-libspatialindex-dev
diff --git a/docs/conf.py b/docs/conf.py
index 59d948e..172ff65 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -55,7 +55,7 @@ autodoc_mock_imports = [
 # -- Project information -----------------------------------------------------
 
 project = "trackintel"
-copyright = "2019 - 2023, Dominik Bucher, Henry Martin, Ye Hong, Nina Wiedemann"
+copyright = "2019 - 2024, Dominik Bucher, Henry Martin, Ye Hong, Nina Wiedemann"
 author = "Dominik Bucher, Henry Martin, Ye Hong, Nina Wiedemann"
 
 
diff --git a/trackintel/analysis/labelling.py b/trackintel/analysis/labelling.py
index cd33060..c2707af 100644
--- a/trackintel/analysis/labelling.py
+++ b/trackintel/analysis/labelling.py
@@ -38,7 +38,7 @@ def create_activity_flag(staypoints, method="time_threshold", time_threshold=15.
             minutes=time_threshold
         )
     else:
-        raise AttributeError(f"Method {method} not known for creating activity flag.")
+        raise ValueError(f"Method {method} not known for creating activity flag.")
 
     return staypoints
 
@@ -86,7 +86,7 @@ def predict_transport_mode(triplegs, method="simple-coarse", **kwargs):
         triplegs["mode"] = _predict_transport_mode_simple_coarse(triplegs, categories)
         return triplegs
     else:
-        raise AttributeError(f"Method {method} not known for predicting tripleg transport modes.")
+        raise ValueError(f"Method {method} not known for predicting tripleg transport modes.")
 
 
 def _predict_transport_mode_simple_coarse(triplegs, categories):
diff --git a/trackintel/analysis/modal_split.py b/trackintel/analysis/modal_split.py
index 23eface..67ef3de 100644
--- a/trackintel/analysis/modal_split.py
+++ b/trackintel/analysis/modal_split.py
@@ -55,7 +55,7 @@ def calculate_modal_split(tpls, freq=None, metric="count", per_user=False, norm=
         metric = "mode"  # count on mode
     else:
         error_msg = f"Metric {metric} unknown, only metrics {{'count', 'distance', 'duration'}} are supported."
-        raise AttributeError(error_msg)
+        raise ValueError(error_msg)
 
     group = []
     if per_user:
diff --git a/trackintel/analysis/tracking_quality.py b/trackintel/analysis/tracking_quality.py
index 28ed88b..407724f 100644
--- a/trackintel/analysis/tracking_quality.py
+++ b/trackintel/analysis/tracking_quality.py
@@ -1,6 +1,5 @@
 import warnings
 
-import numpy as np
 import pandas as pd
 
 
@@ -108,7 +107,7 @@ def temporal_tracking_quality(source, granularity="all"):
         column_name = "hour"
 
     else:
-        raise AttributeError(
+        raise ValueError(
             f"granularity unknown. We only support ['all', 'day', 'week', 'weekday', 'hour']. You passed {granularity}"
         )
 
@@ -159,7 +158,7 @@ def _get_tracking_quality_user(df, granularity="all"):
         # (entries from multiple days may be grouped together)
         extent = (60 * 60) * (df["day"].max() - df["day"].min() + 1)
     else:
-        raise AttributeError(
+        raise ValueError(
             f"granularity unknown. We only support ['all', 'day', 'week', 'weekday', 'hour']. You passed {granularity}"
         )
     return pd.Series([tracked_duration / extent], index=["quality"])
diff --git a/trackintel/geogr/distances.py b/trackintel/geogr/distances.py
index a8c0fe7..ce3b04c 100644
--- a/trackintel/geogr/distances.py
+++ b/trackintel/geogr/distances.py
@@ -348,7 +348,7 @@ def get_speed_triplegs(triplegs, positionfixes=None, method="tpls_speed"):
     # Pfs-based method: compute speed per positionfix and average then
     elif method == "pfs_mean_speed":
         if positionfixes is None:
-            raise AttributeError('Method "pfs_mean_speed" requires positionfixes as input.')
+            raise ValueError('Method "pfs_mean_speed" requires positionfixes as input.')
         if "tripleg_id" not in positionfixes:
             raise AttributeError('Positionfixes must include column "tripleg_id".')
         # group positionfixes by triplegs and compute average speed for each collection of positionfixes
@@ -359,7 +359,7 @@ def get_speed_triplegs(triplegs, positionfixes=None, method="tpls_speed"):
         return tpls
 
     else:
-        raise AttributeError(f"Method {method} not known for speed computation.")
+        raise ValueError(f"Method {method} not known for speed computation.")
 
 
 def _single_tripleg_mean_speed(positionfixes):
diff --git a/trackintel/geogr/filter.py b/trackintel/geogr/filter.py
index fb37143..19bcafc 100644
--- a/trackintel/geogr/filter.py
+++ b/trackintel/geogr/filter.py
@@ -61,9 +61,7 @@ def spatial_filter(source, areas, method="within", re_project=False):
     elif method == "crosses":
         ret_gdf = possible_matches.loc[possible_matches.crosses(areas.unary_union)]
     else:
-        raise AttributeError(
-            "method unknown. We only support ['within', 'intersects', 'crosses']. " f"You passed {method}"
-        )
+        raise ValueError("method unknown. We only support ['within', 'intersects', 'crosses']. " f"You passed {method}")
 
     if re_project:
         return ret_gdf.to_crs(init_crs)
diff --git a/trackintel/io/from_geopandas.py b/trackintel/io/from_geopandas.py
index a5458da..611f465 100644
--- a/trackintel/io/from_geopandas.py
+++ b/trackintel/io/from_geopandas.py
@@ -1,7 +1,6 @@
 import warnings
 import pandas as pd
 import geopandas as gpd
-import pytz
 
 from trackintel import Positionfixes, Staypoints, Triplegs, Locations, Trips, Tours
 
diff --git a/trackintel/model/locations.py b/trackintel/model/locations.py
index 0e1c618..f55db14 100644
--- a/trackintel/model/locations.py
+++ b/trackintel/model/locations.py
@@ -51,7 +51,7 @@ class Locations(TrackintelBase, TrackintelGeoDataFrame):
         if obj["center"].iloc[0].geom_type != "Point":
             # todo: We could think about allowing both geometry types for locations (point and polygon)
             # One for extend and one for the center
-            raise ValueError("The center geometry must be a Point (only first checked).")
+            raise TypeError("The center geometry must be a Point (only first checked).")
 
     @doc(_shared_docs["write_csv"], first_arg="", long="locations", short="locs")
     def to_csv(self, filename, *args, **kwargs):
diff --git a/trackintel/model/positionfixes.py b/trackintel/model/positionfixes.py
index 4990a41..0140408 100644
--- a/trackintel/model/positionfixes.py
+++ b/trackintel/model/positionfixes.py
@@ -71,7 +71,7 @@ class Positionfixes(TrackintelBase, TrackintelGeoDataFrame, gpd.GeoDataFrame):
         ), "Not all geometries are valid. Try x[~ x.geometry.is_valid] where x is you GeoDataFrame"
 
         if obj.geometry.iloc[0].geom_type != "Point":
-            raise AttributeError("The geometry must be a Point (only first checked).")
+            raise TypeError("The geometry must be a Point (only first checked).")
 
     @property
     def center(self):
diff --git a/trackintel/model/staypoints.py b/trackintel/model/staypoints.py
index 7712aa2..860f671 100644
--- a/trackintel/model/staypoints.py
+++ b/trackintel/model/staypoints.py
@@ -71,7 +71,7 @@ class Staypoints(TrackintelBase, TrackintelGeoDataFrame):
             obj.geometry.is_valid.all()
         ), "Not all geometries are valid. Try x[~ x.geometry.is_valid] where x is you GeoDataFrame"
         if obj.geometry.iloc[0].geom_type != "Point":
-            raise AttributeError("The geometry must be a Point (only first checked).")
+            raise TypeError("The geometry must be a Point (only first checked).")
 
     @property
     def center(self):
diff --git a/trackintel/model/triplegs.py b/trackintel/model/triplegs.py
index 972b831..dcd4720 100644
--- a/trackintel/model/triplegs.py
+++ b/trackintel/model/triplegs.py
@@ -69,7 +69,7 @@ class Triplegs(TrackintelBase, TrackintelGeoDataFrame):
             obj.geometry.is_valid.all()
         ), "Not all geometries are valid. Try x[~ x.geometry.is_valid] where x is you GeoDataFrame"
         if obj.geometry.iloc[0].geom_type != "LineString":
-            raise AttributeError("The geometry must be a LineString (only first checked).")
+            raise TypeError("The geometry must be a LineString (only first checked).")
 
     @doc(_shared_docs["write_csv"], first_arg="", long="triplegs", short="tpls")
     def to_csv(self, filename, *args, **kwargs):
diff --git a/trackintel/preprocessing/positionfixes.py b/trackintel/preprocessing/positionfixes.py
index c9834a5..04f45df 100644
--- a/trackintel/preprocessing/positionfixes.py
+++ b/trackintel/preprocessing/positionfixes.py
@@ -395,7 +395,7 @@ def generate_triplegs(
         return pfs, Triplegs(tpls)
 
     else:
-        raise AttributeError(f"Method unknown. We only support 'between_staypoints'. You passed {method}")
+        raise ValueError(f"Method unknown. We only support 'between_staypoints'. You passed {method}")
 
 
 def _generate_staypoints_sliding_user(
@@ -405,7 +405,7 @@ def _generate_staypoints_sliding_user(
     if distance_metric == "haversine":
         dist_func = point_haversine_dist
     else:
-        raise AttributeError("distance_metric unknown. We only support ['haversine']. " f"You passed {distance_metric}")
+        raise ValueError("distance_metric unknown. We only support ['haversine']. " f"You passed {distance_metric}")
 
     df = df.sort_index(kind="stable").sort_values(by=["tracked_at"], kind="stable")
 
diff --git a/trackintel/preprocessing/staypoints.py b/trackintel/preprocessing/staypoints.py
index 69a4911..8e67c17 100644
--- a/trackintel/preprocessing/staypoints.py
+++ b/trackintel/preprocessing/staypoints.py
@@ -76,9 +76,9 @@ def generate_locations(
     """
     Staypoints.validate(staypoints)
     if agg_level not in ["user", "dataset"]:
-        raise AttributeError(f"agg_level '{agg_level}' is unknown. Supported values are ['user', 'dataset'].")
+        raise ValueError(f"agg_level '{agg_level}' is unknown. Supported values are ['user', 'dataset'].")
     if method not in ["dbscan"]:
-        raise AttributeError(f"method '{method}' is unknown. Supported value is ['dbscan'].")
+        raise ValueError(f"method '{method}' is unknown. Supported value is ['dbscan'].")
 
     # initialize the return GeoDataFrames
     sp = staypoints.copy()
diff --git a/trackintel/preprocessing/trips.py b/trackintel/preprocessing/trips.py
index b197964..a5d1832 100644
--- a/trackintel/preprocessing/trips.py
+++ b/trackintel/preprocessing/trips.py
@@ -1,13 +1,11 @@
 import warnings
 from datetime import timedelta
 
-import geopandas as gpd
 import numpy as np
 import pandas as pd
-from tqdm import tqdm
 
 import trackintel as ti
-from trackintel import Tours, Trips
+from trackintel import Tours
 from trackintel.preprocessing.util import applyParallel
 
 


Test patch:
diff --git a/tests/analysis/test_label.py b/tests/analysis/test_label.py
index fce2615..032949e 100644
--- a/tests/analysis/test_label.py
+++ b/tests/analysis/test_label.py
@@ -27,11 +27,11 @@ class TestCreate_activity_flag:
         sp_test = ti.read_staypoints_csv(sp_file, tz="utc", index_col="id")
 
         method = 12345
-        with pytest.raises(AttributeError, match=f"Method {method} not known for creating activity flag."):
+        with pytest.raises(ValueError, match=f"Method {method} not known for creating activity flag."):
             sp_test.as_staypoints.create_activity_flag(method=method)
 
         method = "random"
-        with pytest.raises(AttributeError, match=f"Method {method} not known for creating activity flag."):
+        with pytest.raises(ValueError, match=f"Method {method} not known for creating activity flag."):
             sp_test.as_staypoints.create_activity_flag(method=method)
 
 
@@ -44,11 +44,11 @@ class TestPredict_transport_mode:
         tpls = ti.read_triplegs_csv(tpls_file, sep=";", index_col="id")
 
         method = 12345
-        with pytest.raises(AttributeError, match=f"Method {method} not known for predicting tripleg transport modes."):
+        with pytest.raises(ValueError, match=f"Method {method} not known for predicting tripleg transport modes."):
             tpls.as_triplegs.predict_transport_mode(method=method)
 
         method = "random"
-        with pytest.raises(AttributeError, match=f"Method {method} not known for predicting tripleg transport modes."):
+        with pytest.raises(ValueError, match=f"Method {method} not known for predicting tripleg transport modes."):
             tpls.as_triplegs.predict_transport_mode(method=method)
 
     def test_check_empty_dataframe(self):
diff --git a/tests/analysis/test_modal_split.py b/tests/analysis/test_modal_split.py
index a22f311..c6ff186 100644
--- a/tests/analysis/test_modal_split.py
+++ b/tests/analysis/test_modal_split.py
@@ -204,7 +204,7 @@ class TestModalSplit:
         """Check if error is raised if unknown metric is passed."""
         metric = "unknown_metric"
         error_msg = f"Metric {metric} unknown, only metrics {{'count', 'distance', 'duration'}} are supported."
-        with pytest.raises(AttributeError, match=error_msg):
+        with pytest.raises(ValueError, match=error_msg):
             calculate_modal_split(test_triplegs_modal_split, metric=metric)
 
 
diff --git a/tests/analysis/test_tracking_quality.py b/tests/analysis/test_tracking_quality.py
index e4e0b88..a1732e3 100644
--- a/tests/analysis/test_tracking_quality.py
+++ b/tests/analysis/test_tracking_quality.py
@@ -163,9 +163,9 @@ class TestTemporal_tracking_quality:
         """Test if the an error is raised when passing unknown 'granularity' to temporal_tracking_quality()."""
         sp_tpls = testdata_sp_tpls_geolife_long
 
-        with pytest.raises(AttributeError):
+        with pytest.raises(ValueError):
             ti.analysis.tracking_quality.temporal_tracking_quality(sp_tpls, granularity=12345)
-        with pytest.raises(AttributeError):
+        with pytest.raises(ValueError):
             ti.analysis.tracking_quality.temporal_tracking_quality(sp_tpls, granularity="random")
 
     def test_tracking_quality_wrong_datamodel(self):
@@ -189,9 +189,9 @@ class TestTemporal_tracking_quality:
         sp_tpls = testdata_sp_tpls_geolife_long
         user_0 = sp_tpls.loc[sp_tpls["user_id"] == 0]
 
-        with pytest.raises(AttributeError):
+        with pytest.raises(ValueError):
             ti.analysis.tracking_quality._get_tracking_quality_user(user_0, granularity=12345)
-        with pytest.raises(AttributeError):
+        with pytest.raises(ValueError):
             ti.analysis.tracking_quality._get_tracking_quality_user(user_0, granularity="random")
 
     def test_staypoints_accessors(self, testdata_all_geolife_long):
diff --git a/tests/geogr/test_distances.py b/tests/geogr/test_distances.py
index 0d4e7d2..48262ab 100644
--- a/tests/geogr/test_distances.py
+++ b/tests/geogr/test_distances.py
@@ -506,10 +506,10 @@ class TestPfsMeanSpeedTriplegs:
         assert_geodataframe_equal(tpls_speed_acc, tpls_speed_normal)
 
     def test_pfs_input_assertion(self, example_triplegs):
-        """Test whether an AttributeError is raised if no positionfixes are provided as input"""
+        """Test whether an ValueError is raised if no positionfixes are provided as input"""
         error_msg = 'Method "pfs_mean_speed" requires positionfixes as input.'
         _, tpls = example_triplegs
-        with pytest.raises(AttributeError, match=error_msg):
+        with pytest.raises(ValueError, match=error_msg):
             ti.geogr.distances.get_speed_triplegs(tpls, None, method="pfs_mean_speed")
 
     def test_pfs_tripleg_id_assertion(self, example_triplegs):
@@ -548,8 +548,9 @@ class TestSimpleSpeedTriplegs:
         tpls_speed_normal = ti.geogr.distances.get_speed_triplegs(tpls)
         assert_geodataframe_equal(tpls_speed_acc, tpls_speed_normal)
 
-    def test_method_error(self):
+    def test_method_error(self, example_triplegs):
         """Test whether an error is triggered if wrong posistionfixes are used as input"""
-        with pytest.raises(Exception) as e_info:
-            _ = ti.geogr.distances.get_speed_triplegs(None, None, method="wrong_method")
-            assert e_info == "Method wrong_method not known for speed computation."
+        meth = "wrong_method"
+        _, tpls = example_triplegs
+        with pytest.raises(ValueError, match=f"Method {meth} not known for speed computation."):
+            _ = ti.geogr.distances.get_speed_triplegs(tpls, None, method=meth)
diff --git a/tests/geogr/test_filter.py b/tests/geogr/test_filter.py
index 9424c38..530e7dc 100644
--- a/tests/geogr/test_filter.py
+++ b/tests/geogr/test_filter.py
@@ -117,5 +117,5 @@ class TestSpatial_filter:
         """Test if the an error is raised when passing unknown 'method' to spatial_filter()."""
         locs = locs_from_geolife
         extent = gpd.read_file(os.path.join("tests", "data", "area", "tsinghua.geojson"))
-        with pytest.raises(AttributeError):
+        with pytest.raises(ValueError):
             locs.spatial_filter(areas=extent, method=12345)
diff --git a/tests/model/test_locations.py b/tests/model/test_locations.py
index fe0e739..f22d0ee 100644
--- a/tests/model/test_locations.py
+++ b/tests/model/test_locations.py
@@ -34,7 +34,7 @@ class TestLocations:
         testdata_locs["center"] = LineString(
             [(13.476808430, 48.573711823), (13.506804, 48.939008), (13.4664690, 48.5706414)]
         )
-        with pytest.raises(ValueError, match="The center geometry must be a Point"):
+        with pytest.raises(TypeError, match="The center geometry must be a Point"):
             testdata_locs.as_locations
 
     def test_accessor_empty(self, testdata_locs):
diff --git a/tests/model/test_positionfixes.py b/tests/model/test_positionfixes.py
index c390cbd..b390a73 100644
--- a/tests/model/test_positionfixes.py
+++ b/tests/model/test_positionfixes.py
@@ -41,7 +41,7 @@ class TestPositionfixes:
         pfs = testdata_geolife.copy()
 
         # check geometry type
-        with pytest.raises(AttributeError, match="The geometry must be a Point"):
+        with pytest.raises(TypeError, match="The geometry must be a Point"):
             pfs["geom"] = LineString([(13.476808430, 48.573711823), (13.506804, 48.939008), (13.4664690, 48.5706414)])
             pfs.as_positionfixes
 
diff --git a/tests/model/test_staypoints.py b/tests/model/test_staypoints.py
index cc9166f..edb0d59 100644
--- a/tests/model/test_staypoints.py
+++ b/tests/model/test_staypoints.py
@@ -40,7 +40,7 @@ class TestStaypoints:
         sp = testdata_sp.copy()
 
         # check geometry type
-        with pytest.raises(AttributeError, match="The geometry must be a Point"):
+        with pytest.raises(TypeError, match="The geometry must be a Point"):
             sp["geom"] = LineString([(13.476808430, 48.573711823), (13.506804, 48.939008), (13.4664690, 48.5706414)])
             sp.as_staypoints
 
diff --git a/tests/model/test_triplegs.py b/tests/model/test_triplegs.py
index af59f5d..101bcda 100644
--- a/tests/model/test_triplegs.py
+++ b/tests/model/test_triplegs.py
@@ -44,7 +44,7 @@ class TestTriplegs:
         tpls = testdata_tpls.copy()
 
         # check geometry type
-        with pytest.raises(AttributeError, match="The geometry must be a LineString"):
+        with pytest.raises(TypeError, match="The geometry must be a LineString"):
             tpls["geom"] = Point([(13.476808430, 48.573711823)])
             tpls.as_triplegs
 
diff --git a/tests/preprocessing/test_positionfixes.py b/tests/preprocessing/test_positionfixes.py
index de838e6..d921231 100644
--- a/tests/preprocessing/test_positionfixes.py
+++ b/tests/preprocessing/test_positionfixes.py
@@ -313,8 +313,8 @@ class Test_Generate_staypoints_sliding_user:
     """Test for _generate_staypoints_sliding_user."""
 
     def test_unknown_distance_metric(self, example_positionfixes):
-        """Test if the distance metric is unknown, an AttributeError will be raised."""
-        with pytest.raises(AttributeError):
+        """Test if the distance metric is unknown, an ValueError will be raised."""
+        with pytest.raises(ValueError):
             example_positionfixes.as_positionfixes.generate_staypoints(
                 method="sliding", dist_threshold=100, time_threshold=5, distance_metric="unknown"
             )
@@ -508,12 +508,12 @@ class TestGenerate_triplegs:
         assert (tpls_case2.index == np.arange(len(tpls_case2))).any()
 
     def test_invalid_inputs(self, geolife_pfs_sp_long):
-        """Test if AttributeError will be raised after invalid method input."""
+        """Test if ValueError will be raised after invalid method input."""
         pfs, sp = geolife_pfs_sp_long
 
-        with pytest.raises(AttributeError, match="Method unknown"):
+        with pytest.raises(ValueError, match="Method unknown"):
             pfs.as_positionfixes.generate_triplegs(sp, method="random")
-        with pytest.raises(AttributeError, match="Method unknown"):
+        with pytest.raises(ValueError, match="Method unknown"):
             pfs.as_positionfixes.generate_triplegs(sp, method=12345)
 
     def test_temporal(self, geolife_pfs_sp_long):
diff --git a/tests/preprocessing/test_staypoints.py b/tests/preprocessing/test_staypoints.py
index 579b145..f0e043a 100644
--- a/tests/preprocessing/test_staypoints.py
+++ b/tests/preprocessing/test_staypoints.py
@@ -438,18 +438,18 @@ class TestGenerate_locations:
         assert sp2.loc[[2, 7], "location_id"].isnull().all()
 
     def test_agg_level_error(self, example_staypoints):
-        """Test if unknown "agg_level" raises AttributeError"""
+        """Test if unknown "agg_level" raises ValueError"""
         agg_level = "unknown"
         error_msg = f"agg_level '{agg_level}' is unknown. Supported values are ['user', 'dataset']."
-        with pytest.raises(AttributeError) as e:
+        with pytest.raises(ValueError) as e:
             example_staypoints.as_staypoints.generate_locations(method="dbscan", agg_level="unkown")
             assert error_msg == str(e.value)
 
     def test_method_error(self, example_staypoints):
-        """Test if unknown "method" raises AttributeError"""
+        """Test if unknown "method" raises ValueError"""
         method = "unknown"
         error_msg = f"method '{method}' is unknown. Supported values are ['dbscan']."
-        with pytest.raises(AttributeError) as e:
+        with pytest.raises(ValueError) as e:
             example_staypoints.as_staypoints.generate_locations(method="unknown")
             assert error_msg == str(e.value)
 
diff --git a/tests/visualization/test_plotting.py b/tests/visualization/test_plotting.py
index f37005d..06915bc 100644
--- a/tests/visualization/test_plotting.py
+++ b/tests/visualization/test_plotting.py
@@ -1,6 +1,5 @@
 import datetime
 import os
-import warnings
 
 import matplotlib
 import numpy as np