-
-
Notifications
You must be signed in to change notification settings - Fork 150
fix(series): #1372 🧱✖️ cumprod #1374
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import numpy as np | ||
import pandas as pd | ||
from typing_extensions import assert_type | ||
|
||
from tests import ( | ||
TYPE_CHECKING_INVALID_USAGE, | ||
check, | ||
) | ||
|
||
|
||
def test_cumul_any_float() -> None: | ||
series = pd.DataFrame({"A": [1.0, float("nan"), 2.0]})["A"] | ||
check(assert_type(series.cumprod(), pd.Series), pd.Series, np.floating) | ||
|
||
|
||
def test_cumul_bool() -> None: | ||
series = pd.Series([True, False, True]) | ||
check(assert_type(series.cumprod(), "pd.Series[int]"), pd.Series, np.integer) | ||
|
||
|
||
def test_cumul_int() -> None: | ||
series = pd.Series([3, 1, 2]) | ||
check(assert_type(series.cumprod(), "pd.Series[int]"), pd.Series, np.integer) | ||
|
||
|
||
def test_cumul_float() -> None: | ||
series = pd.Series([3.0, float("nan"), 2.0]) | ||
check(assert_type(series.cumprod(), "pd.Series[float]"), pd.Series, np.floating) | ||
|
||
|
||
def test_cumul_complex() -> None: | ||
series = pd.Series([3j, 3 + 4j, 2j]) | ||
check( | ||
assert_type(series.cumprod(), "pd.Series[complex]"), | ||
pd.Series, | ||
np.complexfloating, | ||
) | ||
|
||
|
||
def test_cumul_str() -> None: | ||
series = pd.Series(["1", "a", "🐼"]) | ||
if TYPE_CHECKING_INVALID_USAGE: | ||
series.cumprod() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
|
||
def test_cumul_ts() -> None: | ||
series = pd.Series(pd.to_datetime(["2025-09-18", "2025-09-18", "2025-09-18"])) | ||
check(assert_type(series, "pd.Series[pd.Timestamp]"), pd.Series, pd.Timestamp) | ||
|
||
if TYPE_CHECKING_INVALID_USAGE: | ||
series.cumprod() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does that work with classes that have overloads for
__mul__
? My understanding from microsoft/pyright#6549 (comment) is that type checkers will then pick the first overload. It might be okay in this case (and I wish we could use this pattern!) - just something to be aware of when using this patterns in more places.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.
Not sure that it would matter, because
S1
are types we define inpandas
as well as fundamental types (int
,float
, etc.), so I think we will be fine. It's a bit different than the case you wrote up, because of the use of_SupportsMul[S1]
requiring the type that supports__mul__()
to be inS1
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 with this pattern can help us saving efforts, too.
SupportsAdd
andSupportsMul
in_typeshed
. They are however different somehow from our_SupportsAdd
and_SupportsMul
. We probably need a renaming in the near future.A.__operate__(B) ->B
andA.__operate__(A) -> B
, for examplebool + int -> int
,int / int -> float
.