mie-lab / trackintel

trackintel is a framework for spatio-temporal analysis of movement trajectory and mobility data.
MIT License
198 stars 50 forks source link

ENH: Change AttributeError to ValueError #599

Closed bifbof closed 8 months ago

bifbof commented 8 months ago

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) or assignment fails. (When an object does not support attribute references or attribute assignments at all, TypeError is raised.)

e.g.

>> 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.

e.g.

>> chr(0x1100001)
ValueError: chr() arg not in range(0x110000)
codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a74f437) 93.31% compared to head (c0f8ab9) 93.41%.

Additional details and impacted files ```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 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

hongyeehh commented 8 months ago

Thanks for the formalization - these error treatments should be enforced in later enhancements and PRs