Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor pandas.core.generic.NDFrame.to_replace() to appease static type analysis #34898

Open
oguzhanogreden opened this issue Jun 20, 2020 · 2 comments
Labels
Refactor Internal refactoring of code replace replace method Typing type annotations, mypy/pyright type checking

Comments

@oguzhanogreden
Copy link
Contributor

Current implementation of pandas.core.to_replace() method won't allow type hints, as noted in #32542 . Contributor guidelines suggest a refactor in this case.

@WillAyd
Copy link
Member

WillAyd commented Jun 22, 2020

Can you share the errors you were seeing?

@jbrockmendel jbrockmendel added Refactor Internal refactoring of code replace replace method Typing type annotations, mypy/pyright type checking labels Jun 23, 2020
@oguzhanogreden oguzhanogreden changed the title Refactor pandas.core.to_replace() to appease static type analysis Refactor pandas.core.Series.to_replace() to appease static type analysis Jun 26, 2020
@oguzhanogreden oguzhanogreden changed the title Refactor pandas.core.Series.to_replace() to appease static type analysis Refactor pandas.core.generic.NDFrame.to_replace() to appease static type analysis Jun 26, 2020
@oguzhanogreden
Copy link
Contributor Author

oguzhanogreden commented Jun 26, 2020

For instance, here mypy would complain that I specified to_replace can be a list, which doesn't have a items() method.

Here's the relevant mypy output (line numbers don't agree with upstream):

pandas/core/generic.py:6475: error: Item "List[Any]" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6475: error: Item "str" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6475: error: Item "int" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6475: error: Item "float" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6475: error: Item "bool" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6475: error: Item "None" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6476: error: 'builtins.object' object is not iterable
pandas/core/generic.py:6478: error: Cannot determine type of 'values'
pandas/core/generic.py:6514: error: Value of type "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" is not indexable
pandas/core/generic.py:6514: error: Value of type "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" is not indexable
pandas/core/generic.py:6515: error: Item "List[Any]" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6515: error: Item "str" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6515: error: Item "int" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6515: error: Item "float" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6515: error: Item "bool" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6515: error: Item "None" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "keys"
pandas/core/generic.py:6516: error: Item "List[Any]" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "keys"
pandas/core/generic.py:6516: error: Item "str" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "keys"
pandas/core/generic.py:6516: error: Item "float" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "keys"
pandas/core/generic.py:6529: error: Item "List[Any]" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6529: error: Item "str" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6529: error: Item "int" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6529: error: Item "float" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6529: error: Item "bool" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6529: error: Item "None" of "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]" has no attribute "items"
pandas/core/generic.py:6537: error: Argument 1 to "len" has incompatible type "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]"; expected "Sized"
pandas/core/generic.py:6537: error: Argument 1 to "len" has incompatible type "Union[Dict[Any, Any], Any, List[Any], str, float, Series]"; expected "Sized"
pandas/core/generic.py:6539: error: Argument 1 to "len" has incompatible type "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]"; expected "Sized"
pandas/core/generic.py:6539: error: Argument 1 to "len" has incompatible type "Union[Dict[Any, Any], Any, List[Any], str, float, Series]"; expected "Sized"
pandas/core/generic.py:6547: error: Argument "regex" to "replace_list" of "BlockManager" has incompatible type "Union[Dict[Any, Any], List[Any], str, int, float, bool, Any, Any, Any, Any, Series, None]"; expected "bool"
pandas/core/generic.py:6578: error: Item "List[Any]" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "items"
pandas/core/generic.py:6578: error: Item "str" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "items"
pandas/core/generic.py:6578: error: Item "float" of "Union[Dict[Any, Any], Any, List[Any], str, float, Series]" has no attribute "items"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code replace replace method Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

No branches or pull requests

3 participants