xoolive / traffic

A toolbox for processing and analysing air traffic data
https://traffic-viz.github.io/
MIT License
362 stars 80 forks source link

Instance of 'DataFrameMixin' has no 'clean_invalid' member #272

Closed q-wertz closed 1 year ago

q-wertz commented 1 year ago

Pylint reports the error Instance of 'DataFrameMixin' has no 'clean_invalid' member on the following code snippet:

import traffic

a = traffic.core.Traffic.from_file(filename="test").clean_invalid(10)

I tried to debug this but didn't get why it is interpreted as a DataFrameMixin

In [11]: type(a)
Out[11]: traffic.core.traffic.Traffic

In [12]: dir(a)
Out[12]: 
[…
 'clean_invalid',
 …
]

Versions

q-wertz commented 1 year ago

Sorry, searched a litte bit more and it seems to be an upstream issue https://github.com/PyCQA/pylint/issues/7487.

Just wondering why

import traffic

a = traffic.core.Traffic.from_flights(flights="").clean_invalid()

gives no error…

Is there a reason why the return type differs between both functions?

xoolive commented 1 year ago

Quickly looking from the phone, I would assume the from_flights function would iterate on "" and create an empty dataframe, which would wrap as None and you can’t apply clean_invalid() on None.

That’s for the runtime.

For the typing Traffic.from_flights should return a Traffic as stated by the type T bound by DataFrameMixin (therefore Traffic not DFM)

Note that the whole code base is checked with mypy, (black, flake8 and isort). I don’t run pylint on top of it otherwise it never ends 😅

q-wertz commented 1 year ago

Quickly looking from the phone, I would assume the from_flights function would iterate on "" and create an empty dataframe, which would wrap as None and you can’t apply clean_invalid() on None.

Was not intended for running but you are right :+1:

Note that the whole code base is checked with mypy, (black, flake8 and isort). I don’t run pylint on top of it otherwise it never ends sweat_smile

I can completely understand :sweat_smile:

I just don't get the pylint logic at that point. But maybe it gets fixed or at some point I understand enough to "fix" my code in case that is the problem…

pylint also states for objects that are of type Traffic:

so probably just a pylint issue…

Interesting is, that mypy states: "Traffic" has no attribute "inside_bbox" [attr-defined]mypy(error) which I can use and is also in the documentation but I cannot find it in the code (traffic.py, mixins.py) :thinking:

xoolive commented 1 year ago

In my experience, pylint is not as “smart-ass” as mypy...

Re: insight_bbox, it's monkey-patched in airspace.py (to avoid infinite import recursion...)

For other “lacking” methods, you can have a look at lazy.py line 468: all functions from GeographyMixin are automatically attached to the LazyTraffic mechanism :wink: I should find a way to make it look clearer to mypy (and to fellow users), but time is lacking!