Skip to content

TYP: Subset of "Improved the type stubs in the _libs directory to help with type checking" #44251

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 16 commits into from
Dec 14, 2021
Merged

Conversation

twoertwein
Copy link
Member

@twoertwein twoertwein commented Oct 31, 2021

The two big parts missing from #43744 are interval.pyi and offsets.pyi as they result in many mypy errors.

I had already made changes to somewhat accommodate for interval.pyi and offsets.pyi (if these files are included, we have now "only" ~100 mypy errors). I kept these changes in this PR.

@pep8speaks
Copy link

pep8speaks commented Oct 31, 2021

Hello @twoertwein! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-12-12 19:24:28 UTC

@twoertwein twoertwein added the Typing type annotations, mypy/pyright type checking label Oct 31, 2021
# Union[Union[str, int, float, bool] Union[Period, Timestamp, Timedelta, Any]]]",
# expected "Tuple[NumpyArrayT, Union[Union[str, int, float, bool], Union[Period,
# Timestamp, Timedelta, Any]]]")
return upcast_values, fill_value # type: ignore[return-value]
Copy link
Member Author

Choose a reason for hiding this comment

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

Should probably be np.ndarray and not be NumpyArrayT since the dtype might change.

Copy link
Member

Choose a reason for hiding this comment

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

The dtype can change but the Python type (i.e. np.ndarray or subclass) maybe preserved. I'm not sure but the numpy types don't annotate as preserving Python object type so maybe not. This was added for ma.MaskedArray handling in the constructors, so could well be that the numpy types are not precise enough, creating this false positive.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks ok to me. can you rebase @twoertwein

@simonjayhawkins @jbrockmendel if comments

@jreback jreback added this to the 1.4 milestone Nov 6, 2021
@jreback
Copy link
Contributor

jreback commented Nov 6, 2021

cc @Dr-Irv

Copy link
Contributor

@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.

I see that you put some typing in the pandas/tests/tseries/... . Have we started typing the test code, and running mypy on parts of the test code?

If not, I don't think that should be included in the PR.

@twoertwein
Copy link
Member Author

I see that you put some typing in the pandas/tests/tseries/... . Have we started typing the test code, and running mypy on parts of the test code?

Some tests are typed checked, including those files.

If not, I don't think that should be included in the PR.

The test changes I made are technically not needed for this PR. They will be needed for offsets.pyi from #43744. Happy to remove them and then add them with offsets.pyi later.

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Nov 8, 2021

The test changes I made are technically not needed for this PR. They will be needed for offsets.pyi from #43744. Happy to remove them and then add them with offsets.pyi later.

IMHO, I think the changes to the test files should be left out for now. That will make the PR smaller. But I would defer to @simonjayhawkins on this

if left_mask is None:
return kleene_xor(right, left, right_mask, left_mask)

assert isinstance(left, np.ndarray)
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this safe? @jbrockmendel The other kleene functions have it as well.

Copy link
Member

Choose a reason for hiding this comment

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

holds in all of our current usages; to be future-safe would need to change this to a check that raises TypeError

Copy link
Member Author

Choose a reason for hiding this comment

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

it raises now a TypeError

@jreback
Copy link
Contributor

jreback commented Nov 14, 2021

looks good, can you rebase

@simonjayhawkins if any comments.

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @twoertwein

# Union[Union[str, int, float, bool] Union[Period, Timestamp, Timedelta, Any]]]",
# expected "Tuple[NumpyArrayT, Union[Union[str, int, float, bool], Union[Period,
# Timestamp, Timedelta, Any]]]")
return upcast_values, fill_value # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

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

The dtype can change but the Python type (i.e. np.ndarray or subclass) maybe preserved. I'm not sure but the numpy types don't annotate as preserving Python object type so maybe not. This was added for ma.MaskedArray handling in the constructors, so could well be that the numpy types are not precise enough, creating this false positive.

@simonjayhawkins
Copy link
Member

IMHO, I think the changes to the test files should be left out for now. That will make the PR smaller. But I would defer to @simonjayhawkins on this

The test modules are type checked but the test functions are not (check_untyped_defs is False). Saying that we have several test modules ignored in the mypy config

@jreback
Copy link
Contributor

jreback commented Nov 28, 2021

@twoertwein can you merge master

@jreback
Copy link
Contributor

jreback commented Dec 14, 2021

thanks @twoertwein very nice

@twoertwein twoertwein deleted the libs_subset branch March 9, 2022 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants