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

Fix pd.concat to accept None values as input. #858

Merged
merged 4 commits into from
Feb 21, 2024

Conversation

amgcc
Copy link
Contributor

@amgcc amgcc commented Feb 9, 2024

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Please add a test in test_pandas.py. Follow the pattern in there of using check() and assert_type().

@amgcc amgcc requested a review from Dr-Irv February 10, 2024 00:05
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 12, 2024

@twoertwein
Copy link
Member

Sorry, had to force push - merging upstream messed things somehow up.

copy: bool = ...,
) -> Never: ...
@overload
def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
Copy link
Member

Choose a reason for hiding this comment

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

overlaps because of Iterable[None]


check(assert_type(pd.concat([s1, df1, df2]), pd.DataFrame), pd.DataFrame)
if TYPE_CHECKING_INVALID_USAGE:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@twoertwein can you explain what this block means and why this is needed? Trying to understand what was missing from my tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is testing that the type checkers see the code as invalid. Although I don't think the test is constructed correctly....

Comment on lines +74 to +75
assert_type(pd.concat({"a": None}), Never)
assert_type(pd.concat([None]), Never)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these tests should be of the form:

    pd.concat({"a": None})  # type: ignore[some_mypy_error] # pyright: ignore[some_pyright_error]
    pd.concat([None])  # type: ignore[some_mypy_error] # pyright: ignore[some_pyright_error]

so we are checking that the type checkers see that invalid code as an error.

Copy link
Member

Choose a reason for hiding this comment

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

I believe I tried that first - the issue is that the second call will not be checked as it cannot be reached (by the type checkers). Would need to split it into two functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense. I think for consistency's sake, we should do that, although I could be convinced otherwise. If we want to use your pattern here, then add a comment to indicate why we can't just check for a specific type checker error based on your comment here.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need the assert_type only when testing at least two invalid function calls where the first one "returns" NoReturn/Never. I think we also have many cases were we do not explicitly return NoReturn/Never. In that case, we might not need the assert_type.

I would be inclined to use the assert_type only when we have to.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

thanks @amgcc and @twoertwein

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.concat with None
3 participants