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

GH1089 Migrate frame/series tests to new framework #1093

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

loicdiridollou
Copy link
Contributor

tests/test_frame.py Outdated Show resolved Hide resolved
tests/test_frame.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Show resolved Hide resolved
@loicdiridollou loicdiridollou requested a review from Dr-Irv January 14, 2025 13:00
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.

For the ones where the results aren't right (mostly the arithmetic ones), the PR should include the fixes to the PYI files to make those results come out right. I don't want to approve the test changes when the results aren't what we expect.

Could include the fix for complex here as well (even though you created a separate issue)

tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
@loicdiridollou
Copy link
Contributor Author

Will address the changes in this PR (although I created a new issue), seems more correct but agree that it will be slightly larger to review.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 15, 2025

Will address the changes in this PR (although I created a new issue), seems more correct but agree that it will be slightly larger to review.

You have 2 options:

  1. Include the changes to the PYI files in this PR so then the "correct" tests pass.
  2. Leave the "failing" tests alone (i.e., don't convert them) and fix them in a PR that has the PYI changes.

I'm fine either way, although I think it would be easier to do (1). No issue for me in reviewing that large of a PR.

tests/test_series.py Outdated Show resolved Hide resolved
@loicdiridollou loicdiridollou requested a review from Dr-Irv January 16, 2025 12:39
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.

I think I figured out your issues by pulling your PR and trying things. I only tested with pyright in VS Code, so when you run the full tests, something might turn up with mypy.

Also - a request - can you NOT resolve conversations. I will do it once I see that my comment has been resolved.

pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
tests/test_series.py Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Show resolved Hide resolved
pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
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.

For safety, we should duplicate the tests in test_types_element_wise_arithmetic() but where s and s2 have parameters dtype=float. Then the results should all be Series[float]

Also, worth doing a set where s is Series[int] and s2 is Series[float] and vice versa.

And we should do ones with the following. If you create a DataFrame that contains numbers, let's say with a column named s3 then df["s3"] is Series[Unknown] in pyright, So now we want to test the arithmetic operations between Series[int] and df["s3"], Series[float] and df["s3"] and df["s3"] and df["s4"] (where s4 is another column of numbers). You'd have to do the tests with all the symmetries.

So create a bunch of new copies of test_types_element_wise_arithmetic() (with different names) that test these different combinations as the first and second operands of the arithmetic operation, where Series[Unknown] comes from a column in a DataFrame

  • Series[int] and Series[float]
  • Series[float] and Series[int]
  • Series[float] and Series[float]
  • Series[int] and Series[Unknown]
  • Series[Unknown] and Series[int]
  • Series[Unknown] and Series[Unknown]
  • Series[float] and Series[Unknown]
  • Series[Unknown] and Series[float]

It might be worth just moving test_types_element_wise_arithmetic() into a new test_series_arithmetic.py file and just put all the new 8 versions there.

Except for division, the results involving Series[Unknown] should just be Series

pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
pandas-stubs/core/series.pyi Outdated Show resolved Hide resolved
tests/test_series.py Outdated Show resolved Hide resolved
@loicdiridollou
Copy link
Contributor Author

I haven't added all the tests yet, this is quite a bit of work so will probably delay it to another PR and fix in priority based on if it causes more issues for the users.

@loicdiridollou loicdiridollou requested a review from Dr-Irv January 18, 2025 16:24
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 20, 2025

I haven't added all the tests yet, this is quite a bit of work so will probably delay it to another PR and fix in priority based on if it causes more issues for the users.

I'm a bit hesitant to approve without the complete set of tests, because people do s = df["x"] a lot, and s is then Series[Unknown] and then they do arithmetic. So I would like the full set of tests with the Series[Unknown] in there to be included.

I know it's a lot of work and really appreciate your hard work on this!

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.

Found a couple of things. As mentioned at #1093 (comment), I'd like to have the full set of tests included.

Once that is due, then I will take another full look at the PR - I've only been looking at your recent changes each time you push.

It seems pretty close!

s2 = pd.Series([0, 1, -105])

check(assert_type(s + s2, pd.Series), pd.Series)
check(assert_type(s.add(s2, fill_value=0), "pd.Series[float]"), pd.Series)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be pd.Series - type should be unknown



def test_element_wise_int_unknown() -> None:
s = cast(pd.Series, pd.Series([7, -5, 10]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you do this as follows:

df = pd.DataFrame({"s": pd.Series{[7, -5, 10])})
s = df["s"]

Because that's a common pattern in pandas usage and will test the "unknown" usage.

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.

Fix pandas nightly test build and migrate tests over new framework
2 participants