Skip to content

pylint: disable invalid-repr-returned in Series.__repr__ #49025

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

Merged
merged 4 commits into from
Nov 7, 2022

Conversation

vamsi-verma-s
Copy link
Contributor

Since the params passed are for getting the repr string. This should not be an issue and to_string will return a str

@vamsi-verma-s vamsi-verma-s changed the title pyllint: disable invalid-repr-returned in Series.__repr__ pylint: disable invalid-repr-returned in Series.__repr__ Oct 10, 2022
@vamsi-verma-s
Copy link
Contributor Author

Hi @MarcoGorelli

Will the cancelled test be re-run?

@MarcoGorelli
Copy link
Member

yeah, don't worry about it - I'll take a look later in the week, curious to see if there's a way to avoid having to turn off the warning at all

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Oct 10, 2022
@@ -1601,6 +1601,7 @@ def __repr__(self) -> str:
"""
Return a string representation for a particular Series.
"""
# pylint: disable=invalid-repr-returned
repr_params = fmt.get_series_repr_params()
return self.to_string(**repr_params)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to solve the issue. Should we go for this?

Suggested change
return self.to_string(**repr_params)
return str(self.to_string(**repr_params)) # GH#49025

Also, self.to_string method has a validation to ensure only str values are returned.

pandas/pandas/core/series.py

Lines 1700 to 1709 in 2a0e3fe

# catch contract violations
if not isinstance(result, str):
raise AssertionError(
"result must be of type str, type "
f"of result is {repr(type(result).__name__)}"
)
if buf is None:
return result

@@ -1601,6 +1601,7 @@ def __repr__(self) -> str:
"""
Return a string representation for a particular Series.
"""
# pylint: disable=invalid-repr-returned
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# pylint: disable=invalid-repr-returned

@MarcoGorelli
Copy link
Member

🤔 not sure what the issue is - if it's already string, I'd rather not add an unnecessary str( to please pylint. I'm surprised that no error is caught in frame.py in the same function. I'll take a look

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a bug in pylint, seems like just the presence of an overload throws it off

from __future__ import annotations

from typing import overload

class Foo:
    def __repr__(self) -> str:
        return self.foo()

    @overload
    def foo(self) -> str:
        ...

    def foo(self) -> str:
        return 'foo'

I'll report there - marking as draft for now then, once/if we can hear back we can move forwards

@MarcoGorelli MarcoGorelli marked this pull request as draft October 15, 2022 08:46
@MarcoGorelli MarcoGorelli marked this pull request as ready for review November 6, 2022 12:03
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vamsi-verma-s , looks good to me pending green!

pylint linked my report to this issue pylint-dev/astroid#1015, which has been open since 2021, so I don't think it'll get addressed anytime soon

Happy to just turn off the check inline then

@mroeschke mroeschke added this to the 2.0 milestone Nov 7, 2022
@mroeschke mroeschke merged commit 0aeac8a into pandas-dev:main Nov 7, 2022
@mroeschke
Copy link
Member

Thanks @vamsi-verma-s

phofl pushed a commit to phofl/pandas that referenced this pull request Nov 9, 2022
…49025)

* pyllint: disable invalid-repr-returned in Series.__repr__

* remove invalid-repr-returned from pyproject.toml

Co-authored-by: Marco Edward Gorelli <[email protected]>
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
…49025)

* pyllint: disable invalid-repr-returned in Series.__repr__

* remove invalid-repr-returned from pyproject.toml

Co-authored-by: Marco Edward Gorelli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants