-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Add typing tests according to the issue 45252 #45594
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
ENH: Add typing tests according to the issue 45252 #45594
Conversation
Test stubs originally authored by Joanna Sendorek, Zbigniew Królikowski and pandas_stubs contributors: https://github.com/VirtusLab/pandas-stubs/graphs/contributors Adapted to pandas needs by Torsten Wörtwein
Except for running isort you will need to skip a few tests depending on required dependencies to make the CI greener :) (or wait first for consensus before going forward)
The easiest is probably to skip the entire test function with the existing decorator: from pandas.util import _test_decorators as td
@td.skip_if_no("matplotlib")
def test_bar():
... Probably wouldn't hurt to also have a small readme in the typing/valid folder to mention where these files came from and state the main contributors. Probably would also need someone with expertise with licenses (Pandas is BSD-3 but the stubs are MIT). |
@twoertwein It's impossible to make both EDIT: No it doesn't. I'll continue working on that. There might be a workaround. I've added a small README but haven't mentioned the contributors - pandas repository seems devoid of such and I've deemed to continue with this approach. |
@twoertwein Only available option was to configure isort to black. This might be a bit controversial. |
I think isort is already configured to be compatible with black: Line 143 in 42a26ac
|
## Origins and attribution | ||
|
||
The tests come from the [pandas-stubs](https://github.com/VirtusLab/pandas-stubs) | ||
repository originally released under the MIT license. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shoyer You seem to often reply to license compatibility questions :)
Is it okay to integrate this MIT-licened code into pandas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pandas is happy to reuse MIT licensed code (e.g., see existing examples in https://github.com/pandas-dev/pandas/tree/main/LICENSES), but you absolutely need to preserve original copyright notices. The general rule (not sure if pandas is 100% strict about it, but it's a good practice) is to keep the original copyright notice as a top level comment inside each file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shoyer Should I include any open source contributors, who added their code since the library was originally created, in the copyright notice?
|
||
def test_types_rank() -> None: | ||
s = pd.Series([1, 1, 2, 5, 6, np.nan, "million"]) | ||
s.rank() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to work with 1.4.0 (FutureWarning) but on main this results in a TypeError
TypeError: '<' not supported between instances of 'str' and 'int'
[I have no idea why some of the tempfile.NamedTemporaryFile-tests create PermissionErrors on Windows]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning towards the opinion that all deprecated features shouldn't be tested - if pandas would ship with type information (which is the ultimate aim AFAIK) users should be discouraged to use them. Looks like the CI won't allow those either way.
Apparently NamedTemporaryFile cannot have two handles on Windows. Fixed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would maybe be a good first invalid type test (but that is probably too much for this already very large PR) @simonjayhawkins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to remove the deprecated use-cases.
Test stubs originally authored by Joanna Sendorek, Zbigniew Królikowski and pandas_stubs contributors: https://github.com/VirtusLab/pandas-stubs/graphs/contributors Adapted to pandas needs by Torsten Wörtwein
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks @zkrolikowski-vl
There are still a few open points to discuss:
- how to handle negative tests
- how to use these new typing test when we have more (public) pyi files TYP/CI: Demonstrate possible integration of VirtusLab's type tests #45561 (comment)
- how to maintain the new type tests (ideally could de-duplicate work between pandas and VirtusLab)
I'm not sure whether this PR needs to wait for all of the above.
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
@Dr-Irv we should close this now and open these changes against https://github.com/pandas-dev/pandas-stubs in the first instance? |
We can close it. The current |
Typing test stubs originally authored by Joanna Sendorek, Zbigniew Królikowski and pandas_stubs contributors: https://github.com/VirtusLab/pandas-stubs/graphs/contributors
Adapted to pandas needs by Torsten Wörtwein
Issue reference:
#45252
Summary of files and changes:
pandas/tests/typing/valid
that contain functions testing different areas of pandas API. There are no assertions there - their only aim to check argument and declarations that should be allowed according to the documentation and popular use-cases.README
underpandas/tests/typing/REAMDE.md
that describes the purpose of origin of those files.STUBS_LICENSE
underLICENSES
. It contain the Copyright and license (MIT) of the original project.pyproject.toml
to enable mypy and pyright on the directory.Related and out-of-scope aspects
How to handle negative tests: That's out-of-scope. Simplest way would be to place those tests in a directory not checked by pytest and use
# type: ignore[<reason>]
.How to use these new typing test when we have more (public) pyi files TYP/CI: Demonstrate possible integration of VirtusLab's type tests #45561 (comment): Mypy or pyright should be able to automatically pick-up the .pyi files when they'll be present.
How to maintain the new type tests (ideally could de-duplicate work between pandas and VirtusLab): As for keeping up-to-date on our side I've created two issues Bring pands_stubs CI standards as close as possible to pandas VirtusLab/pandas-stubs#146 Automate pandas PR/branch creation based on snippet changes VirtusLab/pandas-stubs#147 to tackle that. At the very least we can make it easier to move the code. At best we can partially automate it. In terms of de-duplicating work - all work in pandas_stubs except for small fixes is written out in issues and it will most likely be the same for pandas. We'll need to count on contributor diligence.
closes ENH: Add set of tests to type check the public APIs #45252
tests added / passed
Ensure all linting tests pass, see here for how to run them
whatsnew entry - (doesn't have a functional impact)