user1559897
user1559897

Reputation: 1484

Neither pytype nor mypy is complaining about type error?

I have the following test script which fails by design. However, neither pytype nor mypy warned me about the problem. Why does this happens?

import pandas as pd
import collections


def junkmerge(dfs: collections.abc.Sequence, *args, **kwargs) -> pd.DataFrame:
    print(dfs)
    return pd.concat(dfs, *args, **kwargs)

if __name__ == '__main__':
    pd1 = pd.DataFrame(data={'a': [1]})
    pd2 = pd.DataFrame(data={'a': [2]})
    junkmerge(pd1, pd2, join='outer')

NOTE: I specifically checked that dataframe is not a sequence.

In [6]: isinstance(pd1, collections.abc.Sequence)                      
Out[6]: False

In [10]: issubclass(pd.DataFrame, collections.abc.Sequence)                                                                                                                                                        
Out[10]: False

Upvotes: 2

Views: 388

Answers (1)

user1559897
user1559897

Reputation: 1484

Neither mypy not pytype supports pandas. So when a dataframe is passed in as a function arguments, neither performs a check.

After removing the pandas dependency in the code, i was able to get the error from both mypy and pytype.

See code copied below.

import collections

def junkmerge(dfs: collections.abc.Sequence[int], *args, **kwargs) -> pd.DataFrame:
    print(dfs)
    return

if __name__ == '__main__':
    junkmerge(1, 2, join='outer')

Upvotes: 1

Related Questions